Search in sources :

Example 16 with PathNotFoundException

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

the class NodeImpl method resolveRelativeNodePath.

/**
     * Returns the <code>NodeEntry</code> at <code>relPath</code> or
     * <code>null</code> if no node exists at <code>relPath</code>.
     * <p>
     * Note that access rights are not checked.
     *
     * @param relPath relative path of a (possible) node.
     * @return the HierarchyEntry of the node at <code>relPath</code> or
     * <code>null</code> if no node exists at <code>relPath</code>.
     * @throws RepositoryException if <code>relPath</code> is not a valid
     * relative path.
     */
private NodeEntry resolveRelativeNodePath(String relPath) throws RepositoryException {
    NodeEntry targetEntry = null;
    try {
        Path rp = session.getPathResolver().getQPath(relPath);
        // shortcut
        if (rp.getLength() == 1) {
            if (rp.denotesCurrent()) {
                targetEntry = getNodeEntry();
            } else if (rp.denotesParent()) {
                targetEntry = getNodeEntry().getParent();
            } else {
                // try to get child entry + force loading of not known yet
                targetEntry = getNodeEntry().getNodeEntry(rp.getName(), rp.getNormalizedIndex(), true);
            }
        } else {
            // rp length > 1
            Path p = getPath(rp);
            targetEntry = session.getHierarchyManager().getNodeEntry(p.getCanonicalPath());
        }
    } catch (PathNotFoundException e) {
    // item does not exist -> ignore and return null
    } catch (NameException e) {
        String msg = "Invalid relative path: " + relPath;
        log.debug(msg);
        throw new RepositoryException(msg, e);
    }
    return targetEntry;
}
Also used : Path(org.apache.jackrabbit.spi.Path) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 17 with PathNotFoundException

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

the class RepositoryServiceImpl method internalGetPrivilegeDefinitions.

private PrivilegeDefinition[] internalGetPrivilegeDefinitions(SessionInfo sessionInfo, String uri) throws RepositoryException {
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(SecurityConstants.SUPPORTED_PRIVILEGE_SET);
    HttpPropfind request = null;
    try {
        request = new HttpPropfind(uri, nameSet, DEPTH_0);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (mresponses.length < 1) {
            throw new PathNotFoundException("Unable to retrieve privileges definitions.");
        }
        DavPropertyName displayName = SecurityConstants.SUPPORTED_PRIVILEGE_SET;
        DavProperty<?> p = mresponses[0].getProperties(DavServletResponse.SC_OK).get(displayName);
        if (p == null) {
            return new PrivilegeDefinition[0];
        } else {
            // build PrivilegeDefinition(s) from the supported-privileges dav property
            Map<Name, SupportedPrivilege> spMap = new HashMap<Name, SupportedPrivilege>();
            fillSupportedPrivilegeMap(new SupportedPrivilegeSetProperty(p).getValue(), spMap, getNameFactory());
            List<PrivilegeDefinition> pDefs = new ArrayList<PrivilegeDefinition>();
            for (Name privilegeName : spMap.keySet()) {
                SupportedPrivilege sp = spMap.get(privilegeName);
                Set<Name> aggrnames = null;
                SupportedPrivilege[] aggregates = sp.getSupportedPrivileges();
                if (aggregates != null && aggregates.length > 0) {
                    aggrnames = new HashSet<Name>();
                    for (SupportedPrivilege aggregate : aggregates) {
                        Name aggregateName = nameFactory.create(aggregate.getPrivilege().getNamespace().getURI(), aggregate.getPrivilege().getName());
                        aggrnames.add(aggregateName);
                    }
                }
                PrivilegeDefinition def = new PrivilegeDefinitionImpl(privilegeName, sp.isAbstract(), aggrnames);
                pDefs.add(def);
            }
            return pDefs.toArray(new PrivilegeDefinition[pDefs.size()]);
        }
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) PrivilegeDefinition(org.apache.jackrabbit.spi.PrivilegeDefinition) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) Name(org.apache.jackrabbit.spi.Name) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) PrivilegeDefinitionImpl(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) SupportedPrivilegeSetProperty(org.apache.jackrabbit.webdav.security.SupportedPrivilegeSetProperty) PathNotFoundException(javax.jcr.PathNotFoundException) SupportedPrivilege(org.apache.jackrabbit.webdav.security.SupportedPrivilege)

Example 18 with PathNotFoundException

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

the class ExceptionConverter method generate.

