Hi,
Christophe Lombart schrieb:
> For the Sling explorer app, I would like to get the maximum of information
> on the resource properties. I'm using the following code in my esp script
> :
>
> var valueMap = resource.adaptTo(Packages.java.util.Map);
You might want to do:
var valueMap =
Packages.org.apache.sling.api.resource.ResourceUtil.getValueMap(resource);
This gives you a ValueMap
> var propertyIterator = valueMap.keySet().iterator();
> After that, I can loop on the propertyIterator to get all properties. That
> works fine but I have 3 questions :
>
try
var prop = valueMap.get("theName", Packages.javax.jcr.Property);
if (prop != null) {
....
}
> 1. Is it possible to get the type of a property ?
var type = prop.getType();
> 2. how can I check if the property is a single or multi value prop ?
var isMulti = prop.getDefinition().isMultiple();
> 3. If it is a multi value prop, how can I get the values ?
var vals = prop.getValues();
Or better yet, the ValueMap offers you transparent conversion as in :
var stringVals = valueMap.get("theName", java.lang.String[]);
This gives you either null or a String[] regardless of whether the
property is really multi-val or not and what the actual property type is.
HTH
Regards
Felix
>
>
> br,
> Christophe
>