org.apache.sling.commons.json.JSONObject.accumulate()方法的使用及代码示例

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

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

JSONObject.accumulate介绍

[英]Accumulate values under a key. It is similar to the put method except that if there is already an object stored under the key then a JSONArray is stored under the key to hold all of the accumulated values. If there is already a JSONArray, then the new value is appended to it. In contrast, the put method replaces the previous value.
[中]在键下累积值。它与put方法类似,只是如果已经有一个对象存储在该键下,那么会在该键下存储一个JSONArray来保存所有累积值。如果已经有一个JSONArray,那么新值将附加到它。相反,put方法将替换以前的值。

代码示例

代码示例来源:origin: otros-systems/otroslogviewer

@Override
 public String serialize(List<Session> sessions) {
  Collection<Session> withoutDuplicates = sessions.stream().collect(Collectors.toMap(Session::getName, Function.identity())).values();
  List<JSONObject> objects = withoutDuplicates.stream().map(s -> {
   final HashMap<String, Object> map = new HashMap<>();
   map.put("name", s.getName());
   final List<JSONObject> files = s.getFilesToOpen().stream().map(f -> {
    final HashMap<String, String> map1 = new HashMap<>();
    map1.put("uri", f.getUri());
    map1.put("level", f.getLevel().getName());
    map1.put("openMode", f.getOpenMode().name());
    f.getLogImporter().ifPresent(l -> {
     map1.put("logImporter", l);
    });
    return new JSONObject(map1);
   }).collect(Collectors.toList());
   final JSONObject jsonObject = new JSONObject(map);
   try {
    return jsonObject.accumulate("filesToOpen", new JSONArray(files));
   } catch (JSONException e) {
    LOGGER.error("Can't serialize: ", e);
   }
   return jsonObject;
  }).collect(toList());
  final String result = new JSONArray(objects).toString();
  LOGGER.info("Serialized session: {}", result);
  return result;
 }
}

代码示例来源: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: com.adobe.acs/acs-aem-commons-bundle

json.accumulate("runnerTypes", new JSONObject().put("label", "AEM Workflow").put("value",
      AEMWorkflowRunnerImpl.class.getName()));
  json.accumulate("runnerTypes", new JSONObject().put("label", "Synthetic Workflow (Single-threaded)").put("value",
      SyntheticWorkflowRunnerImpl.class.getName()));
  json.accumulate("runnerTypes", new JSONObject().put("label", "Synthetic Workflow (Multi-threaded)").put("value",
      FastActionManagerRunnerImpl.class.getName()));
} catch (JSONException e) {
  json.accumulate("queryTypes", new JSONObject().put("label", "QueryBuilder").put("value", "queryBuilder"));
  json.accumulate("queryTypes", new JSONObject().put("label", "List").put("value", "list"));
  json.accumulate("queryTypes", new JSONObject().put("label", "xPath").put("value", "xpath"));
  json.accumulate("queryTypes", new JSONObject().put("label", "JCR-SQL2").put("value", "JCR-SQL2"));
  json.accumulate("queryTypes", new JSONObject().put("label", "JCR-SQL").put("value", "JCR-SQL"));
} catch (JSONException e) {
  log.error("Could not create JSON for QueryType options", e);
      jsonWorkflow.put("value", workflowModel.getId());
      jsonWorkflow.put("transient", transientWorkflow);
      json.accumulate("workflowModels", jsonWorkflow);
    } catch (JSONException e) {
      log.error("Could not add workflow [ {} - {} ] to Workflow Models drop-down JSON object",

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

s = x.nextCDATA();
  if (s.length() > 0) {
    context.accumulate("content", s);
    throw x.syntaxError("Missing value");
  o.accumulate(s, t);
  t = null;
} else {
  o.accumulate(s, "");
  throw x.syntaxError("Misshaped tag");
context.accumulate(n, o);
return false;
    s = (String)t;
    if (s.length() > 0) {
      o.accumulate("content", s);
    if (parse(x, o, n)) {
      if (o.length() == 0) {
        context.accumulate(n, "");
      } else if (o.length() == 1 &&
          o.opt("content") != null) {
        context.accumulate(n, o.opt("content"));
      } else {
        context.accumulate(n, o);

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

json.accumulate("workflowModels", jsonWorkflow);

代码示例来源: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

failureJSON.put(Failure.PN_PAYLOAD_PATH, failure.getNodePath());
failureJSON.put(Failure.PN_FAILED_AT, sdf.format(failure.getTime().getTime()));
json.accumulate("failures", failureJSON);
json.accumulate("failures", failure.toJSON());
json.accumulate("activePayloads", payload.toJSON());

代码示例来源: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: com.adobe.acs/acs-aem-commons-bundle

parent.put("padding", 0);
parent.put("style", "padding: 0px");
parent.accumulate("items", widget);
parent.write(response.getWriter());

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

parent.put("border", false);
parent.put("padding", 0);
parent.accumulate("items", widget);
parent.write(response.getWriter());

相关文章