public static RepositoryException generate(DavException davExc, int methodCode, String name) {
    String msg = davExc.getMessage();
    if (davExc.hasErrorCondition()) {
        try {
            Element error = davExc.toXml(DomUtil.createDocument());
            if (DomUtil.matches(error, DavException.XML_ERROR, DavConstants.NAMESPACE)) {
                if (DomUtil.hasChildElement(error, "exception", null)) {
                    Element exc = DomUtil.getChildElement(error, "exception", null);
                    if (DomUtil.hasChildElement(exc, "message", null)) {
                        msg = DomUtil.getChildText(exc, "message", null);
                    }
                    if (DomUtil.hasChildElement(exc, "class", null)) {
                        Class<?> cl = Class.forName(DomUtil.getChildText(exc, "class", null));
                        Constructor<?> excConstr = cl.getConstructor(String.class);
                        if (excConstr != null) {
                            Object o = excConstr.newInstance(msg);
                            if (o instanceof PathNotFoundException && methodCode == DavMethods.DAV_POST) {
                                // see JCR-2536
                                return new InvalidItemStateException(msg);
                            } else if (o instanceof RepositoryException) {
                                return (RepositoryException) o;
                            } else if (o instanceof Exception) {
                                return new RepositoryException(msg, (Exception) o);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            return new RepositoryException(e);
        }
    }
    // make sure an exception is generated
    switch(davExc.getErrorCode()) {
        // TODO: mapping DAV_error to jcr-exception is ambiguous. to be improved
        case DavServletResponse.SC_NOT_FOUND:
            switch(methodCode) {
                case DavMethods.DAV_DELETE:
                case DavMethods.DAV_MKCOL:
                case DavMethods.DAV_PUT:
                case DavMethods.DAV_POST:
                    // been made.
                    return new InvalidItemStateException(msg, davExc);
                default:
                    return new ItemNotFoundException(msg, davExc);
            }
        case DavServletResponse.SC_LOCKED:
            return new LockException(msg, davExc);
        case DavServletResponse.SC_METHOD_NOT_ALLOWED:
            return new ConstraintViolationException(msg, davExc);
        case DavServletResponse.SC_CONFLICT:
            return new InvalidItemStateException(msg, davExc);
        case DavServletResponse.SC_PRECONDITION_FAILED:
            return new LockException(msg, davExc);
        case DavServletResponse.SC_NOT_IMPLEMENTED:
            if (methodCode > 0 && name != null) {
                return new UnsupportedRepositoryOperationException("Missing implementation: Method " + name + " could not be executed", davExc);
            } else {
                return new UnsupportedRepositoryOperationException("Missing implementation", davExc);
            }
        default:
            return new RepositoryException(msg, davExc);
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) InvalidItemStateException(javax.jcr.InvalidItemStateException) Element(org.w3c.dom.Element) RepositoryException(javax.jcr.RepositoryException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) ItemNotFoundException(javax.jcr.ItemNotFoundException) PathNotFoundException(javax.jcr.PathNotFoundException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) DavException(org.apache.jackrabbit.webdav.DavException) RepositoryException(javax.jcr.RepositoryException) LockException(javax.jcr.lock.LockException) InvalidItemStateException(javax.jcr.InvalidItemStateException) LockException(javax.jcr.lock.LockException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) PathNotFoundException(javax.jcr.PathNotFoundException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 19 with PathNotFoundException

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

the class AccessControlManagerImplTest method testRemovePolicyPropertyPath.

@Test
public void testRemovePolicyPropertyPath() throws Exception {
    try {
        String path = "/jcr:primaryType";
        AccessControlPolicy acl = createPolicy(path);
        acMgr.removePolicy(path, acl);
        fail("Removing access control policy at property path should fail");
    } catch (PathNotFoundException e) {
    // success
    }
}
Also used : JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) PathNotFoundException(javax.jcr.PathNotFoundException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 20 with PathNotFoundException

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

the class ItemManager method getNode.

/**
     * @param path
     * @return
     * @throws PathNotFoundException
     * @throws AccessDeniedException
     * @throws RepositoryException
     */
public NodeImpl getNode(Path path) throws PathNotFoundException, AccessDeniedException, RepositoryException {
    NodeId id = hierMgr.resolveNodePath(path);
    if (id == null) {
        throw new PathNotFoundException(safeGetJCRPath(path));
    }
    NodeId parentId = null;
    if (!path.denotesRoot()) {
        parentId = hierMgr.resolveNodePath(path.getAncestor(1));
    }
    try {
        if (parentId == null) {
            return (NodeImpl) getItem(id, path, true);
        }
        // parent
        return getNode(id, parentId);
    } catch (ItemNotFoundException infe) {
        throw new PathNotFoundException(safeGetJCRPath(path));
    }
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) PathNotFoundException(javax.jcr.PathNotFoundException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

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