use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class WorkflowModelFilterPageInfoProvider method filter.
@SuppressWarnings("squid:S3776")
private void filter(JSONObject typeObject, String resourcePath, ResourceResolver resourceResolver) throws JSONException {
final JSONArray models = typeObject.getJSONArray(KEY_MODELS);
final JSONArray newModels = new JSONArray();
for (int i = 0; i < models.length(); i++) {
final JSONObject modelObject = models.getJSONObject(i);
final String path = modelObject.getString(KEY_MODEL_PATH);
final Resource modelResource = resourceResolver.getResource(path);
if (modelResource != null) {
// we're looking for the appliesTo property on the jcr:content node, the wid value
// is the path to the jcr:content/model node.
final ValueMap properties = modelResource.getParent().getValueMap();
final String[] allowedPaths = properties.get(PN_ALLOWED_PATHS, String[].class);
if (allowedPaths == null) {
newModels.put(modelObject);
} else {
for (final String allowedPath : allowedPaths) {
if (resourcePath.matches(allowedPath)) {
newModels.put(modelObject);
break;
}
}
}
}
}
typeObject.put(KEY_MODELS, newModels);
}
use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class CQIncludePropertyNamespaceServlet method doGet.
// @formatter:on
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
if (!this.accepts(request)) {
response.setStatus(SlingHttpServletResponse.SC_NOT_FOUND);
response.getWriter().write(new JSONObject().toString());
}
/* Servlet accepts this request */
RequestUtil.setRequestAttribute(request, REQ_ATTR, true);
final String namespace = URLDecoder.decode(PathInfoUtil.getSelector(request, NAME_PROPERTY_SELECTOR_INDEX), "UTF-8");
final RequestDispatcherOptions options = new RequestDispatcherOptions();
options.setReplaceSelectors(AEM_CQ_INCLUDE_SELECTORS);
final BufferingResponse bufferingResponse = new BufferingResponse(response);
request.getRequestDispatcher(request.getResource(), options).forward(request, bufferingResponse);
try {
final JSONObject json = new JSONObject(bufferingResponse.getContents());
final PropertyNamespaceUpdater propertyNamespaceUpdater = new PropertyNamespaceUpdater(namespace);
propertyNamespaceUpdater.accept(json);
response.getWriter().write(json.toString());
} catch (JSONException e) {
log.error("Error composing the cqinclude JSON representation of the widget overlay for [ {} ]", request.getRequestURI(), e);
response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR);
response.getWriter().write(new JSONObject().toString());
}
}
use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class RTEConfigurationServlet method createEmptyWidget.
@Override
protected JSONObject createEmptyWidget(String rteName) throws JSONException {
JSONObject object = new JSONObject();
object.put("xtype", "richtext");
object.put("name", "./" + xssApi.encodeForJSString(rteName));
object.put("hideLabel", true);
object.put("jcr:primaryType", "cq:Widget");
return object;
}
use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class TagWidgetConfigurationServlet method writeConfigResource.
private void writeConfigResource(Resource resource, String propertyName, SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, JSONException, ServletException {
JSONObject widget = createEmptyWidget(propertyName);
RequestParameterMap map = request.getRequestParameterMap();
for (Map.Entry<String, RequestParameter[]> entry : map.entrySet()) {
String key = entry.getKey();
RequestParameter[] params = entry.getValue();
if (params != null) {
if (params.length > 1) {
JSONArray arr = new JSONArray();
for (int i = 0; i < params.length; i++) {
arr.put(params[i].getString());
}
widget.put(key, arr);
} else if (params.length == 1) {
widget.put(key, params[0].getString());
}
}
}
widget = underlay(widget, resource);
JSONObject parent = new JSONObject();
parent.put("xtype", "dialogfieldset");
parent.put("border", false);
parent.put("padding", 0);
parent.put("style", "padding: 0px");
parent.accumulate("items", widget);
parent.write(response.getWriter());
}
use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class TagWidgetConfigurationServlet method createEmptyWidget.
@Override
protected JSONObject createEmptyWidget(String propertyName) throws JSONException {
JSONObject object = new JSONObject();
object.put("xtype", "tags");
object.put("name", "./" + xssApi.encodeForJSString(propertyName));
object.put("fieldLabel", "Tags/Keywords");
object.put("jcr:primaryType", "cq:Widget");
return object;
}
Aggregations