List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:modelo.ParametrizacionManagers.AcreditacionParametros.java
/** * // w ww.j a v a 2s . c o m * Llama al Delegate para obtener un cliente especifico * * @param codigo * @return * @throws Exception */ public JSONArray getAcreditacionPorLab(String lab) throws Exception { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarAcreditacionParametros select = new SeleccionarAcreditacionParametros(); ResultSet rset = select.getAcreditacionPorLab(lab); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArray = new JSONArray(); JSONArray salida = new JSONArray(); //Recorremos el ResultSet, armamos el objeto JSON con la info y guardamos //en el JSONArray. while (rset.next()) { //Armamos el objeto JSON con la informacion del registro JSONObject jsonObject = new JSONObject(); jsonObject.put("codigoParam", rset.getString("CODIGO_PARAM")); /*jsonObject.put("parametro", rset.getString("PARAMETRO"));*/ //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista. jsonArray.add(jsonObject.clone()); } //Se cierra el ResultSet select.desconectar(); salida.add(jsonArray); return salida; }
From source file:modelo.PDFManagers.PDFManager.java
public JSONArray contarParamIncumplidos(String codigoProceso) throws Exception { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarPDF select = new SeleccionarPDF(); ResultSet rset = select.contarParamIncumplidos(codigoProceso); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArray = new JSONArray(); //Recorremos el ResultSet, armamos el objeto JSON con la info y guardamos //en el JSONArray. JSONObject jsonObject = new JSONObject(); while (rset.next()) { //Armamos el objeto JSON con la informacion del registro jsonObject.put("cantidad", rset.getString("CANTIDAD")); //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista. }/*from ww w . j a v a2s .c o m*/ jsonArray.add(jsonObject.clone()); //Se cierra el ResultSet select.desconectar(); return jsonArray; }
From source file:modelo.PDFManagers.PDFManager.java
public JSONArray contarParam(String codigoProceso) throws Exception { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarPDF select = new SeleccionarPDF(); ResultSet rset = select.contarParam(codigoProceso); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArray = new JSONArray(); //Recorremos el ResultSet, armamos el objeto JSON con la info y guardamos //en el JSONArray. JSONObject jsonObject = new JSONObject(); while (rset.next()) { //Armamos el objeto JSON con la informacion del registro jsonObject.put("cantidad", rset.getString("CANTIDAD")); //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista. }// w w w. j ava2s . c o m jsonArray.add(jsonObject.clone()); //Se cierra el ResultSet select.desconectar(); return jsonArray; }
From source file:org.kitodo.data.elasticsearch.index.type.ProjectType.java
@SuppressWarnings("unchecked") @Override/*from www .ja va 2 s.c o m*/ public HttpEntity createDocument(Project project) { JSONObject projectObject = new JSONObject(); projectObject.put("title", project.getTitle()); String startDate = project.getStartDate() != null ? formatDate(project.getStartDate()) : null; projectObject.put("startDate", startDate); String endDate = project.getEndDate() != null ? formatDate(project.getEndDate()) : null; projectObject.put("endDate", endDate); projectObject.put("numberOfPages", project.getNumberOfPages()); projectObject.put("numberOfVolumes", project.getNumberOfVolumes()); projectObject.put("fileFormatDmsExport", project.getFileFormatDmsExport()); projectObject.put("fileFormatInternal", project.getFileFormatInternal()); String archived = project.getProjectIsArchived() != null ? project.getProjectIsArchived().toString() : null; projectObject.put("archived", archived); projectObject.put("processes", addObjectRelation(project.getProcesses())); projectObject.put("users", addObjectRelation(project.getUsers())); JSONArray projectFileGroups = new JSONArray(); List<ProjectFileGroup> projectProjectFileGroups = project.getProjectFileGroups(); for (ProjectFileGroup projectFileGroup : projectProjectFileGroups) { JSONObject projectFileGroupObject = new JSONObject(); projectFileGroupObject.put("name", projectFileGroup.getName()); projectFileGroupObject.put("path", projectFileGroup.getPath()); projectFileGroupObject.put("mimeType", projectFileGroup.getMimeType()); projectFileGroupObject.put("suffix", projectFileGroup.getSuffix()); projectFileGroupObject.put("folder", projectFileGroup.getFolder()); projectFileGroups.add(projectFileGroupObject); } projectObject.put("projectFileGroups", projectFileGroups); return new NStringEntity(projectObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:analysers.ExportValidated.java
/** * Collect frame positions for a cell into a 2D-array * @param c// w w w .j a va 2 s .co m * @return 2-D array with x and y positions */ @SuppressWarnings("unchecked") private JSONArray makeCellPositions(Cell c) { JSONArray[] pos = new JSONArray[2]; pos[0] = new JSONArray(); pos[1] = new JSONArray(); while (c != null) { double xx = c.getX(); double yy = c.getY(); pos[0].add(new Double(xx)); pos[1].add(new Double(yy)); c = c.getNextCell(); } JSONArray a = new JSONArray(); for (int i = 0; i < pos.length; i++) { a.add(pos[i]); } return a; }
From source file:botvn.libraries.StorageCookies.java
public boolean Save() { if (mCookieStore != null) { FileWriter file = null;// ww w . ja v a2s . c o m try { List<Cookie> ckss = mCookieStore.getCookies(); HashMap<String, Object> d; JSONArray allCks = new JSONArray(); for (Cookie cks : ckss) { d = new HashMap<>(ckss.size()); String name = cks.getName(); long expires = cks.getExpiryDate() != null ? cks.getExpiryDate().getTime() : 0; String path = cks.getPath(); String domain = cks.getDomain(); boolean secure = cks.isSecure(); d.put("name", name); d.put("expires", expires); d.put("path", path); d.put("domain", domain); d.put("secure", secure); allCks.add(d); } String jsonStr = allCks.toJSONString(); String currentDir = System.getProperty(USER_DIR); file = new FileWriter(currentDir + "/" + COOKIE_FILE); file.write(jsonStr); file.flush(); file.close(); return true; } catch (IOException ex) { Logger.getLogger(StorageCookies.class.getName()).log(Level.SEVERE, null, ex); } } return false; }
From source file:eumetsat.pn.common.ISO2JSON.java
private JSONObject convert(Document xmlDocument) throws XPathExpressionException, IOException { String expression = null;/*from w ww.ja v a 2s.co m*/ String result = null; XPath xPath = XPathFactory.newInstance().newXPath(); JSONObject jsonObject = new JSONObject(); String xpathFileID = "//*[local-name()='fileIdentifier']/*[local-name()='CharacterString']"; String fileID = xPath.compile(xpathFileID).evaluate(xmlDocument); log.trace("{} >>> {}", xpathFileID, fileID); if (fileID != null) { jsonObject.put(FILE_IDENTIFIER_PROPERTY, fileID); } expression = "//*[local-name()='hierarchyLevelName']/*[local-name()='CharacterString']"; JSONArray list = new JSONArray(); NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); i++) { list.add(nodeList.item(i).getFirstChild().getNodeValue()); } if (list.size() > 0) { JSONObject hierarchies = parseThemeHierarchy((String) jsonObject.get(FILE_IDENTIFIER_PROPERTY), list); hierarchies.writeJSONString(writer); jsonObject.put("hierarchyNames", hierarchies); log.trace("{} >>> {}", expression, jsonObject.get("hierarchyNames")); } // Get Contact info String deliveryPoint = "//*[local-name()='address']//*[local-name()='deliveryPoint']/*[local-name()='CharacterString']"; String city = "//*[local-name()='address']//*[local-name()='city']/*[local-name()='CharacterString']"; String administrativeArea = "//*[local-name()='address']//*[local-name()='administrativeArea']/*[local-name()='CharacterString']"; String postalCode = "//*[local-name()='address']//*[local-name()='postalCode']/*[local-name()='CharacterString']"; String country = "//*[local-name()='address']//*[local-name()='country']/*[local-name()='CharacterString']"; String email = "//*[local-name()='address']//*[local-name()='electronicMailAddress']/*[local-name()='CharacterString']"; StringBuilder addressString = new StringBuilder(); StringBuilder emailString = new StringBuilder(); appendIfResultNotNull(xPath, xmlDocument, addressString, deliveryPoint); result = xPath.compile(postalCode).evaluate(xmlDocument); if (result != null) { addressString.append("\n").append(result.trim()); } result = xPath.compile(city).evaluate(xmlDocument); if (result != null) { addressString.append(" ").append(result.trim()); } result = xPath.compile(administrativeArea).evaluate(xmlDocument); if (result != null) { addressString.append("\n").append(result.trim()); } result = xPath.compile(country).evaluate(xmlDocument); if (result != null) { addressString.append("\n").append(result.trim()); } result = xPath.compile(email).evaluate(xmlDocument); if (result != null) { emailString.append(result.trim()); } HashMap<String, String> map = new HashMap<>(); map.put("address", addressString.toString()); map.put("email", emailString.toString()); jsonObject.put("contact", map); log.trace("contact: {}", Arrays.toString(map.entrySet().toArray())); // add identification info String abstractStr = "//*[local-name()='identificationInfo']//*[local-name()='abstract']/*[local-name()='CharacterString']"; String titleStr = "//*[local-name()='identificationInfo']//*[local-name()='title']/*[local-name()='CharacterString']"; String statusStr = "//*[local-name()='identificationInfo']//*[local-name()='status']/*[local-name()='MD_ProgressCode']/@codeListValue"; String keywords = "//*[local-name()='keyword']/*[local-name()='CharacterString']"; HashMap<String, Object> idMap = new HashMap<>(); result = xPath.compile(titleStr).evaluate(xmlDocument); if (result != null) { idMap.put("title", result.trim()); } result = xPath.compile(abstractStr).evaluate(xmlDocument); if (result != null) { idMap.put("abstract", result.trim()); } result = xPath.compile(statusStr).evaluate(xmlDocument); if (result != null) { idMap.put("status", result.trim()); } list = new JSONArray(); nodeList = (NodeList) xPath.compile(keywords).evaluate(xmlDocument, XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); i++) { list.add(nodeList.item(i).getFirstChild().getNodeValue()); } if (list.size() > 0) { idMap.put("keywords", list); } jsonObject.put("identificationInfo", idMap); log.trace("idMap: {}", idMap); // get thumbnail product String browseThumbnailStr = "//*[local-name()='graphicOverview']//*[local-name()='MD_BrowseGraphic']//*[local-name()='fileName']//*[local-name()='CharacterString']"; result = xPath.compile(browseThumbnailStr).evaluate(xmlDocument); if (result != null) { idMap.put("thumbnail", result.trim()); log.trace("thumbnail: {}", result); } // add Geo spatial information String westBLonStr = "//*[local-name()='extent']//*[local-name()='geographicElement']//*[local-name()='westBoundLongitude']/*[local-name()='Decimal']"; String eastBLonStr = "//*[local-name()='extent']//*[local-name()='geographicElement']//*[local-name()='eastBoundLongitude']/*[local-name()='Decimal']"; String northBLatStr = "//*[local-name()='extent']//*[local-name()='geographicElement']//*[local-name()='northBoundLatitude']/*[local-name()='Decimal']"; String southBLatStr = "//*[local-name()='extent']//*[local-name()='geographicElement']//*[local-name()='southBoundLatitude']/*[local-name()='Decimal']"; // create a GeoJSON envelope object HashMap<String, Object> latlonMap = new HashMap<>(); latlonMap.put("type", "envelope"); JSONArray envelope = new JSONArray(); JSONArray leftTopPt = new JSONArray(); JSONArray rightDownPt = new JSONArray(); result = xPath.compile(westBLonStr).evaluate(xmlDocument); if (result != null) { leftTopPt.add(Double.parseDouble(result.trim())); } result = xPath.compile(northBLatStr).evaluate(xmlDocument); if (result != null) { leftTopPt.add(Double.parseDouble(result.trim())); } result = xPath.compile(eastBLonStr).evaluate(xmlDocument); if (result != null) { rightDownPt.add(Double.parseDouble(result.trim())); } result = xPath.compile(southBLatStr).evaluate(xmlDocument); if (result != null) { rightDownPt.add(Double.parseDouble(result.trim())); } envelope.add(leftTopPt); envelope.add(rightDownPt); latlonMap.put("coordinates", envelope); jsonObject.put("location", latlonMap); DOMImplementationLS domImplementation = (DOMImplementationLS) xmlDocument.getImplementation(); LSSerializer lsSerializer = domImplementation.createLSSerializer(); String xmlString = lsSerializer.writeToString(xmlDocument); jsonObject.put("xmldoc", xmlString); return jsonObject; }
From source file:com.bloomberglp.blpapi.securitysearch.SecuritySearchApiConnection.java
@SuppressWarnings("unchecked") private void processInstrumentListResponse(Message msg) { Element results = msg.getElement(RESULTS_ELEMENT); int numResults = results.numValues(); System.out.println("Processing " + numResults + " results:"); JSONArray arr = new JSONArray(); d_result.put("result", arr); for (int i = 0; i < numResults; ++i) { Element result = results.getValueAsElement(i); JSONObject el = new JSONObject(); el.put("security", result.getElementAsString(SECURITY_ELEMENT)); el.put("description", result.getElementAsString(DESCRIPTION_ELEMENT)); arr.add(el); }//w ww .j av a 2s.co m }
From source file:analysers.ExportValidated.java
/** * Collect areas for cell in each frame/*from ww w . j ava 2 s .co m*/ * @param c * @return 1-D array with areas */ @SuppressWarnings("unchecked") private JSONArray makeCellAreas(Cell c) { JSONArray a = new JSONArray(); while (c != null) { double ar = c.getArea(); a.add(new Double(ar)); c = c.getNextCell(); } return a; }
From source file:analysers.ExportValidated.java
/** * Make the data array for a given cell//from w w w. j a va 2 s. c o m * @param c * @return a JSON array containing all time values */ @SuppressWarnings("unchecked") private JSONArray makeCellData(Cell c) { boolean meanInt = true; if (screen instanceof DisplayTrackingWindow) { int b = Prefs.getInt(".TrackApp.FilterValidatedDialog.exportMean", 1); meanInt = b != 0; } JSONArray[] q = new JSONArray[c.getIntensity().length]; for (int i = 0; i < q.length; i++) { q[i] = new JSONArray(); } while (c != null) { double[] ints = c.getIntensity(); double ar = c.getArea(); int lm = Math.min(q.length, ints.length); if (lm != ints.length) { IJ.log("Warning : number of channels varies, inconsistent cell dataset."); } for (int i = 0; i < ints.length; i++) { if (meanInt) { q[i].add(new Double(ints[i] / ar)); } else { q[i].add(new Double(ints[i])); } } c = c.getNextCell(); } JSONArray a = new JSONArray(); for (int i = 0; i < q.length; i++) { a.add(q[i]); } return a; }