List of usage examples for org.json.simple JSONObject put
V put(K key, V value);
From source file:com.dubture.symfony.core.util.JsonUtils.java
@SuppressWarnings("unchecked") public static JSONObject createBundle(ISourceModule sourceModule, ClassDeclaration classDec, NamespaceDeclaration namespace) { JSONObject bundle = new JSONObject(); bundle.put(Bundle.NAME, classDec.getName()); bundle.put(Bundle.NAMESPACE, namespace != null ? namespace.getName() : ""); bundle.put(Bundle.PATH, sourceModule.getPath().removeLastSegments(1).toString()); return bundle; }
From source file:msuresh.raftdistdb.RaftCluster.java
private static void UpdatePortNumber() { try {/* w w w . j av a 2 s. c o m*/ JSONParser parser = new JSONParser(); Object obj = parser.parse(new FileReader(Constants.STATE_LOCATION + "global.info")); JSONObject jsonObject = (JSONObject) obj; jsonObject.put("currentCount", portId); try (FileWriter file = new FileWriter(Constants.STATE_LOCATION + "global.info")) { file.write(jsonObject.toJSONString()); } } catch (Exception e) { } }
From source file:com.fujitsu.dc.test.utils.RelationUtils.java
/** * NP?Relation??.//ww w . ja va2 s . c o m * @param cellName ?? * @param token * @param boxName ?? * @param relationName ?? * @param code ? * @return ? */ @SuppressWarnings("unchecked") public static TResponse createViaNP(final String cellName, final String token, final String boxName, final String relationName, final int code) { JSONObject body = new JSONObject(); body.put("Name", relationName); TResponse res = Http.request("createNP.txt").with("token", token).with("accept", MediaType.APPLICATION_JSON) .with("contentType", MediaType.APPLICATION_JSON).with("cell", cellName).with("entityType", "Box") .with("id", boxName).with("navPropName", "_Relation").with("body", body.toString()).returns(); assertEquals(code, res.getStatusCode()); return res; }
From source file:msuresh.raftdistdb.RaftCluster.java
/** * creates the cluster //ww w. j ava2 s . c om * @param nodesInCluster * @param numberOfPartitions * @throws InterruptedException */ public static void createCluster(String name, int nodesInCluster, int numberOfPartitions) throws InterruptedException, ExecutionException { InitPortNumber(); try { JSONObject cluster = new JSONObject(); cluster.put("name", name); cluster.put("countReplicas", nodesInCluster); cluster.put("countPartitions", numberOfPartitions); for (int i = 0; i < numberOfPartitions; i++) cluster.put(i, CreatePartitionCluster(nodesInCluster)); JSONString.ConvertJSON2File(cluster, Constants.STATE_LOCATION + name + ".info"); UpdatePortNumber(); System.out.println("Database " + name + " has been created. "); } catch (Exception ex) { System.out.println(ex.toString()); } }
From source file:org.jboss.aerogear.unifiedpush.test.util.AuthenticationUtils.java
public static boolean changePassword(String loginName, String oldPassword, String newPassword, String root) { Validate.notNull(root);//from w w w. j av a2 s . c o m JSONObject jsonObject = new JSONObject(); jsonObject.put("loginName", loginName); jsonObject.put("password", oldPassword); jsonObject.put("newPassword", newPassword); // FIXME should not this be using already existing session? Response response = Session.newSession(root).given().contentType(ContentTypes.json()) .header(Headers.acceptJson()).body(jsonObject.toJSONString()).put("/rest/auth/update"); if (response.statusCode() == HttpStatus.SC_OK) { return true; } else if (response.statusCode() == HttpStatus.SC_UNAUTHORIZED) { throw new InvalidPasswordException(response); } else { throw new UnexpectedResponseException(response); } }
From source file:org.jboss.aerogear.unifiedpush.test.util.AuthenticationUtils.java
public static Session login(String loginName, String password, String root) throws NullPointerException, UnexpectedResponseException { Validate.notNull(root);/*from w w w .ja v a2s . co m*/ JSONObject jsonObject = new JSONObject(); jsonObject.put("loginName", loginName); jsonObject.put("password", password); Response response = Session.newSession(root).given().contentType(ContentTypes.json()) .header(Headers.acceptJson()).body(jsonObject.toJSONString()).post("/rest/auth/login"); // TODO should we throw or return invalid session? if (response.statusCode() == HttpStatus.SC_OK) { return new Session(root, loginName, password, response.cookies()); } else if (response.statusCode() == HttpStatus.SC_FORBIDDEN) { throw new ExpiredPasswordException(response); } else if (response.statusCode() == HttpStatus.SC_UNAUTHORIZED) { throw new InvalidPasswordException(response); } else { // This should never happen throw new UnexpectedResponseException(response); } }
From source file:edu.indiana.d2i.datacatalog.dashboard.api.USStates.java
public static String getStates(String statesFilePath) throws ParserConfigurationException, IOException, SAXException { JSONObject statesFeatureCollection = new JSONObject(); statesFeatureCollection.put("type", "FeatureCollection"); JSONArray features = new JSONArray(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); try {/*from w ww. j a v a 2 s . c o m*/ DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document dom = documentBuilder.parse(new FileInputStream(new File(statesFilePath))); Element docElement = dom.getDocumentElement(); NodeList states = docElement.getElementsByTagName("state"); for (int i = 0; i < states.getLength(); i++) { Node state = states.item(i); JSONObject stateObj = new JSONObject(); stateObj.put("type", "Feature"); JSONObject geometry = new JSONObject(); geometry.put("type", "Polygon"); JSONArray coordinates = new JSONArray(); JSONArray coordinateSub = new JSONArray(); NodeList points = ((Element) state).getElementsByTagName("point"); for (int j = 0; j < points.getLength(); j++) { Node point = points.item(j); JSONArray pointObj = new JSONArray(); float lat = Float.parseFloat(((Element) point).getAttribute("lat")); float lng = Float.parseFloat(((Element) point).getAttribute("lng")); double trLng = lng * 20037508.34 / 180; double trLat = Math.log(Math.tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180); pointObj.add(lng); pointObj.add(lat); coordinateSub.add(pointObj); } geometry.put("coordinates", coordinates); coordinates.add(coordinateSub); stateObj.put("geometry", geometry); JSONObject name = new JSONObject(); name.put("Name", ((Element) state).getAttribute("name")); name.put("colour", "#FFF901"); stateObj.put("properties", name); features.add(stateObj); } statesFeatureCollection.put("features", features); return statesFeatureCollection.toJSONString(); } catch (ParserConfigurationException e) { log.error("Error while processing states.xml.", e); throw e; } catch (FileNotFoundException e) { log.error("Error while processing states.xml.", e); throw e; } catch (SAXException e) { log.error("Error while processing states.xml.", e); throw e; } catch (IOException e) { log.error("Error while processing states.xml.", e); throw e; } }
From source file:edu.usc.polar.NLTKRest.java
public static void ApacheNLTKRest(String doc, String args[]) { try {/*w w w.j a v a 2 s .com*/ String text; AutoDetectParser parser = new AutoDetectParser(); BodyContentHandler handler = new BodyContentHandler(); Metadata metadata = new Metadata(); InputStream stream = new FileInputStream(doc); // System.out.println(stream.toString()); parser.parse(stream, handler, metadata); // return handler.toString(); text = handler.toString(); //System.out.println(text); String metaValue = metadata.toString(); System.out.println("Desc:: " + metadata.toString()); String[] example = new String[1]; example[0] = text; String name = doc.replace("C:\\Users\\Snehal\\Documents\\TREC-Data\\Data", "polar.usc.edu"); //System.out.println(text); Map<String, Set<String>> list = tikaNLTKRest(text); System.out.println(list); JSONObject jsonObj = new JSONObject(); jsonObj.put("DOI", name); jsonObj.put("metadata", metaValue.replaceAll("\\s\\s+|\n|\t", " ")); JSONArray tempArray = new JSONArray(); JSONObject tempObj = new JSONObject(); for (Map.Entry<String, Set<String>> entry : list.entrySet()) { System.out.println("\"" + entry.getKey() + "/" + ":\"" + entry.getValue() + "\""); tempObj.put(entry.getKey(), entry.getValue()); // String jsonOut="{ DOI:"+name+" ," // + ""+item.first() + "\": \"" + text.substring(item.second(), item.third()).replaceAll("\\s\\s+|\n|\t"," ")+"\"" // + "\"metadata\":\""+metaValue+"\"" // + "}"; // System.out.println(jsonOut); // tempObj.put(item.first(),text.substring(item.second(), item.third()).replaceAll("\\s\\s+|\n|\t"," ")); } tempArray.add(tempObj); jsonObj.put("NER", tempArray); jsonArray.add(jsonObj); // System.out.println("---"); } catch (Exception e) { System.out.println("ERROR : NLTKRest" + "|File Name" + doc.replaceAll("C:\\Users\\Snehal\\Documents\\TREC-Data", "") + " direct" + e.toString()); } }
From source file:net.duckling.ddl.web.controller.space.SpaceController.java
@SuppressWarnings("unchecked") private static void writeResponse(HttpServletResponse response, int state, String message, Map<String, Object> params) { JSONObject msg = new JSONObject(); msg.put("state", state); msg.put("msg", message); if (params != null) { msg.putAll(params);//from w w w . j a va 2 s. com } JsonUtil.writeJSONObject(response, msg); }
From source file:com.healthcit.analytics.utils.ExcelExportUtils.java
@SuppressWarnings("unchecked") public static void streamVisualizationDataAsExcelFormat(OutputStream out, JSONObject data) { // Get the array of columns JSONArray jsonColumnArray = (JSONArray) data.get(COLUMNS_JSON_KEY); String[] excelColumnArray = new String[jsonColumnArray.size()]; for (int index = 0; index < excelColumnArray.length; ++index) { excelColumnArray[index] = (String) ((JSONObject) jsonColumnArray.get(index)).get(LABEL_JSON_KEY); }// w ww. j av a 2 s. c om // Get the array of rows JSONArray jsonRowArray = (JSONArray) data.get(ROWS_JSON_KEY); JSONArray excelRowArray = new JSONArray(); Iterator<JSONObject> jsonRowIterator = jsonRowArray.iterator(); while (jsonRowIterator.hasNext()) { JSONArray rowCell = (JSONArray) jsonRowIterator.next().get(ROWCELL_JSON_KEY); JSONObject excelRowObj = new JSONObject(); for (int index = 0; index < rowCell.size(); ++index) { excelRowObj.put(excelColumnArray[index], ((JSONObject) rowCell.get(index)).get(ROWCELLVALUE_JSON_KEY)); } excelRowArray.add(excelRowObj); } // build the Excel outputstream Json2Excel.build(out, excelRowArray.toJSONString(), excelColumnArray); }