private JSONObject toJson(Map<String, String> properties) throws JSONException { if (properties == null || properties.isEmpty()) { return null; } else { JSONObject metadataProps = new JSONObject(); for (Map.Entry<String, String> entry : properties.entrySet()) { metadataProps.putOpt(entry.getKey(), entry.getValue()); } return metadataProps; } }
private Map<String, String> toMap(StringBuilder sb) { final String text = sb.toString(); try { final JSONObject jsonObject = new JSONObject(text); return JsonExtractor.toMap(jsonObject); } catch (JSONException e) { return new HashMap<>(0); } }
/** * 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; }
/** * Put a value in the JSONArray, where the value will be a * JSONObject which is produced from a Map. * @param value A Map value. * @return this. */ public JSONArray put(Map<String, ?> value) { put(new JSONObject(value)); return this; }
/** * Put a value in the JSONArray, where the value will be a * JSONObject which is produced from a Map. * @param index The subscript. * @param value The Map value. * @return this. * @throws JSONException If the index is negative or if the the value is * an invalid number. */ public JSONArray put(int index, Map<String, ?> value) throws JSONException { put(index, new JSONObject(value)); return this; }
private void addPluginsResource(JSONArray pluginContentJSON, Iterable<String> plugins) throws JSONException { Iterator<String> pluginContentIterator = plugins.iterator(); while (pluginContentIterator.hasNext()) { String plugin = pluginContentIterator.next(); JSONObject updatePluginJSON = new JSONObject(); updatePluginJSON.put(PLUGIN_ITEM_KEY, plugin); pluginContentJSON.put(updatePluginJSON); } }
private void buildJson() { Map<String, Object> objectMap = new HashMap<>(); objectMap.put(Image.JSON_SMART_SIZES, new JSONArray(Arrays.asList(ArrayUtils.toObject(smartSizes)))); objectMap.put(Image.JSON_SMART_IMAGES, new JSONArray(Arrays.asList(smartImages))); objectMap.put(Image.JSON_LAZY_ENABLED, !disableLazyLoading); json = new JSONObject(objectMap).toString(); }
@Activate protected void activate(Map<String, Object> config) throws JSONException { Map<String, String> components = ParameterUtil.toMap(PropertiesUtil.toStringArray(config.get(PROP_COMPONENTS), DEFAULT_COMPONENTS),"="); JSONArray array = new JSONArray(); for (Map.Entry<String, String> entry : components.entrySet()) { JSONObject obj = new JSONObject(); obj.put("propertyName", entry.getKey()); obj.put("componentPath", entry.getValue()); array.put(obj); } this.json = new JSONObject(); json.put("components", array); }
private JSONObject createReloadObject(String includePath) throws JSONException { JSONObject reload = new JSONObject(); reload.put(COMMAND, CMD_RELOAD); reload.put(PATH, includePath); reload.put("liveCSS", true); return reload; }
private JSONObject createReloadObject(String includePath) throws JSONException { JSONObject reload = new JSONObject(); reload.put(COMMAND, CMD_RELOAD); reload.put(PATH, includePath); reload.put("liveCSS", true); return reload; }
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()); }
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; }
public JSONObject toJSON() throws JSONException { SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy hh:mm:ss aaa"); JSONObject json = new JSONObject(); json.put(PN_PATH, getPath()); json.put(PN_PAYLOAD_PATH, getPayloadPath()); json.put(PN_FAILED_AT, sdf.format(getFailedAt().getTime())); return json; } }
@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; }
/** Renditions **/ public JSONObject toJSON() throws JSONException { JSONObject json = new JSONObject(); json.put(PN_STATUS, getStatus().toString()); json.put(PN_PATH, getPayloadPath()); return json; }
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"); }
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; }
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; }