Search in sources :

Example 26 with Path

use of org.apache.jackrabbit.spi.Path in project jackrabbit by apache.

the class NodeImpl method orderBefore.

/**
     * @see Node#orderBefore(String, String)
     */
public synchronized void orderBefore(String srcChildRelPath, String destChildRelPath) throws UnsupportedRepositoryOperationException, VersionException, ConstraintViolationException, ItemNotFoundException, LockException, RepositoryException {
    checkIsWritable();
    if (!getPrimaryNodeType().hasOrderableChildNodes()) {
        throw new UnsupportedRepositoryOperationException("Child node ordering not supported on node " + safeGetJCRPath());
    }
    // check arguments
    if (srcChildRelPath.equals(destChildRelPath)) {
        // there's nothing to do
        return;
    }
    // check existence
    if (!hasNode(srcChildRelPath)) {
        throw new ItemNotFoundException("Node " + safeGetJCRPath() + " has no child node with name " + srcChildRelPath);
    }
    if (destChildRelPath != null && !hasNode(destChildRelPath)) {
        throw new ItemNotFoundException("Node " + safeGetJCRPath() + " has no child node with name " + destChildRelPath);
    }
    Path srcPath = getReorderPath(srcChildRelPath);
    Path beforePath = null;
    if (destChildRelPath != null) {
        beforePath = getReorderPath(destChildRelPath);
    }
    Operation op = ReorderNodes.create(getNodeState(), srcPath, beforePath);
    session.getSessionItemStateManager().execute(op);
}
Also used : Path(org.apache.jackrabbit.spi.Path) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) Operation(org.apache.jackrabbit.jcr2spi.operation.Operation) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 27 with Path

use of org.apache.jackrabbit.spi.Path 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 28 with Path

use of org.apache.jackrabbit.spi.Path 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 29 with Path

use of org.apache.jackrabbit.spi.Path 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 30 with Path

use of org.apache.jackrabbit.spi.Path in project jackrabbit by apache.

the class WorkspaceImpl method move.

/**
     * @see javax.jcr.Workspace#move(String, String)
     */
public void move(String srcAbsPath, String destAbsPath) throws ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException {
    session.checkSupportedOption(Repository.LEVEL_2_SUPPORTED);
    session.checkIsAlive();
    Path srcPath = session.getQPath(srcAbsPath);
    Path destPath = session.getQPath(destAbsPath);
    Operation op = Move.create(srcPath, destPath, getHierarchyManager(), getPathResolver(), false);
    getUpdatableItemStateManager().execute(op);
}
Also used : Path(org.apache.jackrabbit.spi.Path) Operation(org.apache.jackrabbit.jcr2spi.operation.Operation)

Aggregations

Path (org.apache.jackrabbit.spi.Path)222 RepositoryException (javax.jcr.RepositoryException)72 Name (org.apache.jackrabbit.spi.Name)37 ItemNotFoundException (javax.jcr.ItemNotFoundException)25 NodeState (org.apache.jackrabbit.core.state.NodeState)24 PathNotFoundException (javax.jcr.PathNotFoundException)22 NodeId (org.apache.jackrabbit.core.id.NodeId)22 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)20 NamespaceException (javax.jcr.NamespaceException)16 ArrayList (java.util.ArrayList)13 AccessDeniedException (javax.jcr.AccessDeniedException)13 Node (javax.jcr.Node)12 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)12 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)11 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)11 NodeId (org.apache.jackrabbit.spi.NodeId)11 QValue (org.apache.jackrabbit.spi.QValue)10 MalformedPathException (org.apache.jackrabbit.spi.commons.conversion.MalformedPathException)10 IOException (java.io.IOException)9 ItemExistsException (javax.jcr.ItemExistsException)8