in src/main/java/org/apache/sling/bundleresource/impl/BundleResource.java [71:163]
public BundleResource(final ResourceResolver resourceResolver,
final BundleResourceCache cache,
final PathMapping mappedPath,
final String resourcePath,
final Map<String, Object> readProps,
final boolean isFolder) {
this.resourceResolver = resourceResolver;
this.cache = cache;
this.mappedPath = mappedPath;
metadata = new ResourceMetadata();
metadata.setResolutionPath(resourcePath);
metadata.setCreationTime(this.cache.getBundle().getLastModified());
metadata.setModificationTime(this.cache.getBundle().getLastModified());
this.path = resourcePath;
final Map<String, Object> properties = new HashMap<>();
this.valueMap = new ValueMapDecorator(Collections.unmodifiableMap(properties));
if (isFolder) {
properties.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, NT_FOLDER);
} else {
properties.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, NT_FILE);
try {
final URL url = this.cache.getEntry(mappedPath.getEntryPath(resourcePath));
if ( url != null ) {
metadata.setContentLength(url.openConnection().getContentLength());
}
} catch (final Exception e) {
// don't care, we just have no content length
}
}
Map<String, Map<String, Object>> children = null;
if ( readProps != null ) {
for(final Map.Entry<String, Object> entry : readProps.entrySet()) {
if ( entry.getValue() instanceof Map ) {
if ( children == null ) {
children = new HashMap<>();
}
children.put(entry.getKey(), (Map<String, Object>)entry.getValue());
} else {
properties.put(entry.getKey(), entry.getValue());
}
}
}
if ( this.mappedPath.getJSONPropertiesExtension() != null ) {
String propsPath = mappedPath.getEntryPath(resourcePath.concat(this.mappedPath.getJSONPropertiesExtension()));
if (propsPath == null && resourcePath.equals(mappedPath.getResourceRoot())) {
// SLING-10140 - Handle the special case when the resourceRoot points to a file.
// In that case, the JSONProperties sibling entry may still exist
// in the bundle but it would not be contained within the mappedPath set.
// Start with mapped path for the original resource
String entryPath = mappedPath.getEntryPath(resourcePath);
if (entryPath != null) {
// and then add the extension for the candidate sibling path
propsPath = entryPath.concat(this.mappedPath.getJSONPropertiesExtension());
}
}
if ( propsPath != null ) {
try {
final URL url = this.cache.getEntry(propsPath);
if (url != null) {
final JsonObject obj = Json.createReader(url.openStream()).readObject();
for(final Map.Entry<String, JsonValue> entry : obj.entrySet()) {
final Object value = getValue(entry.getValue(), true);
if ( value != null ) {
if ( value instanceof Map ) {
if ( children == null ) {
children = new HashMap<>();
}
children.put(entry.getKey(), (Map<String, Object>)value);
} else {
properties.put(entry.getKey(), value);
}
}
}
}
} catch (final IOException ioe) {
log.error(
"getInputStream: Cannot get input stream for " + propsPath, ioe);
}
}
}
this.subResources = children;
}