Search in sources :

Example 1 with DocViewProperty

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);
    }
}
Also used : DocViewNode(org.apache.jackrabbit.vault.util.DocViewNode) DocViewProperty(org.apache.jackrabbit.vault.util.DocViewProperty) NamespaceException(javax.jcr.NamespaceException) HashMap(java.util.HashMap) Map(java.util.Map) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy)

Example 2 with DocViewProperty

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);
    }
}
Also used : DocViewProperty(org.apache.jackrabbit.vault.util.DocViewProperty)

Aggregations

DocViewProperty (org.apache.jackrabbit.vault.util.DocViewProperty)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NamespaceException (javax.jcr.NamespaceException)1 DocViewNode (org.apache.jackrabbit.vault.util.DocViewNode)1 ResourceProxy (org.apache.sling.ide.transport.ResourceProxy)1