/** * Get the multi-value keywords property as a JSON string. * * @return The multi-value keyword property as a JSON string. */ public String getKeywordsJSON() { JSONArray jsonArray = null; if (keywords != null) { jsonArray = new JSONArray(Arrays.asList(keywords)); } else { jsonArray = new JSONArray(); } return jsonArray.toString(); }
/** * Put a value in the JSONArray, where the value will be a * JSONArray which is produced from a Collection. * @param value A Collection value. * @return this. */ public JSONArray put(Collection<?> value) { put(new JSONArray(value)); return this; }
/** * 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 value in the JSONArray, where the value will be a * JSONArray which is produced from a Collection. * @param index The subscript. * @param value A Collection value. * @return this. * @throws JSONException If the index is negative or if the value is * not finite. */ public JSONArray put(int index, Collection<?> value) throws JSONException { put(index, new JSONArray(value)); return this; }
private Object toJsonValue(Object value) { if (value == null) { return null; } if (value.getClass().isArray()) { JSONArray array = new JSONArray(); for (int i = 0; i < Array.getLength(value); i++) { array.put(Array.get(value, i)); } return array; } else { return value; } }
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(); }
/** * Produce a JSONArray containing the names of the elements of this * JSONObject. * @return A JSONArray containing the key strings, or null if the JSONObject * is empty. */ public JSONArray names() { JSONArray ja = new JSONArray(); Iterator<String> keys = keys(); while (keys.hasNext()) { ja.put(keys.next()); } return ja.length() == 0 ? null : ja; }
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; }
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()); }
@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); }
/** * Collect responsive JSON metadata for all renditions as image sources. * @param media Media * @return JSON metadata */ protected JSONArray getResponsiveImageSources(Media media) { Collection<Rendition> renditions = media.getRenditions(); JSONArray sources = new JSONArray(); for (Rendition rendition : renditions) { sources.put(toReponsiveImageSource(media, rendition)); } return sources; }
/** * Creates a JSON array of the User Groups principals in the system. * @param resourceResolver the security context used to collect the groups. * @return a JSON Array of all the user group principals name that the resourceResolver can read. * @throws RepositoryException */ private JSONArray getGroupOptions(ResourceResolver resourceResolver) throws RepositoryException { final JSONArray jsonArray = new JSONArray(); final QueryManager queryManager = resourceResolver.adaptTo(Session.class).getWorkspace().getQueryManager(); final Query query = queryManager.createQuery(QUERY, Query.JCR_SQL2); final NodeIterator nodeIter = query.execute().getNodes(); while (nodeIter.hasNext()) { Resource resource = resourceResolver.getResource(nodeIter.nextNode().getPath()); jsonArray.put(resource.getValueMap().get("rep:principalName", "Unknown")); } return jsonArray; }
private JSONObject getJSONResults(Command cmd, SlingHttpServletRequest request, final Collection<Result> results) throws JSONException { final JSONObject json = new JSONObject(); json.put(KEY_RESULTS, new JSONArray()); final ValueMap requestConfig = new ValueMapDecorator(new HashMap<String, Object>()); // Collect all items collected from OSGi Properties requestConfig.putAll(this.config); // Add Request specific configurations requestConfig.put(AuthoringUIMode.class.getName(), authoringUIModeService.getAuthoringUIMode(request)); for (final Result result : results) { final JSONObject tmp = resultBuilder.toJSON(cmd, result, requestConfig); if (tmp != null) { json.accumulate(KEY_RESULTS, tmp); } } return json; }
@Override protected JSONArray getJsonContent(Resource rootResource, PageFilter pageFilter) throws JSONException { JSONArray pagelist = new JSONArray(); Iterator<Page> pages = new PageIterator(rootResource.listChildren(), pageFilter); while (pages.hasNext()) { Page page = pages.next(); JSONObject childItem = new JSONObject(); childItem.put("value", page.getPath()); childItem.put("text", page.getTitle()); pagelist.put(childItem); } return pagelist; }
/** * Collect responsive JSON metadata for all renditions as image sources. * @param media Media * @return JSON metadata */ protected JSONArray getResponsiveImageSources(Media media) { MediaFormat[] mediaFormats = media.getMediaRequest().getMediaArgs().getMediaFormats(); JSONArray sources = new JSONArray(); for (MediaFormat mediaFormat : mediaFormats) { sources.put(toReponsiveImageSource(media, mediaFormat)); } return sources; }
/** * Produce a JSONArray containing the values of the members of this * JSONObject. * @param names A JSONArray containing a list of key strings. This * determines the sequence of the values in the result. * @return A JSONArray of values. * @throws JSONException If any of the values are non-finite numbers. */ public JSONArray toJSONArray(JSONArray names) throws JSONException { if (names == null || names.length() == 0) { return null; } JSONArray ja = new JSONArray(); for (int i = 0; i < names.length(); i += 1) { ja.put(this.opt(names.getString(i))); } return ja; }
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; }
/** * {@inheritDoc} */ public String getPathFilterSetPreviewJSON(final Collection<PathFilterSet> pathFilterSets) throws JSONException { final JSONObject json = new JSONObject(); json.put("status", "preview"); json.put("path", "Not applicable (Preview)"); json.put("filterSets", new JSONArray()); for (final PathFilterSet pathFilterSet : pathFilterSets) { final JSONObject tmp = new JSONObject(); tmp.put("importMode", "Not applicable (Preview)"); tmp.put("rootPath", pathFilterSet.getRoot()); json.accumulate("filterSets", tmp); } return json.toString(); }
/** * {@inheritDoc} */ public String getSuccessJSON(final JcrPackage jcrPackage) throws JSONException, RepositoryException { final JSONObject json = new JSONObject(); json.put("status", "success"); json.put("path", jcrPackage.getNode().getPath()); json.put("filterSets", new JSONArray()); final List<PathFilterSet> filterSets = jcrPackage.getDefinition().getMetaInf().getFilter().getFilterSets(); for (final PathFilterSet filterSet : filterSets) { final JSONObject jsonFilterSet = new JSONObject(); jsonFilterSet.put("importMode", filterSet.getImportMode().name()); jsonFilterSet.put("rootPath", filterSet.getRoot()); json.accumulate("filterSets", jsonFilterSet); } return json.toString(); }
private JSONArray getConfigNames(Resource contextResource) throws JSONException { JSONArray output = new JSONArray(); SortedSet<String> configNames = configManager.getConfigurationNames(); for (String configName : configNames) { ConfigurationMetadata metadata = configManager.getConfigurationMetadata(configName); if (metadata != null) { JSONObject item = new JSONObject(); item.put("configName", configName); item.putOpt("label", metadata.getLabel()); item.putOpt("description", metadata.getDescription()); item.put("collection", metadata.isCollection()); item.put("exists", hasConfig(contextResource, configName, metadata.isCollection())); output.put(item); } } return output; }