List of usage examples for org.json JSONObject getBoolean
public boolean getBoolean(String key) throws JSONException
From source file:com.appdynamics.monitors.nginx.statsExtractor.UpstreamsStatsExtractor.java
private void collectMetrics(Map<String, String> upstreamsStats, String serverGroupName, JSONObject server) { String serverIp = server.getString("server"); boolean backup = server.getBoolean("backup"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|backup", backup ? "1" : "0"); long weight = server.getLong("weight"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|weight", String.valueOf(weight)); // up?, down?, unavail?, or unhealthy?. String state = server.getString("state"); int stateInt = -1; if ("up".equals(state)) { stateInt = 0;/*from w w w . ja v a2 s .co m*/ } else if ("down".equals(state)) { stateInt = 1; } else if ("unavail".equals(state)) { stateInt = 2; } else if ("unhealthy".equals(state)) { stateInt = 3; } upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|state", String.valueOf(stateInt)); long active = server.getLong("active"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|active", String.valueOf(active)); if (server.has("max_conns")) { long maxConns = server.getLong("max_conns"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|max_conns", String.valueOf(maxConns)); } long requests = server.getLong("requests"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|requests", String.valueOf(requests)); JSONObject responses = server.getJSONObject("responses"); long resp1xx = responses.getLong("1xx"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|responses|1xx", String.valueOf(resp1xx)); long resp2xx = responses.getLong("2xx"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|responses|2xx", String.valueOf(resp2xx)); long resp3xx = responses.getLong("3xx"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|responses|3xx", String.valueOf(resp3xx)); long resp4xx = responses.getLong("4xx"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|responses|4xx", String.valueOf(resp4xx)); long resp5xx = responses.getLong("5xx"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|responses|5xx", String.valueOf(resp5xx)); long respTotal = responses.getLong("total"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|responses|total", String.valueOf(respTotal)); long sent = server.getLong("sent"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|sent", String.valueOf(sent)); long received = server.getLong("received"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|received", String.valueOf(received)); long upstreamServerFails = server.getLong("fails"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|fails", String.valueOf(upstreamServerFails)); long unavail = server.getLong("unavail"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|unavail", String.valueOf(unavail)); JSONObject healthChecks = server.getJSONObject("health_checks"); long checks = healthChecks.getLong("checks"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|health_checks|checks", String.valueOf(checks)); long healthCheckFails = healthChecks.getLong("fails"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|health_checks|fails", String.valueOf(healthCheckFails)); long unhealthy = healthChecks.getLong("unhealthy"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|health_checks|unhealthy", String.valueOf(unhealthy)); if (server.has("last_passed")) { boolean lastPassed = healthChecks.getBoolean("last_passed"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|health_checks|last_passed", String.valueOf(lastPassed ? 0 : 1)); } long downtime = server.getLong("downtime"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|downtime", String.valueOf(downtime)); long downstart = server.getLong("downstart"); upstreamsStats.put("upstreams|" + serverGroupName + "|" + serverIp + "|downstart", String.valueOf(downstart)); }
From source file:in.neoandroid.neoupdate.neoUpdate.java
private Boolean parseMetafile(JSONObject metafile) { double version; boolean forceVersion; boolean allowed = false; try {/*w w w .j av a 2s . co m*/ version = metafile.getDouble("version"); forceVersion = metafile.getBoolean("forceVersion"); JSONObject appDetails = metafile.getJSONObject("app"); JSONArray assets = metafile.getJSONArray("assets"); JSONArray devices = metafile.getJSONArray("allowedDevices"); int nAssets = assets.length(); String packageName = appDetails.getString("packageName"); int versionCode = appDetails.getInt("versionCode"); String apkPath = appDetails.getString("APK"); boolean offlineSupport = appDetails.getBoolean("offlineSupport"); if (enableDebug) { Log.d(TAG, "Version: " + version + ":" + neoUpdateVersion); Log.d(TAG, "Package Name: " + packageName + ":" + packageInfo.packageName); Log.d(TAG, "APK Path: " + apkPath); } // Check if it is being updated using offline storage if (!offlineSupport && fromOfflineStorage) { Log.e(TAG, "Updating from offline storage is disabled for this app?"); return false; } db.clearDevicesList(); for (int i = 0; i < devices.length(); i++) { String device = devices.getString(i); if (device.length() > 0 && deviceID.compareToIgnoreCase(device) == 0) allowed = true; db.insertDevice(device); if (enableDebug) Log.d(TAG, "Device Allowed: " + device); } // DeviceID or signature error if (!allowed) return false; apkUpdatePath = null; if (version > neoUpdateVersion && forceVersion) { Log.e(TAG, "neoUpdate seems to be of older version! Required: " + version + " Current: " + neoUpdateVersion); return false; } if (packageInfo.packageName.compareTo(packageName) != 0) { Log.e(TAG, "PackageNames don't seem to match - url for some other app? Provided: " + packageName); return false; } if (packageInfo.versionCode < versionCode) { // APK Update Required - Lets first do that apkUpdatePath = new NewAsset(); apkUpdatePath.path = apkPath; apkUpdatePath.md5 = appDetails.getString("md5"); return true; } // Parse the assets for (int i = 0; i < nAssets; i++) { JSONObject obj = assets.getJSONObject(i); NewAsset asset = new NewAsset(); asset.path = obj.getString("path"); asset.md5 = obj.getString("md5"); // Ignore already downloaded files if (db.updateAndGetStatus(asset.path, asset.md5) == neoUpdateDB.UPDATE_STATUS.UPDATE_COMPLETE) continue; filesToDownload.add(asset); if (enableDebug) { Log.d(TAG, "Enqueued: " + asset.path + " With MD5: " + asset.md5); } } totalFilesToDownload = filesToDownload.size(); } catch (Exception e) { if (enableDebug) e.printStackTrace(); return false; } return true; }
From source file:org.alfresco.integrations.google.docs.webscripts.SaveContent.java
private Map<String, Serializable> parseContent(final WebScriptRequest req) { final Map<String, Serializable> result = new HashMap<String, Serializable>(); Content content = req.getContent();// w w w. jav a 2 s . c o m String jsonStr = null; JSONObject json = null; try { if (content == null || content.getSize() == 0) { throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "No content sent with request."); } jsonStr = content.getContent(); if (jsonStr == null || jsonStr.trim().length() == 0) { throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "No content sent with request."); } log.debug("Parsed JSON: " + jsonStr); json = new JSONObject(jsonStr); if (!json.has(JSON_KEY_NODEREF)) { throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "Key " + JSON_KEY_NODEREF + " is missing from JSON: " + jsonStr); } else { NodeRef nodeRef = new NodeRef(json.getString(JSON_KEY_NODEREF)); result.put(JSON_KEY_NODEREF, nodeRef); if (json.has(JSON_KEY_OVERRIDE)) { result.put(JSON_KEY_OVERRIDE, json.getBoolean(JSON_KEY_OVERRIDE)); } else { result.put(JSON_KEY_OVERRIDE, false); } if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE)) { result.put(JSON_KEY_MAJORVERSION, json.getBoolean(JSON_KEY_MAJORVERSION) ? VersionType.MAJOR : VersionType.MINOR); result.put(JSON_KEY_DESCRIPTION, json.getString(JSON_KEY_DESCRIPTION)); } if (json.has(JSON_KEY_REMOVEFROMDRIVE)) { result.put(JSON_KEY_REMOVEFROMDRIVE, json.getBoolean(JSON_KEY_REMOVEFROMDRIVE)); } } } catch (final IOException ioe) { throw new WebScriptException(HttpStatus.SC_INTERNAL_SERVER_ERROR, ioe.getMessage(), ioe); } catch (final JSONException je) { throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "Unable to parse JSON: " + jsonStr); } catch (final WebScriptException wse) { throw wse; // Ensure WebScriptExceptions get rethrown verbatim } catch (final Exception e) { throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "Unable to parse JSON '" + jsonStr + "'.", e); } return result; }
From source file:org.wso2.emm.agent.services.PolicyTester.java
@SuppressWarnings("static-access") @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public boolean testPolicy(String code, String data) { if (code.equals(CommonUtilities.OPERATION_CLEAR_PASSWORD)) { ComponentName demoDeviceAdmin = new ComponentName(context, WSO2DeviceAdminReceiver.class); JSONObject jobj = new JSONObject(); // data = intent.getStringExtra("data"); try {/*from w w w . j a v a2 s . co m*/ Map<String, String> params = new HashMap<String, String>(); params.put("code", code); params.put("status", "200"); if (IS_ENFORCE) { devicePolicyManager.setPasswordQuality(demoDeviceAdmin, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED); devicePolicyManager.resetPassword("", DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY); devicePolicyManager.lockNow(); devicePolicyManager.setPasswordQuality(demoDeviceAdmin, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED); jobj.put("status", true); } else { if (devicePolicyManager.getPasswordQuality( demoDeviceAdmin) != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { jobj.put("status", false); } else { jobj.put("status", true); } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { jobj.put("code", code); //finalArray.put(jobj); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else if (code.equals(CommonUtilities.OPERATION_WIFI)) { boolean wifistatus = false; JSONObject jobjc = new JSONObject(); WiFiConfig config = new WiFiConfig(context); // data = intent.getStringExtra("data"); JSONParser jp = new JSONParser(); try { JSONObject jobj = new JSONObject(data); if (!jobj.isNull("ssid")) { ssid = (String) jobj.get("ssid"); } if (!jobj.isNull("password")) { password = (String) jobj.get("password"); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } Map<String, String> inparams = new HashMap<String, String>(); inparams.put("code", code); if (IS_ENFORCE) { try { wifistatus = config.saveWEPConfig(ssid, password); jobjc.put("status", true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { if (config.readWEPConfig(ssid)) { jobjc.put("status", true); } else { jobjc.put("status", false); if (usermessage != null && usermessage != "") { usermessage += "\nYou are not using company WIFI account, please change your WIFI configuration \n"; } else { usermessage += "You are not using company WIFI account, please change your WIFI configuration \n"; } } jobjc.put("code", code); finalArray.put(jobjc); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else if (code.equals(CommonUtilities.OPERATION_DISABLE_CAMERA)) { ComponentName cameraAdmin = new ComponentName(context, WSO2DeviceAdminReceiver.class); boolean camFunc = false; // data = intent.getStringExtra("data"); JSONParser jp = new JSONParser(); try { JSONObject jobj = new JSONObject(data); if (!jobj.isNull("function") && jobj.get("function").toString().equalsIgnoreCase("enable")) { camFunc = false; } else if (!jobj.isNull("function") && jobj.get("function").toString().equalsIgnoreCase("disable")) { camFunc = true; } else if (!jobj.isNull("function")) { camFunc = Boolean.parseBoolean(jobj.get("function").toString()); } Map<String, String> params = new HashMap<String, String>(); params.put("code", code); params.put("status", "200"); String cammode = "Disabled"; if (camFunc) { cammode = "Disabled"; } else { cammode = "Enabled"; } if (IS_ENFORCE && (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)) { devicePolicyManager.setCameraDisabled(cameraAdmin, camFunc); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONObject jobj = new JSONObject(); try { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { if (!camFunc) { if (!devicePolicyManager.getCameraDisabled(cameraAdmin)) { jobj.put("status", true); } else { jobj.put("status", false); } } else { if (devicePolicyManager.getCameraDisabled(cameraAdmin)) { jobj.put("status", true); } else { jobj.put("status", false); /*if(usermessage!=null && usermessage!=""){ usermessage+="\nYour camera should be deactivated according to the policy, please deactivate your camera\n"; }else{ usermessage+="Your camera should be deactivated according to the policy, please deactivate your camera \n"; }*/ } } } else { jobj.put("status", false); } jobj.put("code", code); finalArray.put(jobj); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else if (code.equals(CommonUtilities.OPERATION_ENCRYPT_STORAGE)) { boolean encryptFunc = true; String pass = ""; JSONParser jp = new JSONParser(); try { JSONObject jobj = new JSONObject(data); if (!jobj.isNull("function") && jobj.get("function").toString().equalsIgnoreCase("encrypt")) { encryptFunc = true; } else if (!jobj.isNull("function") && jobj.get("function").toString().equalsIgnoreCase("decrypt")) { encryptFunc = false; } else if (!jobj.isNull("function")) { encryptFunc = Boolean.parseBoolean(jobj.get("function").toString()); } ComponentName admin = new ComponentName(context, WSO2DeviceAdminReceiver.class); Map<String, String> params = new HashMap<String, String>(); params.put("code", code); if (IS_ENFORCE) { if (encryptFunc && devicePolicyManager .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) { if (devicePolicyManager .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_INACTIVE) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { devicePolicyManager.setStorageEncryption(admin, encryptFunc); Intent intent = new Intent(DevicePolicyManager.ACTION_START_ENCRYPTION); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } } } else if (!encryptFunc && devicePolicyManager .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) { if (devicePolicyManager .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_ACTIVE || devicePolicyManager .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_ACTIVATING) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { devicePolicyManager.setStorageEncryption(admin, encryptFunc); } } } } if (devicePolicyManager .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) { params.put("status", "200"); } else { params.put("status", "400"); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONObject jobj = new JSONObject(); try { jobj.put("code", code); if (encryptFunc) { if (devicePolicyManager .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED && devicePolicyManager .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_INACTIVE) { jobj.put("status", true); } else { jobj.put("status", false); if (usermessage != null && usermessage != "") { usermessage += "\nYour device should be encrypted according to the policy, please enable device encryption through device settings\n"; } else { usermessage += "Your device should be encrypted according to the policy, please enable device encryption through device settings \n"; } } } else { if (devicePolicyManager .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED || devicePolicyManager .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_INACTIVE) { jobj.put("status", true); } else { jobj.put("status", false); } } finalArray.put(jobj); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else if (code.equals(CommonUtilities.OPERATION_MUTE)) { try { Map<String, String> params = new HashMap<String, String>(); params.put("code", code); params.put("status", "200"); if (IS_ENFORCE) { muteDevice(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONObject jobj = new JSONObject(); try { jobj.put("code", code); if (isMuted()) { jobj.put("status", true); } else { jobj.put("status", false); if (usermessage != null && usermessage != "") { usermessage += "\nYour phone should be muted according to the policy, please mute your phone \n"; } else { usermessage += "Your phone should be muted according to the policy, please mute your phone \n"; } } finalArray.put(jobj); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else if (code.equals(CommonUtilities.OPERATION_PASSWORD_POLICY)) { ComponentName demoDeviceAdmin = new ComponentName(context, WSO2DeviceAdminReceiver.class); JSONObject jobjx = new JSONObject(); int attempts, length, history, specialChars; String alphanumeric, complex; boolean b_alphanumeric = false, b_complex = false, is_comply = true, comply_fac1 = true, comply_fac2 = true, comply_fac3 = true, comply_fac4 = true, comply_fac5 = true, comply_fac6 = true, comply_fac7 = true; long timout; Map<String, String> inparams = new HashMap<String, String>(); // data = intent.getStringExtra("data"); JSONParser jp = new JSONParser(); try { JSONObject jobjpass = new JSONObject(); jobjpass.put("code", CommonUtilities.OPERATION_CHANGE_LOCK_CODE); if (devicePolicyManager.isActivePasswordSufficient()) { is_comply = true; //finalArray.put(jobjpass); } else { is_comply = false; } JSONObject jobj = new JSONObject(data); if (!jobj.isNull("maxFailedAttempts") && jobj.get("maxFailedAttempts") != null) { attempts = Integer.parseInt((String) jobj.get("maxFailedAttempts")); if (IS_ENFORCE) { devicePolicyManager.setMaximumFailedPasswordsForWipe(demoDeviceAdmin, attempts); comply_fac1 = true; } else { if (devicePolicyManager.getMaximumFailedPasswordsForWipe(demoDeviceAdmin) != attempts) { comply_fac1 = false; } else { comply_fac1 = true; } } } if (!jobj.isNull("minLength") && jobj.get("minLength") != null) { length = Integer.parseInt((String) jobj.get("minLength")); if (IS_ENFORCE) { devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, length); comply_fac2 = true; } else { if (devicePolicyManager.getPasswordMinimumLength(demoDeviceAdmin) != length) { comply_fac2 = false; } else { comply_fac2 = true; } } } if (!jobj.isNull("pinHistory") && jobj.get("pinHistory") != null) { history = Integer.parseInt((String) jobj.get("pinHistory")); if (IS_ENFORCE) { devicePolicyManager.setPasswordHistoryLength(demoDeviceAdmin, history); comply_fac3 = true; } else { if (devicePolicyManager.getPasswordHistoryLength(demoDeviceAdmin) != history) { comply_fac3 = false; } else { comply_fac3 = true; } } } if (!jobj.isNull("minComplexChars") && jobj.get("minComplexChars") != null) { specialChars = Integer.parseInt((String) jobj.get("minComplexChars")); if (IS_ENFORCE) { devicePolicyManager.setPasswordMinimumSymbols(demoDeviceAdmin, specialChars); comply_fac4 = true; } else { if (devicePolicyManager.getPasswordMinimumSymbols(demoDeviceAdmin) != specialChars) { comply_fac4 = false; } else { comply_fac4 = true; } } } if (!jobj.isNull("requireAlphanumeric") && jobj.get("requireAlphanumeric") != null) { if (jobj.get("requireAlphanumeric") instanceof String) { alphanumeric = (String) jobj.get("requireAlphanumeric").toString(); if (alphanumeric.equals("true")) { b_alphanumeric = true; } else { b_alphanumeric = false; } } else if (jobj.get("requireAlphanumeric") instanceof Boolean) { b_alphanumeric = jobj.getBoolean("requireAlphanumeric"); } if (b_alphanumeric) { if (IS_ENFORCE) { devicePolicyManager.setPasswordQuality(demoDeviceAdmin, DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC); comply_fac5 = true; } else { if (devicePolicyManager.getPasswordQuality( demoDeviceAdmin) != DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC) { comply_fac5 = false; } else { comply_fac5 = true; } } } else { if (devicePolicyManager.getPasswordQuality( demoDeviceAdmin) == DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC) { comply_fac5 = false; } else { comply_fac5 = true; } } } if (!jobj.isNull("allowSimple") && jobj.get("allowSimple") != null) { if (jobj.get("allowSimple") instanceof String) { complex = (String) jobj.get("allowSimple").toString(); if (complex.equals("true")) { b_complex = true; } else { b_complex = false; } } else if (jobj.get("allowSimple") instanceof Boolean) { b_complex = jobj.getBoolean("allowSimple"); } if (!b_complex) { if (IS_ENFORCE) { devicePolicyManager.setPasswordQuality(demoDeviceAdmin, DevicePolicyManager.PASSWORD_QUALITY_COMPLEX); comply_fac6 = true; } else { if (devicePolicyManager.getPasswordQuality( demoDeviceAdmin) != DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) { comply_fac6 = false; } else { comply_fac6 = true; } } } else { if (devicePolicyManager.getPasswordQuality( demoDeviceAdmin) == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) { comply_fac6 = false; } else { comply_fac6 = true; } } } if (!jobj.isNull("maxPINAgeInDays") && jobj.get("maxPINAgeInDays") != null) { int daysOfExp = Integer.parseInt((String) jobj.get("maxPINAgeInDays")); timout = (long) (daysOfExp * 24 * 60 * 60 * 1000); if (IS_ENFORCE) { devicePolicyManager.setPasswordExpirationTimeout(demoDeviceAdmin, timout); comply_fac7 = true; } else { if (devicePolicyManager.getPasswordExpirationTimeout(demoDeviceAdmin) != timout) { comply_fac7 = false; } else { comply_fac7 = true; } } } if (!is_comply || !comply_fac1 || !comply_fac2 || !comply_fac3 || !comply_fac4 || !comply_fac5 || !comply_fac6 || !comply_fac7) { jobjx.put("status", false); if (usermessage != null && usermessage != "") { usermessage += "\nYour screen lock password doesn't meet current policy requirement. Please reset your passcode \n"; } else { usermessage += "Your screen lock password doesn't meet current policy requirement. Please reset your passcode \n"; } } else { jobjx.put("status", true); } inparams.put("code", code); inparams.put("status", "200"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { jobjx.put("code", code); finalArray.put(jobjx); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else if (code.equals(CommonUtilities.OPERATION_BLACKLIST_APPS)) { ArrayList<PInfo> apps = appList.getInstalledApps(false); /* * false = * no system * packages */ JSONArray jsonArray = new JSONArray(); int max = apps.size(); Boolean flag = true; try { JSONObject appObj = new JSONObject(data); String identity = (String) appObj.get("identity"); for (int j = 0; j < max; j++) { JSONObject jsonObj = new JSONObject(); try { jsonObj.put("name", apps.get(j).appname); jsonObj.put("package", apps.get(j).pname); if (identity.trim().equals(apps.get(j).pname)) { jsonObj.put("notviolated", false); flag = false; jsonObj.put("package", apps.get(j).pname); if (apps.get(j).appname != null) { appcount++; apz = appcount + ". " + apps.get(j).appname; } if (apz != null || !apz.trim().equals("")) { if (usermessage != null && usermessage != "") { if (appcount > 1) { usermessage += "\n" + apz; } else { usermessage += "\nFollowing apps are blacklisted by your MDM Admin, please remove them \n\n" + apz; } } else { if (appcount > 1) { usermessage += "\n" + apz; } else { usermessage += "Following apps are blacklisted by your MDM Admin, please remove them \n\n" + apz; } } } } else { jsonObj.put("notviolated", true); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } jsonArray.put(jsonObj); } } catch (Exception ex) { ex.printStackTrace(); } /* * for(int i=0;i<apps.length;i++){ jsonArray.add(apps[i]); } */ JSONObject appsObj = new JSONObject(); try { //appsObj.put("data", jsonArray); appsObj.put("status", flag); appsObj.put("code", code); finalArray.put(appsObj); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } return true; }
From source file:model.Annonce.java
@Override public void update(final JSONObject item) throws JSONException { setContent(item.getString("content")); setRank(item.getInt("rank")); setIsVisible(item.getBoolean("visibility")); setTitle(item.getString("title")); setDate(new DateTime(item.getString("date"))); }
From source file:com.nginious.http.serialize.JsonDeserializer.java
/** * Deserializes property with the specified name from the specified json object into a boolean value. * /*from w ww . ja va 2s . co m*/ * @param object the given json object * @param name the given property name * @return the deserialized boolean value or <code>false</code> if property doesn't exist * @throws SerializerException if unable to deserialize boolean property */ protected boolean deserializeBoolean(JSONObject object, String name) throws SerializerException { if (!object.has(name)) { return false; } try { return object.getBoolean(name); } catch (JSONException e) { throw new SerializerException("Can't deserialize boolean property " + name, e); } }
From source file:com.krayzk9s.imgurholo.ui.ImagesFragment.java
public void onGetObject(Object object, String tag) { if (tag.equals(IMAGES)) { ImgurHoloActivity activity = (ImgurHoloActivity) getActivity(); if (activity == null) return; SharedPreferences settings = activity.getApiCall().settings; JSONObject data = (JSONObject) object; Log.d("imagesData", "checking"); Log.d("imagesData", "failed"); JSONArray imageArray = new JSONArray(); try {/*from www.j av a 2 s . c o m*/ Log.d("URI", data.toString()); imageArray = data.getJSONArray("data"); } catch (JSONException e) { try { imageArray = data.getJSONObject("data").getJSONArray("images"); } catch (JSONException e2) { Log.e("Error!", e2.toString() + data.toString()); } } try { Boolean changed = false; for (int i = 0; i < imageArray.length(); i++) { JSONObject imageData = imageArray.getJSONObject(i); String s = ""; if (isGridView) s = settings.getString("IconQuality", "m"); try { if (imageData.has("is_album") && imageData.getBoolean("is_album")) { if (!urls.contains("http://imgur.com/" + imageData.getString(ImgurHoloActivity.IMAGE_DATA_COVER) + s + ".png")) { changed = true; urls.add("http://imgur.com/" + imageData.getString(ImgurHoloActivity.IMAGE_DATA_COVER) + s + ".png"); JSONParcelable dataParcel = new JSONParcelable(); dataParcel.setJSONObject(imageData); ids.add(dataParcel); } } else { if (!urls.contains("http://imgur.com/" + imageData.getString("id") + s + ".png")) { changed = true; urls.add("http://imgur.com/" + imageData.getString("id") + s + ".png"); JSONParcelable dataParcel = new JSONParcelable(); dataParcel.setJSONObject(imageData); ids.add(dataParcel); } } } catch (RejectedExecutionException e) { Log.e("Rejected", e.toString()); } } fetchingImages = !changed; } catch (JSONException e) { Log.e("Error!", e.toString() + "here"); } if (!isGridView && urls.size() > 0) { restoreCards(); } else if (urls.size() > 0) { imageAdapter.notifyDataSetChanged(); } else if (urls.size() == 0 && noImageView != null) noImageView.setVisibility(View.VISIBLE); else { fetchingImages = true; } if (mPullToRefreshLayout != null) mPullToRefreshLayout.setRefreshComplete(); errorText.setVisibility(View.GONE); } }
From source file:com.facebook.config.BooleanExtractor.java
@Override public Boolean extract(String key, JSONObject jsonObject) throws JSONException { return jsonObject.getBoolean(key); }
From source file:de.jaetzold.philips.hue.HueLightBulb.java
void parseLight(JSONObject lightJson) { name = lightJson.getString("name"); if (lightJson.has("state")) { final JSONObject state = lightJson.getJSONObject("state"); on = state.getBoolean("on"); brightness = state.getInt("bri"); hue = state.getInt("hue"); saturation = state.getInt("sat"); ciex = state.getJSONArray("xy").getDouble(0); ciey = state.getJSONArray("xy").getDouble(1); colorTemperature = state.getInt("ct"); colorMode = new ColorMode[] { HS, XY, CT }[Arrays.asList("hs", "xy", "ct") .indexOf(state.getString("colormode").toLowerCase())]; final Effect effect = Effect.fromName(state.getString("effect")); if (effect == null) { throw new HueCommException("Can not find effect named \"" + state.getString("effect") + "\""); }//from www . j a v a 2 s .c om this.effect = effect; lastSyncTime = System.currentTimeMillis(); } else { sync(); } }
From source file:org.alfresco.integrations.google.docs.webscripts.UploadContent.java
private Map<String, Serializable> parseContent(final WebScriptRequest req) { final Map<String, Serializable> result = new HashMap<String, Serializable>(); Content content = req.getContent();//from w w w .ja v a 2 s .c om String jsonStr = null; JSONObject json = null; try { if (content == null || content.getSize() == 0) { return result; } jsonStr = content.getContent(); if (jsonStr == null || jsonStr.trim().length() == 0) { throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "No content sent with request."); } log.debug("Parsed JSON: " + jsonStr); json = new JSONObject(jsonStr); if (json.has(JSON_KEY_PERMISSIONS)) { JSONObject permissionData = json.getJSONObject(JSON_KEY_PERMISSIONS); boolean sendEmail = permissionData.has(JSON_KEY_PERMISSIONS_SEND_EMAIL) ? permissionData.getBoolean(JSON_KEY_PERMISSIONS_SEND_EMAIL) : true; if (!permissionData.has(JSON_KEY_PERMISSIONS_ITEMS)) { throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "Key " + JSON_KEY_PERMISSIONS_ITEMS + " is missing from JSON object: " + permissionData.toString()); } JSONArray jsonPerms = permissionData.getJSONArray(JSON_KEY_PERMISSIONS_ITEMS); ArrayList<GooglePermission> permissions = new ArrayList<GoogleDocsService.GooglePermission>( jsonPerms.length()); for (int i = 0; i < jsonPerms.length(); i++) { JSONObject jsonPerm = jsonPerms.getJSONObject(i); String authorityId, authorityType, roleName; if (jsonPerm.has(JSON_KEY_AUTHORITY_ID)) { authorityId = jsonPerm.getString(JSON_KEY_AUTHORITY_ID); } else { throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "Key " + JSON_KEY_AUTHORITY_ID + " is missing from JSON object: " + jsonPerm.toString()); } if (jsonPerm.has(JSON_KEY_AUTHORITY_TYPE)) { authorityType = jsonPerm.getString(JSON_KEY_AUTHORITY_TYPE); } else { authorityType = JSON_VAL_AUTHORITY_TYPE_DEFAULT; } if (jsonPerm.has(JSON_KEY_ROLE_NAME)) { roleName = jsonPerm.getString(JSON_KEY_ROLE_NAME); } else { throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "Key " + JSON_KEY_ROLE_NAME + " is missing from JSON object: " + jsonPerm.toString()); } permissions.add(new GooglePermission(authorityId, authorityType, roleName)); } result.put(PARAM_PERMISSIONS, permissions); result.put(PARAM_SEND_EMAIL, Boolean.valueOf(sendEmail)); } } catch (final IOException ioe) { throw new WebScriptException(HttpStatus.SC_INTERNAL_SERVER_ERROR, ioe.getMessage(), ioe); } catch (final JSONException je) { throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "Unable to parse JSON: " + jsonStr); } catch (final WebScriptException wse) { throw wse; // Ensure WebScriptExceptions get rethrown verbatim } catch (final Exception e) { throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "Unable to parse JSON '" + jsonStr + "'.", e); } return result; }