Search in sources :

Example 26 with ResourceProxy

use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.

the class JcrNode method doGetProperty.

private Object doGetProperty(ResourceProxy resourceProxy, String propertyName) {
    if (resourceProxy.getPath().equals(getJcrPath())) {
        Map<String, Object> props = resourceProxy.getProperties();
        if (props.containsKey(propertyName)) {
            Object p0 = props.get(propertyName);
            return p0;
        }
    } else {
        List<ResourceProxy> resourceProxyChildren = resourceProxy.getChildren();
        for (Iterator<ResourceProxy> it = resourceProxyChildren.iterator(); it.hasNext(); ) {
            final ResourceProxy aChild = it.next();
            final Object p1 = doGetProperty(aChild, propertyName);
            if (p1 != null) {
                return p1;
            }
        }
    }
    return null;
}
Also used : ResourceProxy(org.apache.sling.ide.transport.ResourceProxy)

Example 27 with ResourceProxy

use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.

the class AddOrUpdateNodeCommand method update.

private void update(ResourceProxy resource, Session session) throws RepositoryException, IOException {
    String path = resource.getPath();
    boolean nodeExists = session.nodeExists(path);
    Node node;
    if (nodeExists) {
        node = session.getNode(path);
        getLogger().trace("Found existing node at {0} with primaryType {1}", path, node.getPrimaryNodeType().getName());
    } else {
        node = createNode(resource, session);
        getLogger().trace("Created node at {0} with primaryType {1}", path, node.getPrimaryNodeType().getName());
    }
    if (nodeExists && getFlags().contains(CommandExecutionFlag.CREATE_ONLY_WHEN_MISSING)) {
        return;
    }
    updateNode(node, resource);
    processDeletedNodes(node, resource);
    for (ResourceProxy child : resource.getCoveredChildren()) {
        update(child, session);
    }
}
Also used : Node(javax.jcr.Node) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy)

Example 28 with ResourceProxy

use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.

the class VltNodeTypeFactory method initDeclaredFields.

private void initDeclaredFields(VltNodeType nt) {
    final ResourceProxy child = nt.getResourceProxy();
    String[] superTypeNamess = (String[]) child.getProperties().get("jcr:supertypes");
    nt.setDeclaredSupertypeNames(superTypeNamess);
    if (superTypeNamess != null) {
        NodeType[] superTypes = new NodeType[superTypeNamess.length];
        for (int i = 0; i < superTypeNamess.length; i++) {
            superTypes[i] = getNodeType(superTypeNamess[i]);
        }
        nt.setDeclaredSupertypes(superTypes);
    }
    Set<VltNodeDefinition> nds = new HashSet<>();
    for (ResourceProxy ntChild : child.getChildren()) {
        String ntChildName = PathUtil.getName(ntChild.getPath());
        if (ntChildName.startsWith("jcr:childNodeDefinition")) {
            VltNodeDefinition nd = handleChildNodeDefinition(ntChild);
            nds.add(nd);
        } else if (ntChildName.startsWith("rep:residualChildNodeDefinitions")) {
            // go through children
            for (ResourceProxy residualChild : ntChild.getChildren()) {
                nds.add(handleChildNodeDefinition(residualChild));
            }
        }
    }
    nt.setDeclaredChildNodeDefinitions(nds.toArray(new NodeDefinition[0]));
    initDeclaredPropertyDefinitions(nt, child);
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) HashSet(java.util.HashSet)

Example 29 with ResourceProxy

use of org.apache.sling.ide.transport.ResourceProxy 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 30 with ResourceProxy

use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.

the class SimpleXmlSerializationManager method readSerializationData.

@Override
public ResourceProxy readSerializationData(String filePath, InputStream source) throws IOException {
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();
        SerializationDataHandler h = new SerializationDataHandler();
        saxParser.parse(new InputSource(source), h);
        return new ResourceProxy(filePath, h.getResult());
    } catch (ParserConfigurationException | SAXException e) {
        // TODO proper exception handling
        throw new RuntimeException(e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Aggregations

ResourceProxy (org.apache.sling.ide.transport.ResourceProxy)42 Test (org.junit.Test)14 Node (javax.jcr.Node)8 NodeIterator (javax.jcr.NodeIterator)5 IPath (org.eclipse.core.runtime.IPath)5 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 FilterResult (org.apache.sling.ide.filter.FilterResult)4 IFile (org.eclipse.core.resources.IFile)4 IFolder (org.eclipse.core.resources.IFolder)4 Filter (org.apache.sling.ide.filter.Filter)3 RepositoryException (org.apache.sling.ide.transport.RepositoryException)3 JsonReader (com.google.gson.stream.JsonReader)2 JsonToken (com.google.gson.stream.JsonToken)2 File (java.io.File)2 InputStreamReader (java.io.InputStreamReader)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2