use of org.apache.sling.api.request.RequestParameter in project acs-aem-commons by Adobe-Consulting-Services.
the class PropertyMergePostProcessor method getPropertyMerges.
/**
* Gets the corresponding list of PropertyMerge directives from the
* RequestParams.
*
* @param requestParameters the Request Param Map
* @return a list of the PropertyMerge directives by Destination
*/
@SuppressWarnings("squid:S3776")
private List<PropertyMerge> getPropertyMerges(final SlingHttpServletRequest request) {
final RequestParameterMap requestParameters = request.getRequestParameterMap();
final HashMap<String, Set<String>> mapping = new HashMap<>();
boolean isBulkUpdate = Boolean.valueOf(getParamValue(requestParameters, "dam:bulkUpdate"));
// Collect the Destination / Source mappings
requestParameters.forEach((key, values) -> {
if (!StringUtils.endsWith(key, AT_SUFFIX)) {
// Not a @PropertyMerge request param
return;
}
Function<String, String> stripPrefix = (s -> StringUtils.removeStart(StringUtils.stripToNull(s), IGNORE_PREFIX));
final String source = stripPrefix.apply(StringUtils.substringBefore(key, AT_SUFFIX));
Stream.of(values).map(RequestParameter::getString).map(stripPrefix).filter(Objects::nonNull).forEach(destination -> {
if (source.equalsIgnoreCase(OPERATION_ALL_TAGS)) {
// if this is a request for merging all tags, look at everyting that might be a tag
trackAllTagsMergeParameters(request, destination, mapping);
} else if (isBulkUpdate) {
// if this is a DAM bulk update, search all request params ending with this value
trackAssetMergeParameters(requestParameters, source, destination, mapping);
} else {
trackMergeParameters(mapping, source, destination);
}
});
});
// Convert the Mappings into PropertyMerge objects
return mapping.entrySet().stream().map(entry -> new PropertyMerge(entry.getKey(), entry.getValue(), areDuplicatesAllowed(requestParameters, entry.getKey()), getFieldTypeHint(requestParameters, entry.getKey()))).collect(Collectors.toList());
}
use of org.apache.sling.api.request.RequestParameter 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.api.request.RequestParameter in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ModelElementsDataSourceServlet method doGet.
@Override
protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) {
// First try to get the model path from request parameters
// otherwise determine model path from component resource.
RequestParameter modelPathRequestParameter = request.getRequestParameter(PARAMETER_AND_PN_MODEL_PATH);
boolean isOrderBy = request.getResource().isResourceType(RESOURCE_TYPE_ORDER_BY_V1);
String modelPath;
if (modelPathRequestParameter != null) {
modelPath = modelPathRequestParameter.getString();
} else {
Config config = getConfig(request);
ValueMap componentValueMap = getComponentValueMap(config, request);
// get model path from component resource
modelPath = componentValueMap != null ? componentValueMap.get(ContentFragmentList.PN_MODEL_PATH, String.class) : null;
}
DataSource dataSource = EmptyDataSource.instance();
if (modelPath != null) {
ResourceResolver resourceResolver = request.getResourceResolver();
String pathToCFModelElements = String.format("%s/%s/model/cq:dialog/content/items", modelPath, JcrConstants.JCR_CONTENT);
Resource cfModelElementRoot = resourceResolver.getResource(pathToCFModelElements);
if (cfModelElementRoot != null) {
Iterator<Resource> resourceIterator = cfModelElementRoot.listChildren();
List<Resource> resourceList = new LinkedList<>();
if (isOrderBy) {
resourceList.add(createResource(resourceResolver, "Created", JcrConstants.JCR_CREATED));
resourceList.add(createResource(resourceResolver, "Last Modified", JcrConstants.JCR_CONTENT + "/" + JcrConstants.JCR_LASTMODIFIED));
}
while (resourceIterator.hasNext()) {
Resource elementResource = resourceIterator.next();
ValueMap valueMap = elementResource.getValueMap();
String valueValue = valueMap.get("name", "");
String textValue = valueMap.get("fieldLabel", valueValue);
if (isOrderBy && StringUtils.isNotEmpty(valueValue)) {
valueValue = "jcr:content/data/master/" + valueValue;
}
String metaType = valueMap.get("metaType", StringUtils.EMPTY);
if (!isOrderBy || StringUtils.startsWith(metaType, "text-")) {
Resource syntheticResource = createResource(resourceResolver, textValue, valueValue);
resourceList.add(syntheticResource);
}
}
dataSource = new SimpleDataSource(resourceList.iterator());
}
}
request.setAttribute(DataSource.class.getName(), dataSource);
}
use of org.apache.sling.api.request.RequestParameter in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class PageImageThumbnail method initModel.
@PostConstruct
protected void initModel() {
configPath = request.getRequestPathInfo().getResourcePath();
componentPath = request.getRequestPathInfo().getSuffix();
if (StringUtils.isBlank(componentPath)) {
RequestParameter itemParam = request.getRequestParameter("item");
if (itemParam == null) {
log.error("Suffix and 'item' param are blank");
return;
}
componentPath = itemParam.getString();
}
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
if (pageManager == null) {
log.error("pagemanager is null");
return;
}
Resource component = resourceResolver.getResource(componentPath);
if (component == null) {
log.error("the component at {} does not exist", componentPath);
return;
}
Page currentPage = pageManager.getContainingPage(component);
if (currentPage != null) {
currentPagePath = currentPage.getPath();
}
Page targetPage = null;
RequestParameter pageLinkParam = request.getRequestParameter("pageLink");
if (pageLinkParam != null) {
// retrieve the page link from the request parameter
String pageLink = pageLinkParam.getString();
targetPage = pageManager.getPage(pageLink);
} else {
// retrieve the page link from the component model
Teaser teaserModel = modelFactory.getModelFromWrappedRequest(request, component, Teaser.class);
Link link = null;
if (teaserModel != null) {
link = teaserModel.getLink();
} else {
Image imageModel = modelFactory.getModelFromWrappedRequest(request, component, Image.class);
if (imageModel != null) {
link = imageModel.getImageLink();
}
}
if (link != null) {
targetPage = (Page) link.getReference();
} else {
targetPage = currentPage;
}
}
if (targetPage == null) {
log.info("A target page cannot be found for the link defined in the request parameter or on the server at {}.", component.getPath());
return;
}
Resource featuredImage = ComponentUtils.getFeaturedImage(targetPage);
if (featuredImage == null) {
log.info("No featured image defined for the page at {}", targetPage.getPath());
return;
}
Image imageModel = modelFactory.getModelFromWrappedRequest(request, featuredImage, Image.class);
if (imageModel == null) {
log.info("the image model of {} is null", featuredImage.getPath());
return;
}
this.alt = imageModel.getAlt();
this.src = imageModel.getSrc();
}
use of org.apache.sling.api.request.RequestParameter in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class InheritedField method initModel.
@PostConstruct
private void initModel() {
path = slingRequest.getRequestPathInfo().getSuffix();
if (StringUtils.isBlank(path)) {
RequestParameter itemParam = slingRequest.getRequestParameter("item");
if (itemParam == null) {
log.error("Suffix and 'item' param are blank");
return;
}
path = itemParam.getString();
}
if (StringUtils.isBlank(prop)) {
log.error("'prop' value is null");
return;
}
ResourceResolver rr = slingRequest.getResourceResolver();
PageManager pm = rr.adaptTo(PageManager.class);
if (pm == null) {
log.error("pagemanager is null");
return;
}
containingPage = pm.getPage(path);
if (containingPage == null) {
log.error("page is null");
return;
}
inheritedValue = Utils.getInheritedValue(containingPage.getParent(), prop);
Resource contentResource = containingPage.getContentResource();
if (contentResource == null) {
return;
}
ValueMap props = contentResource.adaptTo(ValueMap.class);
if (props == null) {
return;
}
override = props.get(getProp() + OVERRIDE_SUFFIX, OVERRIDE_DEFAULT);
specifiedValue = props.get(getProp(), String.class);
}
Aggregations