in org.apache.sling.ddr/core/src/main/java/org/apache/sling/ddr/core/DeclarativeDynamicResourceProviderHandler.java [302:383]
private List<Resource> obtainChildren(ResourceResolver contextResourceResolver, String resourcePath, boolean returnChildren) {
List<Resource> answer = new ArrayList<>();
String postfix = resourcePath.substring(targetRootPath.length());
if (!postfix.isEmpty() && postfix.charAt(0) == '/') {
postfix = postfix.substring(1);
}
List<Reference> childrenList = new ArrayList<>();
childrenMappings.put(resourcePath, childrenList);
String targetPath = providerRootPath + SLASH + postfix;
Reference ref = mappings.get(resourcePath);
Resource provider =
getResource(
contextResourceResolver,
ref == null || !ref.isRef() ?
targetPath:
ref.getReference()
);
log.info("Provider, Path: '{}', Resource: '{}'", targetPath, provider);
if (provider != null) {
Iterator<Resource> i = provider.listChildren();
while (i.hasNext()) {
Resource child = i.next();
// Ignore Policy Nodes
if (child.getName().equals(REP_POLICY)) {
continue;
}
if (filterSource(child)) {
// Check if this entry is a reference and if so get that one instead
ValueMap properties = child.getValueMap();
String referencePath = null;
boolean handled = false;
for (String followedLinkName : followedLinkNames) {
referencePath = properties.get(followedLinkName, String.class);
if (referencePath != null && !referencePath.isEmpty()) {
Resource reference = getResource(contextResourceResolver, referencePath);
if (reference != null && !reference.isResourceType(RESOURCE_TYPE_NON_EXISTING)) {
log.info("Add Path: '{}' to children list", resourcePath);
childrenList.add(new Reference(child.getPath(), referencePath));
String parentPath = targetRootPath + (postfix.isEmpty() ? "" : SLASH + postfix);
mappings.put(parentPath + SLASH + child.getName(), new Reference(child.getPath(), referencePath));
declarativeDynamicResourceManager.addReference(child.getPath(), referencePath);
if(returnChildren) {
answer.add(
createSyntheticFromResource(
reference,
parentPath + SLASH + child.getName(),
parentPath.equals(targetRootPath)
)
);
}
handled = true;
} else {
log.warn("Reference: '{}' provided by does not resolve to a resource", referencePath);
}
}
}
if(!handled) {
// Not a reference
log.info("Add Path: '{}' to children list", child.getPath());
Reference newRef;
if(ref != null && ref.isRef()) {
newRef = new Reference(ref.getSource() + SLASH + child.getName(), child.getPath());
} else {
newRef = new Reference(child.getPath());
}
childrenList.add(newRef);
String parentPath = targetRootPath + (postfix.isEmpty() ? "" : SLASH + postfix);
mappings.put(parentPath + SLASH + child.getName(), newRef);
if(returnChildren) {
answer.add(
createSyntheticFromResource(
child, parentPath + SLASH + child.getName(),
parentPath.equals(targetRootPath)
)
);
}
}
}
}
}
return answer;
}