Search in sources :

Example 1 with ValueMapDecorator

use of org.apache.sling.fsprovider.internal.mapper.valuemap.ValueMapDecorator in project sling by apache.

the class FileResource method getValueMap.

@Override
public ValueMap getValueMap() {
    if (valueMap == null) {
        // we should simulate the corresponding JCR properties in a value map as well
        if (file.exists() && file.canRead()) {
            Map<String, Object> props = new HashMap<String, Object>();
            props.put("jcr:primaryType", file.isFile() ? RESOURCE_TYPE_FILE : RESOURCE_TYPE_FOLDER);
            props.put("jcr:createdBy", "system");
            Calendar lastModifed = Calendar.getInstance();
            lastModifed.setTimeInMillis(file.lastModified());
            props.put("jcr:created", lastModifed);
            // overlay properties with those from node descriptor content file, if it exists
            ContentFile contentFile = getNodeDescriptorContentFile();
            if (contentFile != null) {
                for (Map.Entry<String, Object> entry : contentFile.getValueMap().entrySet()) {
                    // skip primary type if it is the default type assigned by contentparser when none is defined
                    if (StringUtils.equals(entry.getKey(), "jcr:primaryType") && StringUtils.equals((String) entry.getValue(), ParserOptions.DEFAULT_PRIMARY_TYPE)) {
                        continue;
                    }
                    props.put(entry.getKey(), entry.getValue());
                }
            }
            valueMap = new ValueMapDecorator(props);
        }
    }
    return valueMap;
}
Also used : HashMap(java.util.HashMap) Calendar(java.util.Calendar) ValueMapDecorator(org.apache.sling.fsprovider.internal.mapper.valuemap.ValueMapDecorator) ValueMap(org.apache.sling.api.resource.ValueMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ValueMap (org.apache.sling.api.resource.ValueMap)1 ValueMapDecorator (org.apache.sling.fsprovider.internal.mapper.valuemap.ValueMapDecorator)1