List of usage examples for org.json JSONWriter key
public JSONWriter key(String string) throws JSONException
From source file:org.everit.osgi.webconsole.configuration.DisplayedAttribute.java
public void toJSON(final JSONWriter writer) { writer.object();/*from w w w. j a v a 2 s . c o m*/ writer.key("id"); writer.value(id); writer.key("name"); writer.value(name); writer.key("description"); writer.value(description); writer.key("value"); valueToJSON(writer); writer.key("type"); typeToJSON(writer); writer.endObject(); }
From source file:org.everit.osgi.webconsole.configuration.DisplayedAttribute.java
private void typeToJSON(final JSONWriter writer) { writer.object();//w ww .ja v a 2s . co m writer.key("baseType"); writer.value(type); writer.key("maxOccurences"); if (maxOccurences == Integer.MIN_VALUE || maxOccurences == Integer.MAX_VALUE) { writer.value("unbound"); } else { writer.value(maxOccurences); } optionsToJSON(writer); writer.endObject(); }
From source file:de.jaetzold.philips.hue.HueLightGroup.java
private List<JSONObject> stateChange(String param, Object value) { final JSONObject stateTransaction = stateTransactionJson.get(); if (stateTransaction == null) { JSONWriter json = JO(); if (transitionTime != null) { json = json.key("transitiontime").value(transitionTime); }/*from w w w . j av a 2 s .co m*/ return bridge.checkedSuccessRequest(PUT, "/groups/" + getId() + "/action", json.key(param).value(value)); } else { stateTransaction.put(param, value); return null; } }
From source file:org.everit.osgi.webconsole.configuration.ServiceSuggestion.java
public void toJSON(final JSONWriter writer) { writer.object();// ww w. j a va 2 s .co m writer.key("serviceClass"); writer.value(serviceClass); writer.key("id"); writer.value(serviceId); writer.key("properties"); writer.array(); for (String key : serviceProperties.keySet()) { writer.object(); writer.key("key"); writer.value(key); writer.key("value"); writer.value(serviceProperties.get(key)); writer.endObject(); } writer.endArray(); writer.endObject(); }
From source file:org.mapfish.print.servlet.MapPrinterServlet.java
/** * Create the PDF and returns to the client (in JSON) the URL to get the PDF. *///from ww w . ja va 2 s. co m protected void createPDF(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String basePath) throws ServletException { TempFile tempFile = null; try { purgeOldTemporaryFiles(); String spec = getSpecFromPostBody(httpServletRequest); tempFile = doCreatePDFFile(spec, httpServletRequest); if (tempFile == null) { error(httpServletResponse, "Missing 'spec' parameter", 500); return; } } catch (Throwable e) { deleteFile(tempFile); error(httpServletResponse, e); return; } final String id = generateId(tempFile); httpServletResponse.setContentType("application/json; charset=utf-8"); PrintWriter writer = null; try { writer = httpServletResponse.getWriter(); JSONWriter json = new JSONWriter(writer); json.object(); { json.key("getURL").value(basePath + "/" + id + TEMP_FILE_SUFFIX); } json.endObject(); } catch (JSONException e) { deleteFile(tempFile); throw new ServletException(e); } catch (IOException e) { deleteFile(tempFile); throw new ServletException(e); } finally { if (writer != null) { writer.close(); } } addTempFile(tempFile, id); }
From source file:org.mapfish.print.servlet.MapPrinterServlet.java
/** * To get (in JSON) the information about the available formats and CO. *///ww w .ja va2 s .c o m protected void getInfo(HttpServletRequest req, HttpServletResponse resp, String basePath) throws ServletException, IOException { app = req.getParameter("app"); //System.out.println("app = "+app); MapPrinter printer = getMapPrinter(app); resp.setContentType("application/json; charset=utf-8"); final PrintWriter writer = resp.getWriter(); try { final String var = req.getParameter("var"); if (var != null) { writer.print(var + "="); } JSONWriter json = new JSONWriter(writer); try { json.object(); { printer.printClientConfig(json); json.key("printURL").value(basePath + PRINT_URL); json.key("createURL").value(basePath + CREATE_URL); if (app != null) { json.key("app").value(app); } } json.endObject(); } catch (JSONException e) { throw new ServletException(e); } if (var != null) { writer.print(";"); } } finally { writer.close(); } }
From source file:de.dekarlab.moneybuilder.model.parser.JsonBookSaver.java
/** * Save book to file./* w ww . j av a 2 s .com*/ * * @param file * @param book * @throws Exception */ public static void saveBook(BookFile bookFile) throws Exception { FileWriter writer = null; JSONWriter jsonWriter = null; try { Book book = bookFile.getBook(); writer = new FileWriter(bookFile.getFilePath()); jsonWriter = new JSONWriter(writer); jsonWriter.object().key("book"); jsonWriter.object(); jsonWriter.key("name").value(book.getName()); jsonWriter.key("currPeriodId").value(book.getCurrPeriodId()); savePeriodBudget(book.getPeriodBudget(), jsonWriter); savePeriodValue(book.getPeriodValue(), jsonWriter); jsonWriter.key("assets"); saveAccount(book.getAssetList(), jsonWriter); jsonWriter.key("liability"); saveAccount(book.getLiabilityList(), jsonWriter); jsonWriter.key("income"); saveAccount(book.getIncomeList(), jsonWriter); jsonWriter.key("expenses"); saveAccount(book.getExpenseList(), jsonWriter); jsonWriter.key("periodList"); savePeriodList(book.getPeriodList(), jsonWriter); jsonWriter.endObject(); jsonWriter.endObject(); } finally { if (writer != null) { writer.flush(); writer.close(); } } }
From source file:de.dekarlab.moneybuilder.model.parser.JsonBookSaver.java
/** * Save folder./*from w w w .j a va2 s .co m*/ * * @param account * @param jsonWriter */ protected static void saveAccount(Account account, JSONWriter jsonWriter) { jsonWriter.object(); jsonWriter.key("name").value(account.getName()); jsonWriter.key("type").value(account.getType()); if (account instanceof Folder) { jsonWriter.key("folder").value("y"); } if (account.isHidden()) { jsonWriter.key("hidden").value("y"); if (account.getHiddenDate() != null) { jsonWriter.key("hiddenDate").value(Formatter.formatDate(account.getHiddenDate())); } } savePeriodBudget(account.getPeriodBudget(), jsonWriter); savePeriodValue(account.getPeriodValue(), jsonWriter); if (account instanceof Folder) { jsonWriter.key("list"); jsonWriter.array(); for (Account child : ((Folder) account).getList()) { saveAccount(child, jsonWriter); } jsonWriter.endArray(); } jsonWriter.endObject(); }
From source file:de.dekarlab.moneybuilder.model.parser.JsonBookSaver.java
/** * Save period list.//ww w. j av a2 s. c om * * @param periodList * @param jsonWriter */ protected static void savePeriodList(List<Period> periodList, JSONWriter jsonWriter) { jsonWriter.array(); for (Period period : periodList) { jsonWriter.object(); jsonWriter.key("id").value(period.getId()); jsonWriter.key("date").value(Formatter.formatDate(period.getDate())); saveValue(period.getValue(), jsonWriter); saveTransactions(period.getTransactions(), jsonWriter); jsonWriter.endObject(); } jsonWriter.endArray(); }
From source file:de.dekarlab.moneybuilder.model.parser.JsonBookSaver.java
/** * Save transactions.//w ww . j a va 2s . co m * * @param trans * @param jsonWriter */ protected static void saveTransactions(List<Transaction> trans, JSONWriter jsonWriter) { if (trans.size() > 0) { jsonWriter.key("transactions"); jsonWriter.array(); for (Transaction tr : trans) { jsonWriter.object(); jsonWriter.key("from").value(tr.getFrom().getAbsName()); jsonWriter.key("to").value(tr.getTo().getAbsName()); jsonWriter.key("description").value(tr.getDescription()); jsonWriter.key("value").value(tr.getValue()); jsonWriter.endObject(); } jsonWriter.endArray(); } }