/** * 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, ""); }
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; }
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; }
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);
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);
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()]); }
return StringUtils.equals(value, json.optString(key));
@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); } }
for (int i = 0; i < jsonArray.length(); i++) { final JSONObject tmp = jsonArray.getJSONObject(i); final String pattern = tmp.optString("pattern");
final JSONObject jsonData = new JSONObject(requestData); final String incomingFormName = jsonData.optString(KEY_FORM_NAME);
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));