Search in sources :

Example 26 with ItemNotFoundException

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

the class NodeImpl method getNode.

/**
     * @see Node#getNode(String)
     */
public Node getNode(String relPath) throws PathNotFoundException, RepositoryException {
    checkStatus();
    NodeEntry nodeEntry = resolveRelativeNodePath(relPath);
    if (nodeEntry == null) {
        throw new PathNotFoundException(relPath);
    }
    try {
        return (Node) getItemManager().getItem(nodeEntry);
    } catch (ItemNotFoundException e) {
        throw new PathNotFoundException(relPath, e);
    }
}
Also used : NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) AddNode(org.apache.jackrabbit.jcr2spi.operation.AddNode) Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 27 with ItemNotFoundException

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

the class HierarchyEntryImpl method reload.

/**
     * {@inheritDoc}
     * @see HierarchyEntry#reload(boolean)
     */
public void reload(boolean recursive) {
    int status = getStatus();
    if (status == Status._UNDEFINED_) {
        // unresolved: entry will be loaded and validated upon resolution.
        return;
    }
    if (Status.isTransient(status) || Status.isStale(status) || Status.isTerminal(status)) {
        // transient || stale: avoid reloading
        // new || terminal: cannot be reloaded from persistent layer anyway.
        log.debug("Skip reload for item with status " + Status.getName(status) + ".");
        return;
    }
    /**
         * Retrieved a fresh ItemState from the persistent layer. Which will
         * then be merged into the current state.
         */
    try {
        ItemStateFactory isf = getItemStateFactory();
        if (denotesNode()) {
            NodeEntry ne = (NodeEntry) this;
            isf.createNodeState(ne.getWorkspaceId(), ne);
        } else {
            PropertyEntry pe = (PropertyEntry) this;
            isf.createPropertyState(pe.getWorkspaceId(), pe);
        }
    } catch (ItemNotFoundException e) {
        // remove hierarchyEntry including all children
        log.debug("Item '" + getName() + "' cannot be found on the persistent layer -> remove.");
        remove();
    } catch (RepositoryException e) {
        // TODO: rather throw?
        log.error("Exception while reloading item: " + e);
    }
}
Also used : TransientItemStateFactory(org.apache.jackrabbit.jcr2spi.state.TransientItemStateFactory) ItemStateFactory(org.apache.jackrabbit.jcr2spi.state.ItemStateFactory) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 28 with ItemNotFoundException

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

the class PropertyImpl method getNode.

/**
     * @see Property#getNode()
     */
public Node getNode() throws ValueFormatException, RepositoryException {
    Value value = getValue();
    switch(value.getType()) {
        case PropertyType.REFERENCE:
        case PropertyType.WEAKREFERENCE:
            return session.getNodeByIdentifier(value.getString());
        case PropertyType.PATH:
        case PropertyType.NAME:
            String path = value.getString();
            Path p = session.getPathResolver().getQPath(path);
            try {
                return (p.isAbsolute()) ? session.getNode(path) : getParent().getNode(path);
            } catch (PathNotFoundException e) {
                throw new ItemNotFoundException(path);
            }
        case PropertyType.STRING:
            try {
                Value refValue = ValueHelper.convert(value, PropertyType.REFERENCE, session.getValueFactory());
                return session.getNodeByIdentifier(refValue.getString());
            } catch (ItemNotFoundException e) {
                throw e;
            } catch (RepositoryException e) {
                // try if STRING value can be interpreted as PATH value
                Value pathValue = ValueHelper.convert(value, PropertyType.PATH, session.getValueFactory());
                p = session.getPathResolver().getQPath(pathValue.getString());
                try {
                    return (p.isAbsolute()) ? session.getNode(pathValue.getString()) : getParent().getNode(pathValue.getString());
                } catch (PathNotFoundException e1) {
                    throw new ItemNotFoundException(pathValue.getString());
                }
            }
        default:
            throw new ValueFormatException("Property value cannot be converted to a PATH, REFERENCE or WEAKREFERENCE");
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) SetPropertyValue(org.apache.jackrabbit.jcr2spi.operation.SetPropertyValue) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 29 with ItemNotFoundException

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

the class NodeImpl method getCorrespondingNodePath.

/**
     * @see Node#getCorrespondingNodePath(String)
     */
public String getCorrespondingNodePath(String workspaceName) throws ItemNotFoundException, NoSuchWorkspaceException, AccessDeniedException, RepositoryException {
    checkStatus();
    SessionImpl srcSession = null;
    try {
        // create session on other workspace for current subject
        // (may throw NoSuchWorkspaceException and AccessDeniedException)
        srcSession = session.switchWorkspace(workspaceName);
        // search nearest ancestor that is referenceable
        NodeImpl referenceableNode = this;
        while (referenceableNode.getDepth() != Path.ROOT_DEPTH && !referenceableNode.isNodeType(NameConstants.MIX_REFERENCEABLE)) {
            referenceableNode = (NodeImpl) referenceableNode.getParent();
        }
        // if root is common ancestor, corresponding path is same as ours
        // otherwise access referenceable ancestor and calculate correspond. path.
        String correspondingPath;
        if (referenceableNode.getDepth() == Path.ROOT_DEPTH) {
            if (!srcSession.getItemManager().nodeExists(getQPath())) {
                throw new ItemNotFoundException("No corresponding path found in workspace " + workspaceName + "(" + safeGetJCRPath() + ")");
            } else {
                correspondingPath = getPath();
            }
        } else {
            // get corresponding ancestor
            Node correspNode = srcSession.getNodeByUUID(referenceableNode.getUUID());
            // path of m2 found, if m1 == n1
            if (referenceableNode == this) {
                correspondingPath = correspNode.getPath();
            } else {
                Path p = referenceableNode.getQPath().computeRelativePath(getQPath());
                // use prefix mappings of srcSession
                String relPath = session.getPathResolver().getJCRPath(p);
                if (!correspNode.hasNode(relPath)) {
                    throw new ItemNotFoundException("No corresponding path found in workspace " + workspaceName + "(" + safeGetJCRPath() + ")");
                } else {
                    correspondingPath = correspNode.getNode(relPath).getPath();
                }
            }
        }
        return correspondingPath;
    } finally {
        if (srcSession != null) {
            // we don't need the other session anymore, logout
            srcSession.logout();
        }
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) AddNode(org.apache.jackrabbit.jcr2spi.operation.AddNode) Node(javax.jcr.Node) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 30 with ItemNotFoundException

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

the class NodeImpl method getPrimaryItem.

/**
     * @see Node#getPrimaryItem()
     */
public Item getPrimaryItem() throws ItemNotFoundException, RepositoryException {
    checkStatus();
    String name = getPrimaryNodeType().getPrimaryItemName();
    if (name == null) {
        throw new ItemNotFoundException("No primary item present on Node " + safeGetJCRPath());
    }
    if (hasProperty(name)) {
        return getProperty(name);
    } else if (hasNode(name)) {
        return getNode(name);
    } else {
        throw new ItemNotFoundException("Primary item " + name + " does not exist on Node " + safeGetJCRPath());
    }
}
Also used : ItemNotFoundException(javax.jcr.ItemNotFoundException)

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