Search in sources :

Example 21 with Path

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

the class SessionImpl method getVersionState.

/**
     * Returns the NodeState of the given Node and asserts that the state is
     * listed in the hierarchy built by this Session. If the version
     * was obtained from a different session, the 'corresponding' version
     * state for this session is retrieved.
     *
     * @param version
     * @return the NodeState associated with the specified version.
     */
NodeState getVersionState(Version version) throws RepositoryException {
    NodeState nodeState;
    if (version.getSession() == this) {
        nodeState = (NodeState) ((NodeImpl) version).getItemState();
    } else {
        Path p = getQPath(version.getPath());
        Path parentPath = p.getAncestor(1);
        HierarchyEntry parentEntry = getHierarchyManager().lookup(parentPath);
        if (parentEntry != null) {
            // make sure the parent entry is up to date
            parentEntry.invalidate(false);
        }
        nodeState = getHierarchyManager().getNodeState(p);
    }
    return nodeState;
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) HierarchyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry)

Example 22 with Path

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

the class SessionImpl method getImportContentHandler.

/**
     * @see Session#getImportContentHandler(String, int)
     */
public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior) throws PathNotFoundException, ConstraintViolationException, VersionException, LockException, RepositoryException {
    checkSupportedOption(Repository.LEVEL_2_SUPPORTED);
    checkIsAlive();
    Path parentPath = getQPath(parentAbsPath);
    // NOTE: check if path corresponds to Node and is writable is performed
    // within the SessionImporter.
    Importer importer = new SessionImporter(parentPath, this, itemStateManager, uuidBehavior);
    return new ImportHandler(importer, getNamespaceResolver(), workspace.getNamespaceRegistry(), getNameFactory(), getPathFactory());
}
Also used : Path(org.apache.jackrabbit.spi.Path) ImportHandler(org.apache.jackrabbit.jcr2spi.xml.ImportHandler) Importer(org.apache.jackrabbit.jcr2spi.xml.Importer) SessionImporter(org.apache.jackrabbit.jcr2spi.xml.SessionImporter) SessionImporter(org.apache.jackrabbit.jcr2spi.xml.SessionImporter)

Example 23 with Path

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

the class NodeImpl method addNode.

/**
     * @see Node#addNode(String, String)
     */
public Node addNode(String relPath, String primaryNodeTypeName) throws ItemExistsException, PathNotFoundException, NoSuchNodeTypeException, LockException, VersionException, ConstraintViolationException, RepositoryException {
    checkIsWritable();
    // build path object and retrieve parent node
    Path nodePath = getPath(relPath).getNormalizedPath();
    if (nodePath.getIndex() != Path.INDEX_UNDEFINED) {
        String msg = "Illegal subscript specified: " + relPath;
        log.debug(msg);
        throw new RepositoryException(msg);
    }
    NodeImpl parentNode;
    if (nodePath.getLength() == 1) {
        parentNode = this;
    } else {
        Path parentPath = nodePath.getAncestor(1);
        ItemManager itemMgr = getItemManager();
        if (itemMgr.nodeExists(parentPath)) {
            parentNode = (NodeImpl) itemMgr.getNode(parentPath);
        } else if (itemMgr.propertyExists(parentPath)) {
            String msg = "Cannot add a node to property " + LogUtil.safeGetJCRPath(parentPath, session.getPathResolver());
            log.debug(msg);
            throw new ConstraintViolationException(msg);
        } else {
            throw new PathNotFoundException("Cannot add a new node to a non-existing parent at " + LogUtil.safeGetJCRPath(parentPath, session.getPathResolver()));
        }
    }
    // get names objects for node and nt
    Name nodeName = nodePath.getName();
    Name ntName = (primaryNodeTypeName == null) ? null : getQName(primaryNodeTypeName);
    // create new node (including validation checks)
    return parentNode.createNode(nodeName, ntName);
}
Also used : Path(org.apache.jackrabbit.spi.Path) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) Name(org.apache.jackrabbit.spi.Name)

Example 24 with Path

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

the class NodeImpl method resolveRelativePropertyPath.

/**
     * Returns the id of the property at <code>relPath</code> or <code>null</code>
     * if no property exists at <code>relPath</code>.
     * <p>
     * Note that access rights are not checked.
     *
     * @param relPath relative path of a (possible) property
     * @return the PropertyEntry of the property at <code>relPath</code> or
     * <code>null</code> if no property exists at <code>relPath</code>
     * @throws RepositoryException if <code>relPath</code> is not a valid
     * relative path
     */
private PropertyEntry resolveRelativePropertyPath(String relPath) throws RepositoryException {
    PropertyEntry targetEntry = null;
    try {
        Path rp = session.getPathResolver().getQPath(relPath);
        if (rp.getLength() == 1 && rp.denotesName()) {
            // a single path element must always denote a name. '.' and '..'
            // will never point to a property. If the NodeEntry does not
            // contain such a property entry, the targetEntry is 'null;
            Name propName = rp.getName();
            // check if property entry exists
            targetEntry = getNodeEntry().getPropertyEntry(propName, true);
        } else {
            // build and resolve absolute path
            Path p = getPath(rp).getCanonicalPath();
            try {
                targetEntry = session.getHierarchyManager().getPropertyEntry(p);
            } catch (PathNotFoundException e) {
            // ignore -> return null;
            }
        }
    } catch (NameException e) {
        String msg = "failed to resolve property path " + relPath + " relative to " + safeGetJCRPath();
        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) PropertyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) Name(org.apache.jackrabbit.spi.Name)

Example 25 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)

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