List of usage examples for org.json.simple JSONObject get
V get(Object key);
From source file:net.amigocraft.mpt.command.UpgradeCommand.java
/** * Attempts to upgrade a package by the given ID * <strong>This method may not be called from the main thread.</strong> * @param id the ID of the package to upgrade * @return the new version, or null if the package was not upgraded * @throws MPTException if called from the main thread, or if something goes wrong while upgrading *//* w ww. j a v a2s . c om*/ public static String upgradePackage(String id) throws MPTException { if (Thread.currentThread().getId() == Main.mainThreadId) throw new MPTException(ERROR_COLOR + "Packages may not be upgraded from the main thread!"); id = id.toLowerCase(); if (Main.packageStore.containsKey("packages") && ((JSONObject) Main.packageStore.get("packages")).containsKey(id)) { JSONObject pack = (JSONObject) ((JSONObject) Main.packageStore.get("packages")).get(id); if (pack.containsKey("installed")) { if (pack.containsKey("version")) { int diff = compareVersions(pack.get("installed").toString(), pack.get("version").toString()); if (diff > 0) { // easy way out RemoveCommand.removePackage(id); InstallCommand.downloadPackage(id); InstallCommand.installPackage(id); return pack.get("version").toString(); } else // up-to-date return null; } else throw new MPTException(ERROR_COLOR + "Package " + ID_COLOR + id + ERROR_COLOR + " is missing version string! Type " + COMMAND_COLOR + "/mpt update" + ERROR_COLOR + " to fix this."); } else throw new MPTException( ERROR_COLOR + "Package " + ID_COLOR + id + ERROR_COLOR + " is not installed!"); } return null; }
From source file:com.apigee.edge.config.mavenplugin.APIProductMojo.java
public static List getAPIProduct(ServerProfile profile) throws IOException { HttpResponse response = RestUtil.getOrgConfig(profile, "apiproducts"); if (response == null) return new ArrayList(); JSONArray products = null;/*from w w w . j a v a 2s. c o m*/ try { logger.debug("output " + response.getContentType()); // response can be read only once String payload = response.parseAsString(); logger.debug(payload); /* Parsers fail to parse a string array. * converting it to an JSON object as a workaround */ String obj = "{ \"products\": " + payload + "}"; JSONParser parser = new JSONParser(); JSONObject obj1 = (JSONObject) parser.parse(obj); products = (JSONArray) obj1.get("products"); } catch (ParseException pe) { logger.error("Get API Product parse error " + pe.getMessage()); throw new IOException(pe.getMessage()); } catch (HttpResponseException e) { logger.error("Get API Product error " + e.getMessage()); throw new IOException(e.getMessage()); } return products; }
From source file:com.apigee.edge.config.mavenplugin.CacheMojo.java
public static List getCache(ServerProfile profile) throws IOException { HttpResponse response = RestUtil.getEnvConfig(profile, "caches"); if (response == null) return new ArrayList(); JSONArray caches = null;// w w w . j a v a2 s . c om try { logger.debug("output " + response.getContentType()); // response can be read only once String payload = response.parseAsString(); logger.debug(payload); /* Parsers fail to parse a string array. * converting it to an JSON object as a workaround */ String obj = "{ \"caches\": " + payload + "}"; JSONParser parser = new JSONParser(); JSONObject obj1 = (JSONObject) parser.parse(obj); caches = (JSONArray) obj1.get("caches"); } catch (ParseException pe) { logger.error("Get Cache parse error " + pe.getMessage()); throw new IOException(pe.getMessage()); } catch (HttpResponseException e) { logger.error("Get Cache error " + e.getMessage()); throw new IOException(e.getMessage()); } return caches; }
From source file:ch.newscron.encryption.Encryption.java
/** * Given a JSONObject, extracts its fields and computes the hash using the MD5 algorithm * @param obj is a JSONObject consisting of the four fields * @return a MD5 hash of type byte[]//from w ww. j a va 2s . c o m */ public static byte[] createMD5Hash(JSONObject obj) { //Create a string of the fields with format: "<customerId>$<rew1>$<rew2>$<val>" StringJoiner stringToHash = new StringJoiner("$"); stringToHash.add((String) obj.get("custID")); stringToHash.add((String) obj.get("rew1")); stringToHash.add((String) obj.get("rew2")); stringToHash.add((String) obj.get("val")); //Get hash of string try { MessageDigest m = MessageDigest.getInstance("MD5"); byte[] hash = m.digest(stringToHash.toString().getBytes("UTF-8")); return hash; } catch (Exception e) { } return null; }
From source file:com.apigee.edge.config.mavenplugin.DeveloperMojo.java
public static List getDeveloper(ServerProfile profile) throws IOException { HttpResponse response = RestUtil.getOrgConfig(profile, "developers"); if (response == null) return new ArrayList(); JSONArray developers = null;/* ww w . ja va 2 s . co m*/ try { logger.debug("output " + response.getContentType()); // response can be read only once String payload = response.parseAsString(); logger.debug(payload); /* Parsers fail to parse a string array. * converting it to an JSON object as a workaround */ String obj = "{ \"developers\": " + payload + "}"; JSONParser parser = new JSONParser(); JSONObject obj1 = (JSONObject) parser.parse(obj); developers = (JSONArray) obj1.get("developers"); } catch (ParseException pe) { logger.error("Get Developer parse error " + pe.getMessage()); throw new IOException(pe.getMessage()); } catch (HttpResponseException e) { logger.error("Get Developer error " + e.getMessage()); throw new IOException(e.getMessage()); } return developers; }
From source file:com.apigee.edge.config.mavenplugin.AppMojo.java
public static List getApp(ServerProfile profile, String developerId) throws IOException { HttpResponse response = RestUtil.getOrgConfig(profile, "developers/" + developerId + "/apps"); if (response == null) return new ArrayList(); JSONArray apps = null;//from w w w . j a v a 2 s. c o m try { logger.debug("output " + response.getContentType()); // response can be read only once String payload = response.parseAsString(); logger.debug(payload); /* Parsers fail to parse a string array. * converting it to an JSON object as a workaround */ String obj = "{ \"apps\": " + payload + "}"; JSONParser parser = new JSONParser(); JSONObject obj1 = (JSONObject) parser.parse(obj); apps = (JSONArray) obj1.get("apps"); } catch (ParseException pe) { logger.error("Get App parse error " + pe.getMessage()); throw new IOException(pe.getMessage()); } catch (HttpResponseException e) { logger.error("Get Apps error " + e.getMessage()); throw new IOException(e.getMessage()); } return apps; }
From source file:com.orthancserver.DicomDecoder.java
private static void ExtractCalibration(ImagePlus image, JSONObject tags) { JSONObject rescaleIntercept = (JSONObject) tags.get("0028,1052"); JSONObject rescaleSlope = (JSONObject) tags.get("0028,1053"); if (rescaleIntercept != null && rescaleSlope != null) { double[] coeff = { Float.valueOf((String) rescaleIntercept.get("Value")), Float.valueOf((String) rescaleSlope.get("Value")) }; image.getCalibration().setFunction(Calibration.STRAIGHT_LINE, coeff, "Gray Value"); }/*from w w w . j av a2 s . c o m*/ }
From source file:io.tempra.AppServer.java
public static String getProperty(String string) { // TODO Auto-generated method stub try {/*from w w w.j a v a 2 s . co m*/ // sample to handle params on a json string on a system properties String s = System.getenv("VERSATILE.CONFIG"); org.json.simple.JSONObject json = (JSONObject) JSONValue.parse(s); return (String) json.get(string).toString(); } catch (Exception e) { InputStream in = AppServer.class.getResourceAsStream("/properties.json"); org.json.simple.JSONObject json = null; try { String s = convertStreamToString(in); json = (JSONObject) JSONValue.parse(s); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return (String) json.get(string); } }
From source file:com.fujitsu.dc.test.jersey.bar.BarInstallTestUtils.java
/** * bar?????????./*from www . ja v a 2 s .co m*/ * @param location bar??API?URL * @param schemaUrl URL * @param status ? */ public static void assertBarInstallStatus(String location, String schemaUrl, ProgressInfo.STATUS status) { waitBoxInstallCompleted(location); DcResponse res = ODataCommon.getOdataResource(location); assertEquals(HttpStatus.SC_OK, res.getStatusCode()); JSONObject bodyJson = (JSONObject) ((JSONObject) res.bodyAsJson()); assertEquals(status.value(), bodyJson.get("status")); assertEquals(schemaUrl, bodyJson.get("schema")); if (ProgressInfo.STATUS.FAILED == status) { assertNotNull(bodyJson.get("started_at")); assertNull(bodyJson.get("installed_at")); assertNotNull(bodyJson.get("progress")); assertNotNull(bodyJson.get("message")); assertNotNull(((JSONObject) bodyJson.get("message")).get("code")); assertNotNull(((JSONObject) bodyJson.get("message")).get("message")); assertNotNull(((JSONObject) ((JSONObject) bodyJson.get("message")).get("message")).get("value")); assertNotNull(((JSONObject) ((JSONObject) bodyJson.get("message")).get("message")).get("lang")); } else { assertNull(bodyJson.get("started_at")); assertNotNull(bodyJson.get("installed_at")); assertNull(bodyJson.get("progress")); } }
From source file:com.orthancserver.DicomDecoder.java
private static void ExtractPixelSpacing(ImagePlus image, JSONObject tags) { JSONObject pixelSpacing = (JSONObject) tags.get("0028,0030"); if (pixelSpacing != null) { String[] tokens = ((String) pixelSpacing.get("Value")).split("\\\\"); if (tokens.length == 2) { FileInfo fi = image.getFileInfo(); fi.pixelWidth = Float.valueOf(tokens[0]); fi.pixelHeight = Float.valueOf(tokens[1]); fi.unit = "mm"; image.setFileInfo(fi);// ww w .j a va 2s .c om image.getCalibration().pixelWidth = fi.pixelWidth; image.getCalibration().pixelHeight = fi.pixelHeight; image.getCalibration().setUnit(fi.unit); } } }