/** * Checks whether this element has the specified path. Introduced to * avoid catching a <code>MalformedPathException</code> for simple * path comparisons. * @param path path to compare to * @return <code>true</code> if this child has the path * <code>path</code>, <code>false</code> otherwise */ public boolean hasPath(Path path) { return hasPath(path.getElements(), path.getLength()); }
public Path getCanonicalPath() throws RepositoryException { if (parent != null) { return parent.getCanonicalPath().getAncestor(1); } else { throw new RepositoryException( "There is no canonical representation of .."); } }
private Path getAbsolutePath(PathResolver resolver, String path) throws RepositoryException { try { Path qpath = resolver.getQPath(path).getNormalizedPath(); if (!qpath.isAbsolute()) { throw new RepositoryException("Path is not absolute: " + path); } return qpath; } catch (NameException e) { throw new RepositoryException("Path is invalid: " + path, e); } }
PropertyInclude(Path pattern) throws RepositoryException { super(pattern.getAncestor(1), null); this.propertyName = pattern.getName(); }
/** * @see Query#storeAsNode(String) */ public Node storeAsNode(String absPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, UnsupportedRepositoryOperationException, RepositoryException { NamePathResolver resolver = mgrProvider.getNamePathResolver(); try { Path p = resolver.getQPath(absPath).getNormalizedPath(); if (!p.isAbsolute()) { throw new RepositoryException(absPath + " is not an absolute path"); } String jcrParent = resolver.getJCRPath(p.getAncestor(1)); if (!session.itemExists(jcrParent)) { throw new PathNotFoundException(jcrParent); } String relPath = resolver.getJCRPath(p).substring(1); String ntName = resolver.getJCRName(NameConstants.NT_QUERY); Node queryNode = session.getRootNode().addNode(relPath, ntName); // set properties queryNode.setProperty(resolver.getJCRName(NameConstants.JCR_LANGUAGE), getLanguage()); queryNode.setProperty(resolver.getJCRName(NameConstants.JCR_STATEMENT), getStatement()); node = queryNode; return node; } catch (NameException e) { throw new RepositoryException(e.getMessage(), e); } }
public Property getProperty() throws RepositoryException { Value value = getValue(); Value pathValue = ValueHelper.convert(value, PATH, getSession().getValueFactory()); String path = pathValue.getString(); boolean absolute; try { Path p = sessionContext.getQPath(path); absolute = p.isAbsolute(); } catch (RepositoryException e) { throw new ValueFormatException("Property value cannot be converted to a PATH"); } try { return (absolute) ? getSession().getProperty(path) : getParent().getProperty(path); } catch (PathNotFoundException e) { throw new ItemNotFoundException(path); } }
/** * @see AbstractAccessControlManager#checkValidNodePath(String) */ @Override protected void checkValidNodePath(String absPath) throws PathNotFoundException, RepositoryException { Path p = getPath(absPath); if (p != null) { if (!p.isAbsolute()) { throw new RepositoryException("Absolute path expected."); } if (hierMgr.resolveNodePath(p) == null) { throw new PathNotFoundException("No such node " + absPath); } } }
private Property getProperty(PropertyId id, SessionInfoImpl sessionInfo) throws ItemNotFoundException, PathNotFoundException, RepositoryException { Session session = sessionInfo.getSession(); Node n; if (id.getUniqueID() != null) { n = session.getNodeByIdentifier(id.getUniqueID()); } else { n = session.getRootNode(); } Path path = id.getPath(); String jcrPath = sessionInfo.getNamePathResolver().getJCRPath(path); if (path.isAbsolute()) { jcrPath = jcrPath.substring(1, jcrPath.length()); } return n.getProperty(jcrPath); }
private Node getNode(NodeId id, SessionInfoImpl sessionInfo) throws ItemNotFoundException, PathNotFoundException, RepositoryException { Session session = sessionInfo.getSession(); Node n; if (id.getUniqueID() != null) { n = session.getNodeByIdentifier(id.getUniqueID()); } else { n = session.getRootNode(); } Path path = id.getPath(); if (path == null || path.denotesRoot()) { return n; } String jcrPath; jcrPath = sessionInfo.getNamePathResolver().getJCRPath(path); if (path.isAbsolute()) { jcrPath = jcrPath.substring(1, jcrPath.length()); } return n.getNode(jcrPath); }
/** * {@inheritDoc} */ public final ItemId resolvePath(Path path) throws RepositoryException { // shortcut if (path.denotesRoot()) { return rootNodeId; } if (!path.isCanonical()) { String msg = "path is not canonical"; log.debug(msg); throw new RepositoryException(msg); } return resolvePath(path, RETURN_ANY); }
/** * @see HierarchyManager#getPropertyEntry(Path) */ public PropertyEntry getPropertyEntry(Path qPath) throws PathNotFoundException, RepositoryException { // shortcut if (qPath.denotesRoot()) { throw new PathNotFoundException("The root path never points to a Property."); } if (!qPath.isCanonical()) { String msg = "Path is not canonical"; log.debug(msg); throw new RepositoryException(msg); } return getRootEntry().getDeepPropertyEntry(qPath); }
/** * * @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); } }
/** * @inheritDoc */ @Override public NodeIterator findNodes(Path relPath, String value, int authorizableType, boolean exact, long maxSize) throws RepositoryException { String sr = getSearchRoot(authorizableType); if (getSession().nodeExists(sr)) { try { String path = getNamePathResolver().getJCRPath(relPath); AuthorizableTypePredicate pred = getAuthorizableTypePredicate(authorizableType, relPath.getLength() > 1); Node root = getSession().getNode(sr); Map<String, Node> matchingNodes = new HashMap<String, Node>(); collectNodes(value, path, pred, root.getNodes(), matchingNodes, exact, maxSize); return new NodeIteratorAdapter(matchingNodes.values()); } catch (PathNotFoundException e) { // should not get here log.warn("Error while retrieving node " + sr); } } // else: searchRoot does not exist yet -> omit the search return NodeIteratorAdapter.EMPTY; }
/** * @see AccessManager#isGranted(Path, int) */ public boolean isGranted(Path absPath, int permissions) throws RepositoryException { checkInitialized(); if (!absPath.isAbsolute()) { throw new RepositoryException("Absolute path expected"); } return compiledPermissions.grants(absPath, permissions); }
public NodeImpl getImportTargetNode() throws RepositoryException { try { Path p = session.getQPath(parentAbsPath).getNormalizedPath(); if (!p.isAbsolute()) { throw new RepositoryException("not an absolute path: " + parentAbsPath); } return session.getItemManager().getNode(p); } catch (NameException e) { String msg = parentAbsPath + ": invalid path"; throw new RepositoryException(msg, e); } catch (AccessDeniedException ade) { throw new PathNotFoundException(parentAbsPath); } }
public Item perform(SessionContext context) throws RepositoryException { if (degree == 0) { return context.getItemManager().getRootNode(); } try { // Path.getAncestor requires relative degree, i.e. we need // to convert absolute to relative ancestor degree Path path = getPrimaryPath(); int relDegree = path.getAncestorCount() - degree; if (relDegree < 0) { throw new ItemNotFoundException(); } else if (relDegree == 0) { return ItemImpl.this; // shortcut } Path ancestorPath = path.getAncestor(relDegree); return context.getItemManager().getNode(ancestorPath); } catch (PathNotFoundException e) { throw new ItemNotFoundException("Ancestor not found", e); } } public String toString() {
private Node getExistingNode(Path path) throws RepositoryException { String absPath = session.getJCRPath(path.getNormalizedPath()); if (session.nodeExists(absPath)) { return session.getNode(absPath); } else if (session.propertyExists(absPath)) { return session.getProperty(absPath).getParent(); } else { String pPath = Text.getRelativeParent(absPath, 1); while (!"/".equals(pPath)) { if (session.nodeExists(pPath)) { return session.getNode(pPath); } else { pPath = Text.getRelativeParent(pPath, 1); } } throw new ItemNotFoundException("Unable to determine permissions: No item and no existing parent for target path " + absPath); } }
/** * @see Session#getProperty(String) */ @Override public Property getProperty(String absPath) throws RepositoryException { checkIsAlive(); try { Path qPath = getQPath(absPath).getNormalizedPath(); ItemManager itemMgr = getItemManager(); return itemMgr.getProperty(qPath); } catch (AccessDeniedException ade) { throw new PathNotFoundException(absPath); } }
public PathPattern(Path path) { super(); this.path = path; patternElements = path.getElements(); }