List of usage examples for org.json JSONObject has
public boolean has(String key)
From source file:cn.code.notes.gtask.remote.GTaskManager.java
private void addLocalNode(Node node) throws NetworkFailureException { if (mCancelled) { return;// ww w . j av a 2 s. c o m } SqlNote sqlNote; if (node instanceof TaskList) { if (node.getName().equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT)) { sqlNote = new SqlNote(mContext, Notes.ID_ROOT_FOLDER); } else if (node.getName() .equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_CALL_NOTE)) { sqlNote = new SqlNote(mContext, Notes.ID_CALL_RECORD_FOLDER); } else { sqlNote = new SqlNote(mContext); sqlNote.setContent(node.getLocalJSONFromContent()); sqlNote.setParentId(Notes.ID_ROOT_FOLDER); } } else { sqlNote = new SqlNote(mContext); JSONObject js = node.getLocalJSONFromContent(); try { if (js.has(GTaskStringUtils.META_HEAD_NOTE)) { JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); if (note.has(NoteColumns.ID)) { long id = note.getLong(NoteColumns.ID); if (DataUtils.existInNoteDatabase(mContentResolver, id)) { // the id is not available, have to create a new one note.remove(NoteColumns.ID); } } } if (js.has(GTaskStringUtils.META_HEAD_DATA)) { JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA); for (int i = 0; i < dataArray.length(); i++) { JSONObject data = dataArray.getJSONObject(i); if (data.has(DataColumns.ID)) { long dataId = data.getLong(DataColumns.ID); if (DataUtils.existInDataDatabase(mContentResolver, dataId)) { // the data id is not available, have to create // a new one data.remove(DataColumns.ID); } } } } } catch (JSONException e) { Log.w(TAG, e.toString()); e.printStackTrace(); } sqlNote.setContent(js); Long parentId = mGidToNid.get(((Task) node).getParent().getGid()); if (parentId == null) { Log.e(TAG, "cannot find task's parent id locally"); throw new ActionFailureException("cannot add local node"); } sqlNote.setParentId(parentId.longValue()); } // create the local node sqlNote.setGtaskId(node.getGid()); sqlNote.commit(false); // update gid-nid mapping mGidToNid.put(node.getGid(), sqlNote.getId()); mNidToGid.put(sqlNote.getId(), node.getGid()); // update meta updateRemoteMeta(node.getGid(), sqlNote); }
From source file:net.jmhertlein.mcanalytics.api.request.AuthenticationRequest.java
@Override public AuthenticationResult processResponse(JSONObject response) { Boolean success = response.getString("status").equals("OK"); X509Certificate cert, ca;// w w w .j a v a 2 s .co m if (response.has("cert")) { cert = SSLUtil.certFromBase64(response.getString("cert")); } else { cert = null; } if (response.has("ca")) { ca = SSLUtil.certFromBase64(response.getString("ca")); } else { ca = null; } return new AuthenticationResult(cert, ca, success); }
From source file:org.wso2.carbon.connector.integration.test.meetup.venues.VenuesIntegrationTest.java
@Test(groups = { "wso2.esb" }, description = "meetup {getOpenVenues} integration test") public void testGetOpenVenuesRequiredParameters() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "venues_getOpenVenues_mandatory.txt"; String methodName = "venues_get_open_venues"; final String jsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath); final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml"; String modifiedJsonString = String.format(jsonString, meetupConnectorProperties.getProperty("key")); proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath))); try {//from www . j a v a 2 s . co m JSONObject jsonObject = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName), modifiedJsonString); Assert.assertTrue(jsonObject.has("results")); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:org.wso2.carbon.connector.integration.test.meetup.venues.VenuesIntegrationTest.java
@Test(groups = { "wso2.esb" }, description = "meetup {getOpenVenues} integration test") public void testGetOpenVenuesWithOptionalParameters() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "venues_getOpenVenues_optional.txt"; String methodName = "venues_get_open_venues"; final String jsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath); final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml"; String modifiedJsonString = String.format(jsonString, meetupConnectorProperties.getProperty("key")); proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath))); try {/*from w w w . jav a 2s. co m*/ JSONObject jsonObject = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName), modifiedJsonString); Assert.assertTrue(jsonObject.has("results")); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:org.wso2.carbon.connector.integration.test.meetup.venues.VenuesIntegrationTest.java
@Test(groups = { "wso2.esb" }, description = "meetup {getVenues} integration test") public void testGetVenuesRequiredParameters() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "venues_getVenues_mandatory.txt"; String methodName = "venues_get_venues"; final String jsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath); final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml"; String modifiedJsonString = String.format(jsonString, meetupConnectorProperties.getProperty("key")); proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath))); try {// www .ja va2s .co m JSONObject jsonObject = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName), modifiedJsonString); Assert.assertTrue(jsonObject.has("results")); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:org.wso2.carbon.connector.integration.test.meetup.venues.VenuesIntegrationTest.java
@Test(groups = { "wso2.esb" }, description = "meetup {getVenues} integration test") public void testGetVenuesWithOptionalParameters() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "venues_getVenues_optional.txt"; String methodName = "venues_get_venues"; final String jsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath); final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml"; String modifiedJsonString = String.format(jsonString, meetupConnectorProperties.getProperty("key")); proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath))); try {/* w w w. jav a 2s.co m*/ JSONObject jsonObject = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName), modifiedJsonString); Assert.assertTrue(jsonObject.has("results")); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:org.wso2.carbon.connector.integration.test.meetup.venues.VenuesIntegrationTest.java
@Test(groups = { "wso2.esb" }, description = "meetup {getRecommendedVenues} integration test") public void testGetRecommendedVenuesWithOptionalParameters() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "venues_getRecommendedVenues_optional.txt"; String methodName = "venues_get_recommended_venues"; final String jsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath); final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml"; String modifiedJsonString = String.format(jsonString, meetupConnectorProperties.getProperty("key")); proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath))); try {//w ww .j a v a2s. c om JSONArray jsonObjectArray = ConnectorIntegrationUtil .sendRequestJSONArray(getProxyServiceURL(methodName), modifiedJsonString); JSONObject jsonObject = (JSONObject) jsonObjectArray.get(0); Assert.assertTrue(jsonObject.has("visibility")); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:cn.code.notes.gtask.data.SqlData.java
public void setContent(JSONObject js) throws JSONException { long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID; if (mIsCreate || mDataId != dataId) { mDiffDataValues.put(DataColumns.ID, dataId); }//from w w w .ja v a 2s. c o m mDataId = dataId; String dataMimeType = js.has(DataColumns.MIME_TYPE) ? js.getString(DataColumns.MIME_TYPE) : DataConstants.NOTE; if (mIsCreate || !mDataMimeType.equals(dataMimeType)) { mDiffDataValues.put(DataColumns.MIME_TYPE, dataMimeType); } mDataMimeType = dataMimeType; String dataContent = js.has(DataColumns.CONTENT) ? js.getString(DataColumns.CONTENT) : ""; if (mIsCreate || !mDataContent.equals(dataContent)) { mDiffDataValues.put(DataColumns.CONTENT, dataContent); } mDataContent = dataContent; long dataContentData1 = js.has(DataColumns.DATA1) ? js.getLong(DataColumns.DATA1) : 0; if (mIsCreate || mDataContentData1 != dataContentData1) { mDiffDataValues.put(DataColumns.DATA1, dataContentData1); } mDataContentData1 = dataContentData1; String dataContentData3 = js.has(DataColumns.DATA3) ? js.getString(DataColumns.DATA3) : ""; if (mIsCreate || !mDataContentData3.equals(dataContentData3)) { mDiffDataValues.put(DataColumns.DATA3, dataContentData3); } mDataContentData3 = dataContentData3; }
From source file:com.android.browser.GearsSettingsDialog.java
public void setup() { // First let's add the permissions' resources LOCAL_STORAGE.setResources(R.string.settings_storage_title, R.string.settings_storage_subtitle_on, R.string.settings_storage_subtitle_off); LOCATION_DATA.setResources(R.string.settings_location_title, R.string.settings_location_subtitle_on, R.string.settings_location_subtitle_off); // add the permissions to the list of permissions. mPermissions = new Vector<PermissionType>(); mPermissions.add(LOCAL_STORAGE);/*from w w w .jav a 2 s . c om*/ mPermissions.add(LOCATION_DATA); OriginPermissions.setListener(this); setupDialog(); // We manage the permissions using three vectors, mSitesPermissions, // mOriginalPermissions and mCurrentPermissions. // The dialog's arguments are parsed and a list of permissions is // generated and stored in those three vectors. // mOriginalPermissions is a separate copy and will not be modified; // mSitesPermissions contains the current permissions _only_ -- // if an origin is removed, it is also removed from mSitesPermissions. // Finally, mCurrentPermissions contains the current permissions and // is a clone of mSitesPermissions, but removed sites aren't removed, // their permissions are simply set to PERMISSION_NOT_SET. This // allows us to easily generate the final difference between the // original permissions and the final permissions, while directly // using mSitesPermissions for the listView adapter (SettingsAdapter). mSitesPermissions = new Vector<OriginPermissions>(); mOriginalPermissions = new Vector<OriginPermissions>(); try { JSONObject json = new JSONObject(mDialogArguments); if (json.has("permissions")) { JSONArray jsonArray = json.getJSONArray("permissions"); for (int i = 0; i < jsonArray.length(); i++) { JSONObject infos = jsonArray.getJSONObject(i); String name = null; int localStorage = PermissionType.PERMISSION_NOT_SET; int locationData = PermissionType.PERMISSION_NOT_SET; if (infos.has("name")) { name = infos.getString("name"); } if (infos.has(LOCAL_STORAGE_STRING)) { JSONObject perm = infos.getJSONObject(LOCAL_STORAGE_STRING); if (perm.has("permissionState")) { localStorage = perm.getInt("permissionState"); } } if (infos.has(LOCATION_DATA_STRING)) { JSONObject perm = infos.getJSONObject(LOCATION_DATA_STRING); if (perm.has("permissionState")) { locationData = perm.getInt("permissionState"); } } OriginPermissions perms = new OriginPermissions(name); perms.setPermission(LOCAL_STORAGE, localStorage); perms.setPermission(LOCATION_DATA, locationData); mSitesPermissions.add(perms); mOriginalPermissions.add(new OriginPermissions(perms)); } } } catch (JSONException e) { Log.e(TAG, "JSON exception ", e); } mCurrentPermissions = (Vector<OriginPermissions>) mSitesPermissions.clone(); View listView = findViewById(R.id.sites_list); if (listView != null) { ListView list = (ListView) listView; mListAdapter = new SettingsAdapter(mActivity, mSitesPermissions); list.setAdapter(mListAdapter); list.setScrollBarStyle(android.view.View.SCROLLBARS_OUTSIDE_INSET); list.setOnItemClickListener(mListAdapter); } if (mDebug) { printPermissions(); } }
From source file:fr.bmartel.android.fadecandy.model.FadecandyColor.java
public FadecandyColor(JSONObject color) { try {/* w ww .j av a 2s.c om*/ if (color.has(Constants.CONFIG_GAMMA) && color.has(Constants.CONFIG_WHITEPOINT)) { mGamma = (float) color.getDouble(Constants.CONFIG_GAMMA); JSONArray whitepoints = color.getJSONArray(Constants.CONFIG_WHITEPOINT); for (int i = 0; i < whitepoints.length(); i++) { mWhitepoints.add((float) whitepoints.getDouble(i)); } } } catch (JSONException e) { e.printStackTrace(); } }