@Test void testCopySubtree() { Resource parent = create(context.resourceResolver(), "/target/path", "/my/type"); Resource source = context.create().resource("/source", "sling:resourceType", "/my/type2", "prop1", "value1"); context.create().resource("/source/child1", "sling:resourceType", "/my/type3", "prop1", "value2"); context.create().resource("/source/child1/child11"); context.create().resource("/source/child1/child12"); context.create().resource("/source/child2"); copySubtree(parent, source); List<Resource> children1 = ImmutableList.copyOf(parent.getChildren()); assertEquals(1, children1.size()); assertEquals("/target/path/source", children1.get(0).getPath()); assertEquals("value1", children1.get(0).getValueMap().get("prop1", String.class)); List<Resource> children2 = ImmutableList.copyOf(children1.get(0).getChildren()); assertEquals(2, children2.size()); assertEquals("/target/path/source/child1", children2.get(0).getPath()); assertEquals("value2", children2.get(0).getValueMap().get("prop1", String.class)); assertEquals("/target/path/source/child2", children2.get(1).getPath()); List<Resource> children3 = ImmutableList.copyOf(children2.get(0).getChildren()); assertEquals(2, children3.size()); assertEquals("/target/path/source/child1/child11", children3.get(0).getPath()); assertEquals("/target/path/source/child1/child12", children3.get(1).getPath()); }
public static void copySubtree(@NotNull Resource targetParent, @NotNull Resource source) { Resource targetChild = GraniteUiSyntheticResource.child(targetParent, source.getName(), source.getResourceType(), source.getValueMap()); for (Resource sourceChild : source.getChildren()) { copySubtree(targetChild, sourceChild); } }
GraniteUiSyntheticResource extends SyntheticResource { public static void copySubtree(@NotNull Resource targetParent, @NotNull Resource source) { Resource targetChild = GraniteUiSyntheticResource.child(targetParent, source.getName(), source.getResourceType(), source.getValueMap()); for (Resource sourceChild : source.getChildren()) { copySubtree(targetChild, sourceChild); } } }
GraniteUiSyntheticResource extends SyntheticResource { public static void copySubtree(@NotNull Resource targetParent, @NotNull Resource source) { Resource targetChild = GraniteUiSyntheticResource.child(targetParent, source.getName(), source.getResourceType(), source.getValueMap()); for (Resource sourceChild : source.getChildren()) { copySubtree(targetChild, sourceChild); } } private  GraniteUiSyntheticResource(ResourceResolver resourceResolver,
      ResourceMetadata resourceMetadata, String resourceType,
      ValueMap props, Iterable<Resource> children); private  GraniteUiSyntheticResource(ResourceResolver resourceResolver,
      String path,
      String resourceType,
      ValueMap props,
      Iterable<Resource> children); }
GraniteUiSyntheticResource extends SyntheticResource { public static void copySubtree(@NotNull Resource targetParent, @NotNull Resource source) { Resource targetChild = GraniteUiSyntheticResource.child(targetParent, source.getName(), source.getResourceType(), source.getValueMap()); for (Resource sourceChild : source.getChildren()) { copySubtree(targetChild, sourceChild); } } private  GraniteUiSyntheticResource(ResourceResolver resourceResolver,
      ResourceMetadata resourceMetadata, String resourceType,
      ValueMap props, Iterable<Resource> children); private  GraniteUiSyntheticResource(ResourceResolver resourceResolver,
      String path,
      String resourceType,
      ValueMap props,
      Iterable<Resource> children); @SuppressWarnings({ "unchecked", "null" }) @Override Type adaptTo(Class<Type> type); @Override Iterator<Resource> listChildren(); @Override Iterable<Resource> getChildren(); @Override boolean hasChildren(); @Override Resource getChild(String relPath); static Resource create(@NotNull ResourceResolver resourceResolver, @NotNull ValueMap valueMap); static Resource create(@NotNull ResourceResolver resourceResolver, @Nullable String path, @NotNull String resourceType); static Resource create(@NotNull ResourceResolver resourceResolver, @Nullable String path, @NotNull String resourceType,
      @NotNull ValueMap valueMap); static Resource wrap(@NotNull Resource resource); static Resource wrap(@NotNull Resource resource, @NotNull ValueMap valueMap); static Resource wrapMerge(@NotNull Resource resource, @NotNull ValueMap valueMap); static Resource child(@NotNull Resource parentResource, @NotNull String name, @NotNull String resourceType); static Resource child(@NotNull Resource parentResource, @NotNull String name, @NotNull String resourceType,
      @NotNull ValueMap valueMap); static void copySubtree(@NotNull Resource targetParent, @NotNull Resource source); }
GraniteUiSyntheticResource extends SyntheticResource { public static void copySubtree(@NotNull Resource targetParent, @NotNull Resource source) { Resource targetChild = GraniteUiSyntheticResource.child(targetParent, source.getName(), source.getResourceType(), source.getValueMap()); for (Resource sourceChild : source.getChildren()) { copySubtree(targetChild, sourceChild); } } private  GraniteUiSyntheticResource(ResourceResolver resourceResolver,
      ResourceMetadata resourceMetadata, String resourceType,
      ValueMap props, Iterable<Resource> children); private  GraniteUiSyntheticResource(ResourceResolver resourceResolver,
      String path,
      String resourceType,
      ValueMap props,
      Iterable<Resource> children); @SuppressWarnings({ "unchecked", "null" }) @Override Type adaptTo(Class<Type> type); @Override Iterator<Resource> listChildren(); @Override Iterable<Resource> getChildren(); @Override boolean hasChildren(); @Override Resource getChild(String relPath); static Resource create(@NotNull ResourceResolver resourceResolver, @NotNull ValueMap valueMap); static Resource create(@NotNull ResourceResolver resourceResolver, @Nullable String path, @NotNull String resourceType); static Resource create(@NotNull ResourceResolver resourceResolver, @Nullable String path, @NotNull String resourceType,
      @NotNull ValueMap valueMap); static Resource wrap(@NotNull Resource resource); static Resource wrap(@NotNull Resource resource, @NotNull ValueMap valueMap); static Resource wrapMerge(@NotNull Resource resource, @NotNull ValueMap valueMap); static Resource child(@NotNull Resource parentResource, @NotNull String name, @NotNull String resourceType); static Resource child(@NotNull Resource parentResource, @NotNull String name, @NotNull String resourceType,
      @NotNull ValueMap valueMap); static void copySubtree(@NotNull Resource targetParent, @NotNull Resource source);  }