org.apache.sling.commons.json.JSONArray.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(94)

本文整理了Java中org.apache.sling.commons.json.JSONArray.<init>()方法的一些代码示例,展示了JSONArray.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONArray.<init>()方法的具体详情如下:
包路径:org.apache.sling.commons.json.JSONArray
类名称:JSONArray
方法名:<init>

JSONArray.<init>介绍

[英]Construct an empty JSONArray.
[中]构造一个空的JSONArray。

代码示例

代码示例来源:origin: nateyolles/publick-sling-blog

/**
 * 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();
}

代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json

/**
 * 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;
}

代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json

/**
 * 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;
}

代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json

/**
 * 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;
}

代码示例来源:origin: io.wcm/io.wcm.caconfig.editor

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;
 }
}

代码示例来源:origin: Adobe-Marketing-Cloud/aem-guides

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();
}

代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json

/**
 * 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;
}

代码示例来源:origin: com.adobe.acs/acs-aem-commons-bundle

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;
}

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-tools

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());
}

代码示例来源:origin: com.adobe.acs/acs-aem-commons-bundle

@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);
}

代码示例来源:origin: io.wcm/io.wcm.handler.media

/**
 * 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;
}

代码示例来源:origin: com.adobe.acs/acs-aem-commons-bundle

/**
 * 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;
}

代码示例来源:origin: com.adobe.acs/acs-aem-commons-bundle

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;
}

代码示例来源:origin: io.wcm/io.wcm.wcm.ui.extjs

@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;
}

代码示例来源:origin: io.wcm/io.wcm.handler.media

/**
 * 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;
}

代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json

/**
 * 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;
}

代码示例来源:origin: com.adobe.acs/acs-aem-commons-bundle

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;
}

代码示例来源:origin: com.adobe.acs/acs-aem-commons-bundle

/**
 * {@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();
}

代码示例来源:origin: com.adobe.acs/acs-aem-commons-bundle

/**
 * {@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();
}

代码示例来源:origin: io.wcm/io.wcm.caconfig.editor

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;
}

相关文章