Search in sources :

Example 11 with PathNotFoundException

use of javax.jcr.PathNotFoundException 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 12 with PathNotFoundException

use of javax.jcr.PathNotFoundException 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 13 with PathNotFoundException

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

the class NodeImpl method getProperty.

/**
     * @see Node#getProperty(String)
     */
public Property getProperty(String relPath) throws PathNotFoundException, RepositoryException {
    checkStatus();
    PropertyEntry entry = resolveRelativePropertyPath(relPath);
    if (entry == null) {
        throw new PathNotFoundException(relPath);
    }
    try {
        return (Property) getItemManager().getItem(entry);
    } catch (AccessDeniedException e) {
        throw new PathNotFoundException(relPath);
    } catch (ItemNotFoundException e) {
        throw new PathNotFoundException(relPath);
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) PropertyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry) PathNotFoundException(javax.jcr.PathNotFoundException) Property(javax.jcr.Property) AddProperty(org.apache.jackrabbit.jcr2spi.operation.AddProperty) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 14 with PathNotFoundException

use of javax.jcr.PathNotFoundException 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 15 with PathNotFoundException

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

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