List of usage examples for org.json JSONWriter endObject
public JSONWriter endObject() throws JSONException
From source file:org.everit.osgi.webconsole.configuration.ConfigServlet.java
private void listConfigAdminServices(final Writer writer) { JSONWriter jsonWriter = new JSONWriter(writer); jsonWriter.array();/*from w ww . ja va 2s .com*/ configManager.configAdminStream().forEach((confAdmin) -> { jsonWriter.object(); jsonWriter.key("pid"); jsonWriter.value(confAdmin.getProperty("service.pid")); jsonWriter.key("description"); jsonWriter.value(confAdmin.getProperty("service.description")); jsonWriter.key("bundleId"); jsonWriter.value(confAdmin.getBundle().getBundleId()); jsonWriter.endObject(); }); jsonWriter.endArray(); }
From source file:org.everit.osgi.webconsole.configuration.ConfigServlet.java
private void printServiceSuggestions(final HttpServletResponse resp, final String configAdminPid, final String pid, final String attributeId, final String ldapQuery) { try {//from w w w. j a va 2 s. c o m JSONWriter writer = new JSONWriter(resp.getWriter()); List<ServiceSuggestion> suggestions; try { suggestions = configManager.getServiceSuggestions(configAdminPid, pid, attributeId, ldapQuery); writer.array(); for (ServiceSuggestion suggestion : suggestions) { suggestion.toJSON(writer); } writer.endArray(); } catch (InvalidSyntaxException e) { // resp.setStatus(403); writer.object(); writer.key("error"); writer.value("invalid query: " + e.getMessage()); writer.endObject(); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.everit.osgi.webconsole.configuration.ConfigServlet.java
private void printSuccess(final HttpServletResponse resp) { resp.setContentType("application/json"); try {/* w w w. java2s . com*/ JSONWriter writer = new JSONWriter(resp.getWriter()); writer.object(); writer.key("status"); writer.value("success"); writer.endObject(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.gatein.management.rest.providers.JsonResourceProvider.java
@Override public void writeTo(Resource resource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { PrintWriter printWriter = new PrintWriter(entityStream); try {/*from w w w . j a v a 2s .c om*/ JSONWriter writer = new JSONWriter(printWriter); writer.object().key("description").value(resource.getDescription()); writer.key("children").array(); for (Child child : resource.getChildren()) { writeChild(child, writer); } writer.endArray(); if (resource.getOperations() != null) { writer.key("operations").array(); for (Operation operation : resource.getOperations()) { writeOperation(operation, writer); } writer.endArray(); } writer.endObject(); printWriter.flush(); } catch (JSONException e) { throw new IOException("Exception writing json result.", e); } finally { printWriter.close(); } }
From source file:org.gatein.management.rest.providers.JsonResourceProvider.java
private void writeOperation(Operation operation, JSONWriter writer) throws IOException, JSONException { writer.object().key("operation-name").value(operation.getOperationName()); writer.key("operation-description").value(operation.getOperationDescription()); writeLink("link", operation.getOperationLink(), writer); writer.endObject(); }
From source file:org.gatein.management.rest.providers.JsonResourceProvider.java
private void writeChild(Child child, JSONWriter writer) throws IOException, JSONException { writer.object().key("name").value(child.getName()); writer.key("description").value(child.getDescription()); writeLink("link", child.getLink(), writer); writer.endObject(); }
From source file:org.gatein.management.rest.providers.JsonResourceProvider.java
private void writeLink(String name, Link link, JSONWriter writer) throws IOException, JSONException { writer.key(name).object();/*from www . ja v a2 s . c o m*/ if (link.getRel() != null) { writer.key("rel").value(link.getRel()); } writer.key("href").value(link.getHref()); if (link.getType() != null) { writer.key("type").value(link.getType()); } if (link.getMethod() != null) { writer.key("method").value(link.getMethod()); } writer.endObject(); }
From source file:org.araqne.confdb.file.Exporter.java
public void exportData(OutputStream os) throws IOException { if (os == null) throw new IllegalArgumentException("export output stream cannot be null"); logger.debug("araqne confdb: start export data"); db.lock();// w w w . java 2 s . c o m try { OutputStreamWriter writer = new OutputStreamWriter(os, Charset.forName("utf-8")); JSONWriter jw = new JSONWriter(writer); jw.object(); jw.key("metadata"); jw.object(); jw.key("version").value(1); jw.key("date").value(sdf.format(new Date())); jw.endObject(); jw.key("collections"); jw.object(); for (String name : db.getCollectionNames()) { ConfigCollection col = db.getCollection(name); // collection name jw.key(name); // typed doc list jw.array(); jw.value("list"); // doc list begin jw.array(); ConfigIterator it = col.findAll(); try { while (it.hasNext()) { Object doc = it.next().getDocument(); jw.value(insertType(doc)); } } finally { it.close(); } // end of doc list jw.endArray(); // end of typed list jw.endArray(); } // end of collection jw.endObject(); // end of master doc jw.endObject(); writer.flush(); logger.debug("araqne confdb: export complete"); } catch (JSONException e) { throw new IOException(e); } finally { db.unlock(); } }
From source file:tap.formatter.JSONFormat.java
@Override public void writeResult(TableIterator result, OutputStream output, TAPExecutionReport execReport, Thread thread) throws TAPException, IOException, InterruptedException { try {/*from w w w . j a va 2s .c om*/ // Prepare the output stream for JSON: BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output)); JSONWriter out = new JSONWriter(writer); // { out.object(); // "metadata": [...] out.key("metadata"); // Write metadata part: DBColumn[] columns = writeMetadata(result, out, execReport, thread); writer.flush(); if (thread.isInterrupted()) throw new InterruptedException(); // "data": [...] out.key("data"); // Write the data part: writeData(result, columns, out, execReport, thread); // } out.endObject(); writer.flush(); } catch (JSONException je) { throw new TAPException(je.getMessage(), je); } }
From source file:tap.formatter.JSONFormat.java
/** * Formats in JSON and writes the given {@link TAPColumn} in the given output. * /* www . j a v a 2 s .co m*/ * @param tapCol The column metadata to format/write in JSON. * @param out The stream in which the formatted column metadata must be written. * * @throws IOException If there is an error while writing the field metadata. * @throws JSONException If there is an error while formatting something in JSON format. * @throws TAPException If there is any other error (by default: never happen). */ protected void writeFieldMeta(TAPColumn tapCol, JSONWriter out) throws IOException, TAPException, JSONException { // { out.object(); // "name": "..." out.key("name").value(tapCol.getADQLName()); // "description": "..." (if any) if (tapCol.getDescription() != null && tapCol.getDescription().trim().length() > 0) out.key("description").value(tapCol.getDescription()); // "datatype": "..." VotType votType = new VotType(tapCol.getDatatype()); out.key("datatype").value(votType.datatype); // "arraysize": "..." (if any) if (votType.arraysize != null) out.key("arraysize").value(votType.arraysize); // "xtype": "..." (if any) if (votType.xtype != null) out.key("xtype").value(votType.xtype); // "unit": "..." (if any) if (tapCol.getUnit() != null && tapCol.getUnit().length() > 0) out.key("unit").value(tapCol.getUnit()); // "ucd": "..." (if any) if (tapCol.getUcd() != null && tapCol.getUcd().length() > 0) out.key("ucd").value(tapCol.getUcd()); // "utype": "..." (if any) if (tapCol.getUtype() != null && tapCol.getUtype().length() > 0) out.key("utype").value(tapCol.getUtype()); // } out.endObject(); }