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

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

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

JSONObject.optString介绍

[英]Get an optional string associated with a key. It returns an empty string if there is no such key. If the value is not a string and is not null, then it is coverted to a string.
[中]获取与键关联的可选字符串。如果没有这样的键,它将返回一个空字符串。如果值不是字符串且不为null,则将其转换为字符串。

代码示例

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

/**
 * Get an optional string associated with a key.
 * It returns an empty string if there is no such key. If the value is not
 * a string and is not null, then it is coverted to a string.
 *
 * @param key   A key string.
 * @return      A string which is the value.
 */
public String optString(String key) {
  return optString(key, "");
}

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

protected boolean isCqincludeNamespaceWidget(JSONObject jsonObject) {
  if (StringUtils.equals(jsonObject.optString(JcrConstants.JCR_PRIMARYTYPE), NT_CQ_WIDGET)
      && (StringUtils.equals(jsonObject.optString(PN_XTYPE), "cqinclude"))) {
    String path = jsonObject.optString(PN_PATH);
    if (StringUtils.isNotBlank(path) &&
        path.matches(CQINCLUDE_NAMESPACE_URL_REGEX)) {
      return true;
    }
  }
  return false;
}

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

protected JSONObject makeMultiLevel(JSONObject jsonObject) {
  String path = jsonObject.optString(PN_PATH);
  if (StringUtils.isNotBlank(path)) {
    Pattern pattern = Pattern.compile(CQINCLUDE_NAMESPACE_URL_REGEX);
    Matcher m = pattern.matcher(path);
    if (m.matches()) {
      path = m.group(1) + this.namespace + ESCAPED_SLASH + m.group(2) + m.group(3);
      try {
        jsonObject.put(PN_PATH, path);
      } catch (JSONException e) {
        log.error("Could not update cqinclude namespace with path [ {} ]", path);
      }
    }
  }
  return jsonObject;
}

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

rootPath = json.optString("rootPath", "");
template = json.optString("template", "");
total = json.optInt("total", 0);
bucketSize = json.optInt("bucketSize", DEFAULT_BUCKET_SIZE);
bucketType = json.optString("bucketType", DEFAULT_BUCKET_TYPE);
saveThreshold = json.optInt("saveThreshold", DEFAULT_SAVE_THRESHOLD);
    String name = item.optString("name", "");
        for (String value : StringUtils.split(item.optString("value", ""), ",")) {
          final String tmp = StringUtils.stripToNull(value);
          if (tmp != null) {
        String value = item.optString("value", "");
        properties.put(name, value);

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

protected void visit(JSONObject jsonObject) {
  if (StringUtils.equals(jsonObject.optString(JcrConstants.JCR_PRIMARYTYPE), NT_CQ_WIDGET)) {
    if (supportMultiLevel) {
      if (isCqincludeNamespaceWidget(jsonObject)) {
      final String propertyName = keys.next();
      if (!this.accept(propertyName, jsonObject.optString(propertyName))) {
        log.debug("Property [ {} ~> {} ] is not a namespace-able property name/value", propertyName,
            jsonObject.optString(propertyName));
        continue;
      String value = jsonObject.optString(propertyName);

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

public Parameters(SlingHttpServletRequest request) throws IOException, JSONException {
  final JSONObject json = new JSONObject(request.getParameter("params"));
  final List<String> customProperties = new ArrayList<String>();
  final List<String> groups = new ArrayList<String>();
  groupFilter = json.getString(GROUP_FILTER);
  JSONArray groupsJSON = json.getJSONArray(GROUPS);
  for (int i = 0; i < groupsJSON.length(); i++) {
    groups.add(groupsJSON.getString(i));
  }
  this.groups = groups.toArray(new String[groups.size()]);
  JSONArray customPropertiesJSON = json.getJSONArray(CUSTOM_PROPERTIES);
  for (int i = 0; i < customPropertiesJSON.length(); i++) {
    JSONObject tmp = customPropertiesJSON.getJSONObject(i);
    String relativePropertyPath = tmp.optString(RELATIVE_PROPERTY_PATH);
    if (StringUtils.isNotBlank(relativePropertyPath)) {
      customProperties.add(relativePropertyPath);
    }
  }
  this.customProperties = customProperties.toArray(new String[customProperties.size()]);
}

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

return StringUtils.equals(value, json.optString(key));

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

@Override
 public Optional<List<Session>> deserialize(String data) {
  final ArrayList<Session> sessions = new ArrayList<>();
  try {
   final JSONArray array = new JSONArray(data);
   for (int i = 0; i < array.length(); i++) {
    final JSONObject jsonObject = array.getJSONObject(i);
    String name = jsonObject.getString("name");
    final ArrayList<FileToOpen> fileToOpens = new ArrayList<>();
    final JSONArray filesArray = jsonObject.optJSONArray("filesToOpen");
    if (filesArray != null){
     for (int j = 0; j < filesArray.length(); j++) {
      final JSONObject filesToOpen = filesArray.getJSONObject(j);
      String uri = filesToOpen.getString("uri");
      Level level = Level.parse(filesToOpen.getString("level"));
      OpenMode openMode = OpenMode.valueOf(filesToOpen.getString("openMode"));
      String logImporter = filesToOpen.optString("logImporter", null);
      fileToOpens.add(new FileToOpen(uri, openMode, level, Optional.ofNullable(logImporter)));
     }
    }
    sessions.add(new Session(name, fileToOpens));
   }
  } catch (JSONException e) {
   LOGGER.error("Can't deserialize sessions: ", e);
   Optional.empty();
  }
  LOGGER.info("Returning deserialized sessions: " + sessions.size());
  return Optional.of(sessions);
 }
}

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

for (int i = 0; i < jsonArray.length(); i++) {
  final JSONObject tmp = jsonArray.getJSONObject(i);
  final String pattern = tmp.optString("pattern");

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

final JSONObject jsonData = new JSONObject(requestData);
final String incomingFormName = jsonData.optString(KEY_FORM_NAME);

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

properties.put("queryType", params.getString("queryType"));
properties.put("queryStatement", params.getString("queryStatement"));
properties.put("relativePath", StringUtils.removeStart(params.optString("relativePath", ""), "/"));
properties.put("workflowModel", params.getString("workflowModelId"));
properties.put("interval", params.optInt("interval", 10));

相关文章