Search in sources :

Example 1 with DocViewNode

use of org.apache.jackrabbit.vault.util.DocViewNode 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)

Aggregations

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