Search in sources :

Example 21 with PathNotFoundException

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

the class ResourceFactoryImpl method getNode.

/**
     * Returns the <code>Node</code> corresponding to the given locator or
     * <code>null</code> if it does not exist or if the existing item represents
     * a <code>Property</code>.
     *
     * @param sessionImpl
     * @param locator
     * @return
     * @throws RepositoryException
     */
private Node getNode(DavSession sessionImpl, DavResourceLocator locator) throws RepositoryException {
    Node node = null;
    try {
        String repoPath = locator.getRepositoryPath();
        if (repoPath != null) {
            Session session = ((JcrDavSession) sessionImpl).getRepositorySession();
            Item item = session.getItem(repoPath);
            if (item instanceof Node) {
                node = (Node) item;
            }
        // else: item is a property -> return null
        }
    } catch (PathNotFoundException e) {
    // item does not exist (yet). return null -> create null-resource
    }
    return node;
}
Also used : Item(javax.jcr.Item) Node(javax.jcr.Node) JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) PathNotFoundException(javax.jcr.PathNotFoundException) JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) Session(javax.jcr.Session) DavSession(org.apache.jackrabbit.webdav.DavSession)

Example 22 with PathNotFoundException

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

the class LocateCorrespondingNodeReport method getCorrespondingResourceHref.

/**
     * Retrieve the href of the corresponding resource in the indicated workspace.
     *
     * @param resource
     * @param session Session object used to access the {@link Node} object
     * represented by the given resource.
     * @param workspaceHref
     * @return
     * @throws RepositoryException
     */
private static String getCorrespondingResourceHref(DavResource resource, Session session, String workspaceHref) throws RepositoryException {
    DavResourceLocator rLoc = resource.getLocator();
    String itemPath = rLoc.getRepositoryPath();
    Item item = session.getItem(itemPath);
    if (item.isNode()) {
        String workspaceName = rLoc.getFactory().createResourceLocator(rLoc.getPrefix(), workspaceHref).getWorkspaceName();
        String corrPath = ((Node) item).getCorrespondingNodePath(workspaceName);
        DavResourceLocator corrLoc = rLoc.getFactory().createResourceLocator(rLoc.getPrefix(), "/" + workspaceName, corrPath, false);
        return corrLoc.getHref(true);
    } else {
        throw new PathNotFoundException("Node with path " + itemPath + " does not exist.");
    }
}
Also used : Item(javax.jcr.Item) Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 23 with PathNotFoundException

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

the class ItemImpl method getAncestor.

/**
     * @see javax.jcr.Item#getAncestor(int)
     */
public Item getAncestor(int depth) throws ItemNotFoundException, AccessDeniedException, RepositoryException {
    checkStatus();
    if (depth == 0) {
        return session.getRootNode();
    }
    String msg = "No ancestor at depth = " + depth;
    try {
        // Path.getAncestor requires relative degree, i.e. we need
        // to convert absolute to relative ancestor degree
        Path path = getQPath();
        int relDegree = path.getAncestorCount() - depth;
        if (relDegree < 0) {
            throw new ItemNotFoundException(msg);
        }
        Path ancestorPath = path.getAncestor(relDegree);
        if (relDegree == 0) {
            return this;
        } else {
            return getItemManager().getNode(ancestorPath);
        }
    } catch (PathNotFoundException e) {
        throw new ItemNotFoundException(msg);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) PathNotFoundException(javax.jcr.PathNotFoundException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 24 with PathNotFoundException

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

the class ACLEditor method setPolicy.

/**
     * @see AccessControlEditor#setPolicy(String,AccessControlPolicy)
     */
public void setPolicy(String nodePath, AccessControlPolicy policy) throws AccessControlException, PathNotFoundException, RepositoryException {
    checkProtectsNode(nodePath);
    checkValidPolicy(nodePath, policy);
    ACLTemplate acl = (ACLTemplate) policy;
    NodeImpl acNode = getAcNode(nodePath);
    if (acNode == null) {
        throw new PathNotFoundException("No such node " + nodePath);
    }
    // write the entries to the node
    NodeImpl aclNode;
    if (acNode.hasNode(N_POLICY)) {
        aclNode = acNode.getNode(N_POLICY);
        // remove all existing aces
        for (NodeIterator aceNodes = aclNode.getNodes(); aceNodes.hasNext(); ) {
            NodeImpl aceNode = (NodeImpl) aceNodes.nextNode();
            removeItem(aceNode);
        }
    } else {
        /* doesn't exist yet -> create */
        aclNode = addNode(acNode, N_POLICY, NT_REP_ACL);
    }
    /* add all new entries defined on the template */
    AccessControlEntry[] aces = acl.getAccessControlEntries();
    for (AccessControlEntry ace1 : aces) {
        AccessControlEntryImpl ace = (AccessControlEntryImpl) ace1;
        // create the ACE node
        Name nodeName = getUniqueNodeName(aclNode, "entry");
        Name ntName = (ace.isAllow()) ? NT_REP_GRANT_ACE : NT_REP_DENY_ACE;
        NodeImpl aceNode = addNode(aclNode, nodeName, ntName);
        ValueFactory vf = session.getValueFactory();
        // write the rep:principalName property
        setProperty(aceNode, P_PRINCIPAL_NAME, vf.createValue(ace.getPrincipal().getName()));
        // ... and the rep:privileges property
        Privilege[] privs = ace.getPrivileges();
        Value[] vs = new Value[privs.length];
        for (int j = 0; j < privs.length; j++) {
            vs[j] = vf.createValue(privs[j].getName(), PropertyType.NAME);
        }
        setProperty(aceNode, P_PRIVILEGES, vs);
        // store the restrictions:
        Set<Name> restrNames = ace.getRestrictions().keySet();
        for (Name restrName : restrNames) {
            Value value = ace.getRestriction(restrName);
            setProperty(aceNode, restrName, value);
        }
    }
    // mark the parent modified.
    markModified((NodeImpl) aclNode.getParent());
}
Also used : NodeIterator(javax.jcr.NodeIterator) AccessControlEntryImpl(org.apache.jackrabbit.core.security.authorization.AccessControlEntryImpl) NodeImpl(org.apache.jackrabbit.core.NodeImpl) AccessControlEntry(javax.jcr.security.AccessControlEntry) ValueFactory(javax.jcr.ValueFactory) Name(org.apache.jackrabbit.spi.Name) Value(javax.jcr.Value) PathNotFoundException(javax.jcr.PathNotFoundException) Privilege(javax.jcr.security.Privilege)

Example 25 with PathNotFoundException

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

the class TraversingNodeResolver method findNodes.

/**
     * @inheritDoc
     */
@Override
public NodeIterator findNodes(Set<Name> propertyNames, String value, Name ntName, boolean exact, long maxSize) throws RepositoryException {
    String sr = getSearchRoot(ntName);
    if (getSession().nodeExists(sr)) {
        try {
            Node root = getSession().getNode(sr);
            Set<Node> matchSet = new HashSet<Node>();
            collectNodes(value, propertyNames, ntName, root.getNodes(), matchSet, exact, maxSize);
            return new NodeIteratorAdapter(matchSet);
        } catch (PathNotFoundException e) {
            // should not get here
            log.warn("Error while retrieving node " + sr);
        }
    }
    // else: searchRoot does not exist yet -> omit the search
    return NodeIteratorAdapter.EMPTY;
}
Also used : Node(javax.jcr.Node) NodeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter) PathNotFoundException(javax.jcr.PathNotFoundException) HashSet(java.util.HashSet)

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