public int getDepth(Path path, PathResolver pathResolver) throws NamespaceException { return this.config.getRequestDepth(pathResolver.getJCRPath(path), path.getDepth()); } }
/** * @see Path#isAncestorOf(Path) */ public boolean isAncestorOf(Path other) throws IllegalArgumentException, RepositoryException { if (other == null) { throw new IllegalArgumentException("null argument"); } // make sure both paths are either absolute or relative if (isAbsolute() != other.isAbsolute()) { throw new IllegalArgumentException("Cannot compare a relative path with an absolute path"); } // make sure we're comparing normalized paths Path p0 = getNormalizedPath(); Path p1 = other.getNormalizedPath(); if (p0.equals(p1)) { return false; } // calculate depth of paths (might be negative) if (p0.getDepth() >= p1.getDepth()) { return false; } Path.Element[] elems0 = p0.getElements(); Path.Element[] elems1 = p1.getElements(); for (int i = 0; i < elems0.length; i++) { if (!elems0[i].equals(elems1[i])) { return false; } } return true; }
protected RelativePath(Path parent) { this.parent = parent; if (parent != null) { this.absolute = parent.isAbsolute(); this.identifier = parent.isIdentifierBased(); this.depth = parent.getDepth() + getDepthModifier(); this.length = parent.getLength() + 1; } else { this.absolute = false; this.identifier = false; this.depth = getDepthModifier(); this.length = 1; } }
protected RelativePath(Path parent) { this.parent = parent; if (parent != null) { this.absolute = parent.isAbsolute(); this.identifier = parent.isIdentifierBased(); this.depth = parent.getDepth() + getDepthModifier(); this.length = parent.getLength() + 1; } else { this.absolute = false; this.identifier = false; this.depth = getDepthModifier(); this.length = 1; } }
/** * * @param relativePath * @return * @throws RepositoryException */ private Path getReorderPath(String relativePath) throws RepositoryException { try { Path p = session.getPathResolver().getQPath(relativePath); if (p.isAbsolute() || p.getLength() != 1 || p.getDepth() != 1) { throw new RepositoryException("Invalid relative path: " + relativePath); } return p; } catch (NameException e) { String msg = "Invalid relative path: " + relativePath; log.debug(msg); throw new RepositoryException(msg, e); } }
/** * * @param relativePath * @return * @throws RepositoryException */ private Path getReorderPath(String relativePath) throws RepositoryException { try { Path p = session.getPathResolver().getQPath(relativePath); if (p.isAbsolute() || p.getLength() != 1 || p.getDepth() != 1) { throw new RepositoryException("Invalid relative path: " + relativePath); } return p; } catch (NameException e) { String msg = "Invalid relative path: " + relativePath; log.debug(msg); throw new RepositoryException(msg, e); } }
/** * Determines if this path is a descendant of the given other path * by comparing the depths of the paths and checking if the corresponding * ancestor of this path is equivalent to the given other path. * * @param other other path * @return <code>true</code> if this path is a descendant of the other path, * <code>false</code> otherwise * @throws IllegalArgumentException if the other path is <code>null</code>, * or relative when this path is absolute, * or vice versa * @throws RepositoryException if an error occurs */ public final boolean isDescendantOf(Path other) throws IllegalArgumentException, RepositoryException { if (other != null && isAbsolute() == other.isAbsolute() && isIdentifierBased() == other.isIdentifierBased()) { int d = getDepth() - other.getDepth(); return d > 0 && getAncestor(d).isEquivalentTo(other); } else { throw new IllegalArgumentException( this + ".isDescendantOf(" + other + ")"); } }
/** * Determines if this path is a ancestor of the given other path * by comparing the depths of the paths and checking if the corresponding * ancestor of the given other path is equivalent to this path. * * @param other other path * @return <code>true</code> if this path is an ancestor of the other path, * <code>false</code> otherwise * @throws IllegalArgumentException if the other path is <code>null</code>, * or relative when this path is absolute, * or vice versa * @throws RepositoryException if an error occurs */ public final boolean isAncestorOf(Path other) throws IllegalArgumentException, RepositoryException { if (other != null && isAbsolute() == other.isAbsolute() && isIdentifierBased() == other.isIdentifierBased()) { int d = other.getDepth() - getDepth(); return d > 0 && isEquivalentTo(other.getAncestor(d)); } else { throw new IllegalArgumentException( this + ".isAncestorOf(" + other + ")"); } }
/** * Determines if this path is a ancestor of the given other path * by comparing the depths of the paths and checking if the corresponding * ancestor of the given other path is equivalent to this path. * * @param other other path * @return <code>true</code> if this path is an ancestor of the other path, * <code>false</code> otherwise * @throws IllegalArgumentException if the other path is <code>null</code>, * or relative when this path is absolute, * or vice versa * @throws RepositoryException if an error occurs */ public final boolean isAncestorOf(Path other) throws IllegalArgumentException, RepositoryException { if (other != null && isAbsolute() == other.isAbsolute() && isIdentifierBased() == other.isIdentifierBased()) { int d = other.getDepth() - getDepth(); return d > 0 && isEquivalentTo(other.getAncestor(d)); } else { throw new IllegalArgumentException( this + ".isAncestorOf(" + other + ")"); } }
/** * Determines if this path is a descendant of the given other path * by comparing the depths of the paths and checking if the corresponding * ancestor of this path is equivalent to the given other path. * * @param other other path * @return <code>true</code> if this path is a descendant of the other path, * <code>false</code> otherwise * @throws IllegalArgumentException if the other path is <code>null</code>, * or relative when this path is absolute, * or vice versa * @throws RepositoryException if an error occurs */ public final boolean isDescendantOf(Path other) throws IllegalArgumentException, RepositoryException { if (other != null && isAbsolute() == other.isAbsolute() && isIdentifierBased() == other.isIdentifierBased()) { int d = getDepth() - other.getDepth(); return d > 0 && getAncestor(d).isEquivalentTo(other); } else { throw new IllegalArgumentException( this + ".isDescendantOf(" + other + ")"); } }
Path p = sessionContext.getQPath(srcName); if (p.isAbsolute() || p.getLength() != 1 || p.getDepth() != 1) { throw new RepositoryException("invalid name: " + srcName); Path p = sessionContext.getQPath(destName); if (p.isAbsolute() || p.getLength() != 1 || p.getDepth() != 1) { throw new RepositoryException("invalid name: " + destName);
Path p = sessionContext.getQPath(srcName); if (p.isAbsolute() || p.getLength() != 1 || p.getDepth() != 1) { throw new RepositoryException("invalid name: " + srcName); Path p = sessionContext.getQPath(destName); if (p.isAbsolute() || p.getLength() != 1 || p.getDepth() != 1) { throw new RepositoryException("invalid name: " + destName);
/** * @see PathFactory#create(org.apache.jackrabbit.spi.Path.Element[]) */ public Path create(Path.Element[] elements) throws IllegalArgumentException { Path path = null; for (Path.Element element : elements) { if (element.denotesCurrent()) { path = new CurrentPath(path); } else if (element.denotesIdentifier()) { if (path != null) { throw new IllegalArgumentException(); } path = new IdentifierPath(element.getIdentifier()); } else if (element.denotesName()) { path = new NamePath(path, element.getName(), element.getIndex()); } else if (element.denotesParent()) { if (path != null && path.isAbsolute() && path.getDepth() == 0) { throw new IllegalArgumentException(); } path = new ParentPath(path); } else if (element.denotesRoot()) { if (path != null) { throw new IllegalArgumentException(); } path = RootPath.ROOT_PATH; } } return path; }
/** * @see PathFactory#create(org.apache.jackrabbit.spi.Path.Element[]) */ public Path create(Path.Element[] elements) throws IllegalArgumentException { Path path = null; for (Path.Element element : elements) { if (element.denotesCurrent()) { path = new CurrentPath(path); } else if (element.denotesIdentifier()) { if (path != null) { throw new IllegalArgumentException(); } path = new IdentifierPath(element.getIdentifier()); } else if (element.denotesName()) { path = new NamePath(path, element.getName(), element.getIndex()); } else if (element.denotesParent()) { if (path != null && path.isAbsolute() && path.getDepth() == 0) { throw new IllegalArgumentException(); } path = new ParentPath(path); } else if (element.denotesRoot()) { if (path != null) { throw new IllegalArgumentException(); } path = RootPath.ROOT_PATH; } } return path; }