Search in sources :

Example 36 with ItemNotFoundException

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

the class RepositoryServiceImpl method getValues.

private QValue[] getValues(InputStream response, NamePathResolver resolver, ItemId id) throws RepositoryException {
    try {
        Document doc = DomUtil.parseDocument(response);
        Element prop = DomUtil.getChildElement(doc, JcrRemotingConstants.JCR_VALUES_LN, ItemResourceConstants.NAMESPACE);
        if (prop == null) {
            // not representation of a jcr-property
            throw new ItemNotFoundException("No property found at " + saveGetIdString(id, resolver));
        } else {
            DavProperty<?> p = DefaultDavProperty.createFromXml(prop);
            Value[] jcrVs = ValueUtil.valuesFromXml(p.getValue(), PropertyType.STRING, valueFactory);
            QValue[] qvs = new QValue[jcrVs.length];
            int type = (jcrVs.length > 0) ? jcrVs[0].getType() : PropertyType.STRING;
            for (int i = 0; i < jcrVs.length; i++) {
                if (jcrVs[i] instanceof QValueValue) {
                    qvs[i] = ((QValueValue) jcrVs[i]).getQValue();
                } else if (type == PropertyType.BINARY) {
                    qvs[i] = qValueFactory.create(jcrVs[i].getStream());
                } else {
                    qvs[i] = ValueFormat.getQValue(jcrVs[i], resolver, qValueFactory);
                }
            }
            return qvs;
        }
    } catch (SAXException e) {
        log.warn("Internal error: {}", e.getMessage());
        throw new RepositoryException(e);
    } catch (IOException e) {
        log.warn("Internal error: {}", e.getMessage());
        throw new RepositoryException(e);
    } catch (ParserConfigurationException e) {
        log.warn("Internal error: {}", e.getMessage());
        throw new RepositoryException(e);
    }
}
Also used : QValueValue(org.apache.jackrabbit.spi.commons.value.QValueValue) QValue(org.apache.jackrabbit.spi.QValue) Element(org.w3c.dom.Element) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) QValueValue(org.apache.jackrabbit.spi.commons.value.QValueValue) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 37 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException 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)

Example 38 with ItemNotFoundException

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

the class HierarchyManagerImpl method isShareAncestor.

/**
     * {@inheritDoc}
     */
public boolean isShareAncestor(NodeId ancestor, NodeId descendant) throws ItemNotFoundException, RepositoryException {
    if (ancestor.equals(descendant)) {
        // can't be ancestor of self
        return false;
    }
    try {
        ItemState state = getItemState(descendant);
        Set<NodeId> parentIds = getParentIds(state, false);
        while (parentIds.size() > 0) {
            if (parentIds.contains(ancestor)) {
                return true;
            }
            Set<NodeId> grandparentIds = new LinkedHashSet<NodeId>();
            for (NodeId parentId : parentIds) {
                grandparentIds.addAll(getParentIds(getItemState(parentId), false));
            }
            parentIds = grandparentIds;
        }
        // not an ancestor
        return false;
    } catch (NoSuchItemStateException nsise) {
        String msg = "failed to determine degree of relationship of " + ancestor + " and " + descendant;
        log.debug(msg);
        throw new ItemNotFoundException(msg, nsise);
    } catch (ItemStateException ise) {
        String msg = "failed to determine degree of relationship of " + ancestor + " and " + descendant;
        log.debug(msg);
        throw new RepositoryException(msg, ise);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemState(org.apache.jackrabbit.core.state.ItemState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 39 with ItemNotFoundException

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

the class HierarchyManagerImpl method getDepth.

/**
     * {@inheritDoc}
     */
public int getDepth(ItemId id) throws ItemNotFoundException, RepositoryException {
    // shortcut
    if (id.equals(rootNodeId)) {
        return 0;
    }
    try {
        ItemState state = getItemState(id);
        NodeId parentId = getParentId(state);
        int depth = 0;
        while (parentId != null) {
            depth++;
            state = getItemState(parentId);
            parentId = getParentId(state);
        }
        return depth;
    } catch (NoSuchItemStateException nsise) {
        String msg = "failed to determine depth of " + id;
        log.debug(msg);
        throw new ItemNotFoundException(msg, nsise);
    } catch (ItemStateException ise) {
        String msg = "failed to determine depth of " + id;
        log.debug(msg);
        throw new RepositoryException(msg, ise);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemState(org.apache.jackrabbit.core.state.ItemState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 40 with ItemNotFoundException

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

the class HierarchyManagerImpl method getRelativeDepth.

/**
     * {@inheritDoc}
     */
public int getRelativeDepth(NodeId ancestorId, ItemId descendantId) throws ItemNotFoundException, RepositoryException {
    if (ancestorId.equals(descendantId)) {
        return 0;
    }
    int depth = 1;
    try {
        ItemState state = getItemState(descendantId);
        NodeId parentId = getParentId(state);
        while (parentId != null) {
            if (parentId.equals(ancestorId)) {
                return depth;
            }
            depth++;
            state = getItemState(parentId);
            parentId = getParentId(state);
        }
        // not an ancestor
        return -1;
    } catch (NoSuchItemStateException nsise) {
        String msg = "failed to determine depth of " + descendantId + " relative to " + ancestorId;
        log.debug(msg);
        throw new ItemNotFoundException(msg, nsise);
    } catch (ItemStateException ise) {
        String msg = "failed to determine depth of " + descendantId + " relative to " + ancestorId;
        log.debug(msg);
        throw new RepositoryException(msg, ise);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemState(org.apache.jackrabbit.core.state.ItemState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Aggregations

ItemNotFoundException (javax.jcr.ItemNotFoundException)139 RepositoryException (javax.jcr.RepositoryException)61 Node (javax.jcr.Node)44 Path (org.apache.jackrabbit.spi.Path)25 PathNotFoundException (javax.jcr.PathNotFoundException)23 NodeId (org.apache.jackrabbit.core.id.NodeId)22 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)16 IOException (java.io.IOException)14 InvalidItemStateException (javax.jcr.InvalidItemStateException)14 NodeState (org.apache.jackrabbit.core.state.NodeState)14 Name (org.apache.jackrabbit.spi.Name)14 AccessDeniedException (javax.jcr.AccessDeniedException)13 HttpResponse (org.apache.http.HttpResponse)13 DavException (org.apache.jackrabbit.webdav.DavException)13 ItemExistsException (javax.jcr.ItemExistsException)12 Session (javax.jcr.Session)12 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)12 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)11 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)10 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)10