/** * Put a key/boolean pair in the JSONObject. * * @param key A key string. * @param value A boolean which is the value. * @return this. * @throws JSONException If the key is null. */ public JSONObject put(String key, boolean value) throws JSONException { put(key, value ? Boolean.TRUE : Boolean.FALSE); return this; }
/** * Put a key/int pair in the JSONObject. * * @param key A key string. * @param value An int which is the value. * @return this. * @throws JSONException If the key is null. */ public JSONObject put(String key, int value) throws JSONException { put(key, new Integer(value)); return this; }
/** * Put a key/double pair in the JSONObject. * * @param key A key string. * @param value A double which is the value. * @return this. * @throws JSONException If the key is null or if the number is invalid. */ public JSONObject put(String key, double value) throws JSONException { put(key, new Double(value)); return this; }
private void addMessage(JSONObject jsonObject, String message) { try { jsonObject.put("message", message); } catch (JSONException e) { log.error("Could not formulate JSON Response", e); } }
/** * Put a key/long pair in the JSONObject. * * @param key A key string. * @param value A long which is the value. * @return this. * @throws JSONException If the key is null. */ public JSONObject put(String key, long value) throws JSONException { put(key, new Long(value)); return this; }
@Override protected JSONObject createEmptyWidget(String rteName) throws JSONException { JSONObject object = new JSONObject(); object.put("xtype", "richtext"); object.put("name", "./" + xssApi.encodeForJSString(rteName)); object.put("hideLabel", true); object.put("jcr:primaryType", "cq:Widget"); return object; }
@Override protected JSONObject createEmptyWidget(String propertyName) throws JSONException { JSONObject object = new JSONObject(); object.put("xtype", "tags"); object.put("name", "./" + xssApi.encodeForJSString(propertyName)); object.put("fieldLabel", "Tags/Keywords"); object.put("jcr:primaryType", "cq:Widget"); return object; }
private void addActionManagerTrackedCounts(String name, JSONObject json) throws JSONException { final ActionManager actionManager = actionManagerFactory.getActionManager(name); int failureCount = actionManager.getErrorCount(); int completeCount = actionManager.getSuccessCount(); int totalCount = actionManager.getAddedCount(); int remainingCount = actionManager.getRemainingCount(); json.put("totalCount", totalCount); json.put("completeCount", completeCount); json.put("remainingCount", remainingCount); json.put("failCount", failureCount); json.put("percentComplete", Math.round(((totalCount - remainingCount) / (totalCount * 1F)) * DECIMAL_TO_PERCENT)); }
/** * Put a key/value pair in the JSONObject, where the value will be a * JSONArray which is produced from a Collection. * @param key A key string. * @param value A Collection value. * @return this. * @throws JSONException */ public JSONObject put(String key, Collection<?> value) throws JSONException { put(key, new JSONArray(value)); return this; }
/** * Put a key/value pair in the JSONObject, where the value will be a * JSONObject which is produced from a Map. * @param key A key string. * @param value A Map value. * @return this. * @throws JSONException */ public JSONObject put(String key, Map<String, ?> value) throws JSONException { put(key, new JSONObject(value)); return this; }
public JSONObject toJSON(final Action action) throws JSONException { final JSONObject json = new JSONObject(); if (action != null) { json.put("uri", action.getUri()); json.put("method", action.getMethod()); json.put("target", action.getTarget()); json.put("xhr", false); json.put("script", action.getScript()); json.put("params", new JSONObject(action.getParams())); } return json; } }
private void decorateEdge(JSONArray inputArray, StreamEdge inEdge, int mappedInputID) throws JSONException { JSONObject input = new JSONObject(); inputArray.put(input); input.put(ID, mappedInputID); input.put(SHIP_STRATEGY, inEdge.getPartitioner()); input.put(SIDE, (inputArray.length() == 0) ? "first" : "second"); }
public JSONObject toJSON(final Result result, final ValueMap config) throws JSONException { final JSONObject json = new JSONObject(); json.put("title", result.getTitle()); json.put("type", result.getResultType()); json.put("description", result.getDescription()); json.put("path", result.getPath()); json.put("action", this.toJSON(result.getAction())); json.put("secondaryAction", this.toJSON(result.getSecondaryAction())); return json; }
private void addWorkspaceTrackedCounts(Workspace workspace, JSONObject json) throws JSONException { // Counts int remainingCount = workspace.getTotalCount() - (workspace.getCompleteCount() + workspace.getFailCount()); json.put("totalCount", workspace.getTotalCount()); json.put("completeCount", workspace.getCompleteCount()); json.put("remainingCount", remainingCount); json.put("failCount", workspace.getFailCount()); json.put("percentComplete", Math.round(((workspace.getTotalCount() - remainingCount) / (workspace.getTotalCount() * 1F)) * DECIMAL_TO_PERCENT)); }
private JSONArray convertResponseToJson(List<ReplicationResult> list) throws JSONException { JSONArray arr = new JSONArray(); for (ReplicationResult result : list) { JSONObject resultObject = new JSONObject(); resultObject.put("path", result.getPath()); resultObject.put("status", result.getStatus().name()); resultObject.put("version", result.getVersion()); arr.put(resultObject); } return arr; }
private void writeJsonResponse(final List<String> categories, final SlingHttpServletResponse response) throws JSONException, IOException { final JSONObject jsonObject = new JSONObject(); jsonObject.put("categories", new JSONArray(categories)); response.getWriter().print(jsonObject.toString()); }
/** Dump a single node */ private static void createSingleResource(final Resource n, final JSONObject parent, final int currentRecursionLevel, final int maxRecursionLevels) throws JSONException { if (recursionLevelActive(currentRecursionLevel, maxRecursionLevels)) { parent.put(ResourceUtil.getName(n), create(n, currentRecursionLevel + 1, maxRecursionLevels)); } }
public JSONArray getCustomPropertiesAsJSON() throws JSONException { final JSONArray jsonArray = new JSONArray(); for (String customProperty : customProperties) { final JSONObject jsonObject = new JSONObject(); jsonObject.put(RELATIVE_PROPERTY_PATH, customProperty); jsonArray.put(jsonObject); } return jsonArray; }