use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class RTEConfigurationServlet method writeConfigResource.
private void writeConfigResource(Resource resource, String rteName, SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, JSONException, ServletException {
JSONObject widget = createEmptyWidget(rteName);
// these two size properties seem to be necessary to get the size correct
// in a component dialog
widget.put("width", RTE_WIDTH);
widget.put("height", RTE_HEIGHT);
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 || EXTERNAL_STYLESHEETS_PROPERTY.equals(key)) {
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());
}
}
}
if (widget.has("fieldLabel")) {
widget.remove("hideLabel");
}
JSONObject config = toJSONObject(resource);
if (config == null) {
config = new JSONObject();
}
if (config.optBoolean("includeDefault")) {
config = underlay(config, resource.getResourceResolver().getResource(DEFAULT_CONFIG));
}
widget.put("rtePlugins", config);
JSONObject parent = new JSONObject();
parent.put("xtype", "dialogfieldset");
parent.put("border", false);
parent.put("padding", 0);
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 WorkflowModelFilterPageInfoProvider method updatePageInfo.
@Override
public void updatePageInfo(SlingHttpServletRequest request, JSONObject info, Resource resource) throws JSONException {
if (info.has(KEY_WORKFLOWS)) {
final JSONObject workflows = info.getJSONObject(KEY_WORKFLOWS);
final String resourcePath = resource.getPath();
final ResourceResolver resourceResolver = resource.getResourceResolver();
for (final Iterator<String> types = workflows.keys(); types.hasNext(); ) {
final String type = types.next();
final JSONObject typeObject = workflows.getJSONObject(type);
filter(typeObject, resourcePath, resourceResolver);
}
} else {
log.warn("No workflows found in existing page info. Check order of cq:infoProviders.");
}
}
use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class SharedComponentPropertiesPageInfoProvider method updatePageInfo.
/**
* Add a "sharedComponentProperties" section to pageInfo so that JS libs in the authoring interface
* can determine whether or not to enable shared/global properties for a component on a site.
*/
@Override
public void updatePageInfo(SlingHttpServletRequest request, JSONObject info, Resource resource) throws JSONException {
if (scheduledSharedComponentsMapUpdate > 0 && System.currentTimeMillis() > scheduledSharedComponentsMapUpdate) {
scheduledSharedComponentsMapUpdate = -1L;
updateSharedComponentsMap();
}
JSONObject props = new JSONObject();
props.put("enabled", false);
Page page = pageRootProvider.getRootPage(resource);
if (page != null) {
Session session = request.getResourceResolver().adaptTo(Session.class);
try {
AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session);
Privilege privilegeAddChild = accessControlManager.privilegeFromName("jcr:addChildNodes");
Privilege privilegeModifyProps = accessControlManager.privilegeFromName("jcr:modifyProperties");
Privilege[] requiredPrivs = new Privilege[] { privilegeAddChild, privilegeModifyProps };
if (accessControlManager.hasPrivileges(page.getPath() + "/jcr:content", requiredPrivs)) {
props.put("enabled", true);
props.put("root", page.getPath());
props.put("components", Maps.transformValues(componentsWithSharedProperties, (Function<List<Boolean>, Object>) JSONArray::new));
} else {
log.debug("User does not have [ {} ] on [ {} ]", requiredPrivs, page.getPath() + "/jcr:content");
}
} catch (RepositoryException e) {
log.error("Unexpected error checking permissions to modify shared component properties", e);
}
} else {
log.debug("No Page Root could be found for [ {} ]", resource.getPath());
}
info.put("sharedComponentProperties", props);
}
use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class DataSourceBuilderImpl method writeDataSourceOptions.
@Override
public void writeDataSourceOptions(final SlingHttpServletRequest slingRequest, final SlingHttpServletResponse slingResponse) throws JSONException, IOException {
final DataSource datasource = (DataSource) slingRequest.getAttribute(DataSource.class.getName());
final JSONArray jsonArray = new JSONArray();
if (datasource != null) {
final Iterator<Resource> iterator = datasource.iterator();
if (iterator != null) {
while (iterator.hasNext()) {
final Resource dataResource = iterator.next();
if (dataResource != null) {
final ValueMap dataProps = dataResource.adaptTo(ValueMap.class);
if (dataProps != null) {
final JSONObject json = new JSONObject();
json.put(TEXT, dataProps.get(TEXT, ""));
json.put(VALUE, dataProps.get(VALUE, ""));
jsonArray.put(json);
}
}
}
}
}
slingResponse.setContentType("application/json; charset=UTF-8");
slingResponse.setCharacterEncoding("UTF-8");
slingResponse.getWriter().write(jsonArray.toString());
}
Aggregations