@Test public void testCreateSubnodeWithUniqueNameAndAppendValue() throws Exception { MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(context.resourceResolver()); request.setResource(context.resourceResolver().resolve("/content/postprocessor/jcr:content/existingComposite")); request.setParameterMap(Collections.singletonMap("./multiDropTarget->/subNode/{{COMPOSITE}}/@link", "b")); MultiFieldDropTargetPostProcessor dropTargetPostProcessor = new MultiFieldDropTargetPostProcessor(); List<Modification> modifications = new ArrayList<>(); dropTargetPostProcessor.process(request, modifications); Resource resource = request.getResource(); assertThat(modifications) .isNotEmpty() .hasSize(1); assertThat(resource).isNotNull(); assertThat(resource.getValueMap()) .isNotEmpty() .doesNotContainKeys("./items") .doesNotContainKeys("./multiDropTarget->/subNode/{{COMPOSITE}}/@link"); assertThat(resource.getChild("multiDropTarget->")).isNull(); assertThat(resource.getChild("subNode")).isNotNull(); assertThat(resource.getChild("subNode").getChildren()).hasSize(3); assertThat(resource.getChild("subNode/item0")).isNotNull(); assertThat(resource.getChild("subNode/item1")).isNotNull(); assertThat(resource.getChild("subNode/item2")).isNotNull(); assertThat(resource.getChild("subNode/item0").getValueMap()) .contains( entry("jcr:primaryType", "nt:unstructured"), entry("link", "a")); assertThat(resource.getChild("subNode/item1").getValueMap()) .contains( entry("jcr:primaryType", "nt:unstructured"), entry("link", "c")); assertThat(resource.getChild("subNode/item2").getValueMap()) .contains( entry("link", "b")); }
@Override public void process(SlingHttpServletRequest request, List<Modification> modifications) throws Exception { RequestParameterMap requestParameterMap = request.getRequestParameterMap(); for (String key : requestParameterMap.keySet()) { if (key.startsWith(DROP_TARGET_PREFIX)) { RequestParameter requestParameter = requestParameterMap.getValue(key); if (requestParameter != null) { String target = key.replace(DROP_TARGET_PREFIX, StringUtils.EMPTY); String propertyValue = requestParameter.getString(); Resource resource = request.getResource(); if (requestParameterMap.containsKey(SLING_COPY_FROM)) { Modification copyFrom = modifications .stream() .filter(m -> ModificationType.COPY.equals(m.getType())) .findFirst().orElseGet(null); if (copyFrom != null) { Resource dropComponent = resource.getResourceResolver().getResource(copyFrom.getDestination()); ModifiableValueMap properties = dropComponent.adaptTo(ModifiableValueMap.class); properties.remove(target); resource = dropComponent; } } RequestParameter selectionTypeParameter = requestParameterMap.getValue(SELECTION_ID); String selectionType = selectionTypeParameter != null ? selectionTypeParameter.getString() : null; RequestParameter multipleParameter = requestParameterMap.getValue(MULTIPLE); boolean multiple = true; if (multipleParameter != null) { multiple = Boolean.valueOf(multipleParameter.getString()); } processProperty(resource, target, propertyValue, key, selectionType, multiple); modifications.add(Modification.onModified(resource.getPath())); } } } }
MultiFieldDropTargetPostProcessor implements SlingPostProcessor { @Override public void process(SlingHttpServletRequest request, List<Modification> modifications) throws Exception { RequestParameterMap requestParameterMap = request.getRequestParameterMap(); for (String key : requestParameterMap.keySet()) { if (key.startsWith(DROP_TARGET_PREFIX)) { RequestParameter requestParameter = requestParameterMap.getValue(key); if (requestParameter != null) { String target = key.replace(DROP_TARGET_PREFIX, StringUtils.EMPTY); String propertyValue = requestParameter.getString(); Resource resource = request.getResource(); if (requestParameterMap.containsKey(SLING_COPY_FROM)) { Modification copyFrom = modifications .stream() .filter(m -> ModificationType.COPY.equals(m.getType())) .findFirst().orElseGet(null); if (copyFrom != null) { Resource dropComponent = resource.getResourceResolver().getResource(copyFrom.getDestination()); ModifiableValueMap properties = dropComponent.adaptTo(ModifiableValueMap.class); properties.remove(target); resource = dropComponent; } } RequestParameter selectionTypeParameter = requestParameterMap.getValue(SELECTION_ID); String selectionType = selectionTypeParameter != null ? selectionTypeParameter.getString() : null; RequestParameter multipleParameter = requestParameterMap.getValue(MULTIPLE); boolean multiple = true; if (multipleParameter != null) { multiple = Boolean.valueOf(multipleParameter.getString()); } processProperty(resource, target, propertyValue, key, selectionType, multiple); modifications.add(Modification.onModified(resource.getPath())); } } } } }
MultiFieldDropTargetPostProcessor implements SlingPostProcessor { @Override public void process(SlingHttpServletRequest request, List<Modification> modifications) throws Exception { RequestParameterMap requestParameterMap = request.getRequestParameterMap(); for (String key : requestParameterMap.keySet()) { if (key.startsWith(DROP_TARGET_PREFIX)) { RequestParameter requestParameter = requestParameterMap.getValue(key); if (requestParameter != null) { String target = key.replace(DROP_TARGET_PREFIX, StringUtils.EMPTY); String propertyValue = requestParameter.getString(); Resource resource = request.getResource(); if (requestParameterMap.containsKey(SLING_COPY_FROM)) { Modification copyFrom = modifications .stream() .filter(m -> ModificationType.COPY.equals(m.getType())) .findFirst().orElseGet(null); if (copyFrom != null) { Resource dropComponent = resource.getResourceResolver().getResource(copyFrom.getDestination()); ModifiableValueMap properties = dropComponent.adaptTo(ModifiableValueMap.class); properties.remove(target); resource = dropComponent; } } RequestParameter selectionTypeParameter = requestParameterMap.getValue(SELECTION_ID); String selectionType = selectionTypeParameter != null ? selectionTypeParameter.getString() : null; RequestParameter multipleParameter = requestParameterMap.getValue(MULTIPLE); boolean multiple = true; if (multipleParameter != null) { multiple = Boolean.valueOf(multipleParameter.getString()); } processProperty(resource, target, propertyValue, key, selectionType, multiple); modifications.add(Modification.onModified(resource.getPath())); } } } }  }
MultiFieldDropTargetPostProcessor implements SlingPostProcessor { @Override public void process(SlingHttpServletRequest request, List<Modification> modifications) throws Exception { RequestParameterMap requestParameterMap = request.getRequestParameterMap(); for (String key : requestParameterMap.keySet()) { if (key.startsWith(DROP_TARGET_PREFIX)) { RequestParameter requestParameter = requestParameterMap.getValue(key); if (requestParameter != null) { String target = key.replace(DROP_TARGET_PREFIX, StringUtils.EMPTY); String propertyValue = requestParameter.getString(); Resource resource = request.getResource(); if (requestParameterMap.containsKey(SLING_COPY_FROM)) { Modification copyFrom = modifications .stream() .filter(m -> ModificationType.COPY.equals(m.getType())) .findFirst().orElseGet(null); if (copyFrom != null) { Resource dropComponent = resource.getResourceResolver().getResource(copyFrom.getDestination()); ModifiableValueMap properties = dropComponent.adaptTo(ModifiableValueMap.class); properties.remove(target); resource = dropComponent; } } RequestParameter selectionTypeParameter = requestParameterMap.getValue(SELECTION_ID); String selectionType = selectionTypeParameter != null ? selectionTypeParameter.getString() : null; RequestParameter multipleParameter = requestParameterMap.getValue(MULTIPLE); boolean multiple = true; if (multipleParameter != null) { multiple = Boolean.valueOf(multipleParameter.getString()); } processProperty(resource, target, propertyValue, key, selectionType, multiple); modifications.add(Modification.onModified(resource.getPath())); } } } }  @Override void process(SlingHttpServletRequest request, List<Modification> modifications); }
MultiFieldDropTargetPostProcessor implements SlingPostProcessor { @Override public void process(SlingHttpServletRequest request, List<Modification> modifications) throws Exception { RequestParameterMap requestParameterMap = request.getRequestParameterMap(); for (String key : requestParameterMap.keySet()) { if (key.startsWith(DROP_TARGET_PREFIX)) { RequestParameter requestParameter = requestParameterMap.getValue(key); if (requestParameter != null) { String target = key.replace(DROP_TARGET_PREFIX, StringUtils.EMPTY); String propertyValue = requestParameter.getString(); Resource resource = request.getResource(); if (requestParameterMap.containsKey(SLING_COPY_FROM)) { Modification copyFrom = modifications .stream() .filter(m -> ModificationType.COPY.equals(m.getType())) .findFirst().orElseGet(null); if (copyFrom != null) { Resource dropComponent = resource.getResourceResolver().getResource(copyFrom.getDestination()); ModifiableValueMap properties = dropComponent.adaptTo(ModifiableValueMap.class); properties.remove(target); resource = dropComponent; } } RequestParameter selectionTypeParameter = requestParameterMap.getValue(SELECTION_ID); String selectionType = selectionTypeParameter != null ? selectionTypeParameter.getString() : null; RequestParameter multipleParameter = requestParameterMap.getValue(MULTIPLE); boolean multiple = true; if (multipleParameter != null) { multiple = Boolean.valueOf(multipleParameter.getString()); } processProperty(resource, target, propertyValue, key, selectionType, multiple); modifications.add(Modification.onModified(resource.getPath())); } } } }  @Override void process(SlingHttpServletRequest request, List<Modification> modifications);  }