use of org.apache.jackrabbit.vault.util.DocViewProperty in project sling by apache.
the class ContentXmlHandler method startElement.
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
ResourceProxy current;
// name is equal to label except for SNS
String label = ISO9075.decode(qName);
String name = label;
// code mostly taken from {@link org.apache.jackrabbit.vault.fs.impl.io.DocViewSaxImporter}
DocViewNode node;
try {
node = new DocViewNode(name, label, attributes, npResolver);
if (qName.equals(JCR_ROOT)) {
current = root;
} else {
ResourceProxy parent = queue.peekLast();
StringBuilder path = new StringBuilder(parent.getPath());
if (path.charAt(path.length() - 1) != '/')
path.append('/');
path.append(qName);
current = new ResourceProxy(ISO9075.decode(path.toString()));
parent.addChild(current);
}
for (Map.Entry<String, DocViewProperty> entry : node.props.entrySet()) {
try {
Object typedValue = TypeHint.convertDocViewPropertyToTypedValue(entry.getValue());
// unsupported
if (typedValue == null) {
continue;
}
current.addProperty(entry.getKey(), typedValue);
} catch (Throwable t) {
Activator.getDefault().getPluginLogger().error("Could not parse property '" + entry.getValue().name, t);
}
}
queue.add(current);
} catch (NamespaceException e) {
Activator.getDefault().getPluginLogger().error("Could not resolve a JCR namespace.", e);
}
}
use of org.apache.jackrabbit.vault.util.DocViewProperty in project sling by apache.
the class JcrXmlValueConverter method parseValue.
/**
* Parse JSON value from XML Attribute.
* @param value XML attribute value
* @return Value object
*/
public static Object parseValue(final String name, final String value) {
if (value == null) {
return null;
}
DocViewProperty prop = DocViewProperty.parse(name, value);
// convert values
if (prop.isMulti) {
Class<?> arrayType = getType(prop.type);
if (arrayType == null) {
return null;
}
Object result = Array.newInstance(arrayType, prop.values.length);
for (int i = 0; i < prop.values.length; i++) {
Array.set(result, i, convertValue(prop.values[i], prop.type, true));
}
return result;
} else {
return convertValue(prop.values[0], prop.type, false);
}
}
Aggregations