Search in sources :

Example 76 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit by apache.

the class WorkspaceImporterTest method testReferenceImport.

/**
     * Tests that an XML document with an internal reference is correctly
     * imported. This functionality got broken by JCR-569.
     *
     * @throws Exception if an unexpected error occurs
     */
public void testReferenceImport() throws Exception {
    try {
        NodeId id = NodeId.randomId();
        String xml = "<sv:node sv:name=\"a\"" + " xmlns:jcr=\"http://www.jcp.org/jcr/1.0\"" + " xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\"" + " xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\">" + "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">" + "<sv:value>nt:unstructured</sv:value></sv:property>" + "<sv:node sv:name=\"b\">" + "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">" + "<sv:value>nt:unstructured</sv:value></sv:property>" + "<sv:property sv:name=\"jcr:mixinTypes\" sv:type=\"Name\">" + "<sv:value>mix:referenceable</sv:value></sv:property>" + "<sv:property sv:name=\"jcr:uuid\" sv:type=\"String\">" + "<sv:value>" + id + "</sv:value></sv:property>" + "</sv:node>" + "<sv:node sv:name=\"c\">" + "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">" + "<sv:value>nt:unstructured</sv:value></sv:property>" + "<sv:property sv:name=\"ref\" sv:type=\"Reference\">" + "<sv:value>" + id + "</sv:value></sv:property>" + "</sv:node>" + "</sv:node>";
        superuser.getWorkspace().importXML(root.getPath(), new ByteArrayInputStream(xml.getBytes("UTF-8")), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
        Node b = root.getNode("a/b");
        Node c = root.getNode("a/c");
        assertTrue("Imported reference points to the correct node", b.isSame(c.getProperty("ref").getNode()));
    } catch (PathNotFoundException e) {
        fail("Imported node or property not found");
    } catch (RepositoryException e) {
        fail("Failed to import an XML document with an internal reference");
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Node(javax.jcr.Node) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 77 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit by apache.

the class ItemSequence method getPredecessor.

/**
     * Returns the direct predecessor of <code>key</code> amongst
     * <code>node</code>'s child nodes wrt. to {@link TreeManager#getOrder()}.
     * Returns <code>null</code> if either <code>node</code> has no child nodes
     * or <code>node</code> is a leaf (see {@link TreeManager#isLeaf(Node)}) or
     * <code>key</code> is smaller than all the keys of all child nodes of
     * <code>node</code>.
     */
protected final Node getPredecessor(Node node, String key) throws RepositoryException {
    if (!node.hasNodes() || treeManager.isLeaf(node)) {
        return null;
    }
    // Shortcut for exact match
    try {
        return node.getNode(key);
    } catch (PathNotFoundException ignore) {
    }
    // Search for direct predecessor of key in the nodes children
    // todo performance: for ordered nodes use binary search
    NodeIterator childNodes = node.getNodes();
    Node p = null;
    while (childNodes.hasNext()) {
        Node n = childNodes.nextNode();
        String childKey = n.getName();
        if (order.compare(key, childKey) > 0 && (p == null || order.compare(childKey, p.getName()) > 0)) {
            p = n;
        }
    }
    return p;
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 78 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit by apache.

the class ItemSequence method getSuccessor.

/**
     * Returns the successor node for the given
     * <code>key</code>. That is the node
     * whose key directly succeeds the passed <code>key</code> in the order
     * determined by {@link TreeManager#getOrder()}. There are two cases:
     * <ul>
     * <li>A node with the given <code>key</code> is mapped: then that node is
     * returned.</li>
     * <li>A node with the given <code>key</code> is not mapped: the the node
     * where that would contain that key if present is returned.</li>
     * </ul>
     */
protected final Node getSuccessor(Node node, String key) throws RepositoryException {
    if (!node.hasNodes() || treeManager.isLeaf(node)) {
        return null;
    }
    // Shortcut for exact match
    try {
        return node.getNode(key);
    } catch (PathNotFoundException ignore) {
    }
    // Search for direct successor of key in the nodes children
    // todo performance: for ordered nodes use binary search
    NodeIterator childNodes = node.getNodes();
    Node s = null;
    while (childNodes.hasNext()) {
        Node n = childNodes.nextNode();
        String childKey = n.getName();
        if (order.compare(key, childKey) < 0 && (s == null || order.compare(childKey, s.getName()) < 0)) {
            s = n;
        }
    }
    return s;
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 79 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit by apache.

the class AbstractNode method getMixinNodeTypes.

//----------------------------------------------------------------< Node >
/**
     * Returns the declared mixin node types of this node.
     * <p>
     * The default implementation uses the values of the
     * <code>jcr:mixinTypes</code> property to look up the mixin node types
     * from the {@link NodeTypeManager} of the current workspace.
     *
     * @return mixin node types
     * @throws RepositoryException if an error occurs
     */
public NodeType[] getMixinNodeTypes() throws RepositoryException {
    try {
        NodeTypeManager manager = getSession().getWorkspace().getNodeTypeManager();
        Property property = getProperty(getName("jcr:mixinTypes"));
        Value[] values = property.getValues();
        NodeType[] types = new NodeType[values.length];
        for (int i = 0; i < values.length; i++) {
            types[i] = manager.getNodeType(values[i].getString());
        }
        return types;
    } catch (PathNotFoundException e) {
        // jcr:mixinTypes does not exist, i.e. no mixin types on this node
        return new NodeType[0];
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeType(javax.jcr.nodetype.NodeType) Value(javax.jcr.Value) PathNotFoundException(javax.jcr.PathNotFoundException) Property(javax.jcr.Property)

Example 80 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit by apache.

the class AbstractNode method getProperty.

/**
     * Returns the property at the given relative path from this node.
     * <p>
     * The default implementation looks up the parent node of the given
     * relative path and iterates through the properties of that node to
     * find and return the identified property.
     *
     * @param relPath relative path of the property
     * @return property
     * @throws PathNotFoundException if the property is not found
     * @throws RepositoryException if an error occurs
     */
public Property getProperty(String relPath) throws PathNotFoundException, RepositoryException {
    // Corner case, remove any "/." self references at the end of the path
    while (relPath.endsWith("/.")) {
        relPath = relPath.substring(0, relPath.length() - 2);
    }
    // Find the parent node of the identified property
    Node node = this;
    int slash = relPath.lastIndexOf('/');
    if (slash == 0) {
        node = getSession().getRootNode();
        relPath = relPath.substring(1);
    } else if (slash > 0) {
        node = getNode(relPath.substring(0, slash));
        relPath = relPath.substring(slash + 1);
    }
    // Look for the named property. Must iterate and re-check for the name
    // since the client could have used an invalid path like "./a|b".
    PropertyIterator properties = node.getProperties(relPath);
    while (properties.hasNext()) {
        Property property = (Property) properties.next();
        if (relPath.equals(property.getName())) {
            return property;
        }
    }
    throw new PathNotFoundException("Property not found: " + relPath);
}
Also used : Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) PathNotFoundException(javax.jcr.PathNotFoundException) Property(javax.jcr.Property)

Aggregations

PathNotFoundException (javax.jcr.PathNotFoundException)136 Node (javax.jcr.Node)58 RepositoryException (javax.jcr.RepositoryException)46 ItemNotFoundException (javax.jcr.ItemNotFoundException)24 Session (javax.jcr.Session)23 Path (org.apache.jackrabbit.spi.Path)22 AccessDeniedException (javax.jcr.AccessDeniedException)14 Property (javax.jcr.Property)14 Test (org.junit.Test)14 Item (javax.jcr.Item)11 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)10 NodeIterator (javax.jcr.NodeIterator)9 Value (javax.jcr.Value)9 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)9 Name (org.apache.jackrabbit.spi.Name)8 PropertyIterator (javax.jcr.PropertyIterator)7 NodeDelegate (org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate)7 HashSet (java.util.HashSet)6 ItemExistsException (javax.jcr.ItemExistsException)6 ValueFormatException (javax.jcr.ValueFormatException)6