/** * Checks if this node holds a lock. * <p> * The default implementation calls {@link Node#getLock()} and returns * <code>true</code> iff the holding node of the lock is the same as this * node. * * @return <code>true</code> if this node holds a lock, * <code>false</code> otherwise * @throws RepositoryException if an error occurs */ public boolean holdsLock() throws RepositoryException { try { return isSame(getLock().getNode()); } catch (LockException e) { return false; } }
/** * Returns the primary node type of this node. * <p> * The default implementation uses the value of the * <code>jcr:primaryType</code> property to look up the primary * node type from the {@link NodeTypeManager} of the current workspace. * * @return primary node type * @throws RepositoryException if an error occurs */ public NodeType getPrimaryNodeType() throws RepositoryException { NodeTypeManager manager = getSession().getWorkspace().getNodeTypeManager(); Property property = getProperty(getName("jcr:primaryType")); return manager.getNodeType(property.getString()); }
/** * Checks whether a node at the given relative path exists. * <p> * The default implementation looks up the node using * {@link Node#getNode(String)} and returns <code>true</code> if * a {@link PathNotFoundException} is not thrown. * * @param relPath relative path * @return <code>true</code> if a node exists at the given path, * <code>false</code> otherwise * @throws RepositoryException if an error occurs */ public boolean hasNode(String relPath) throws RepositoryException { try { getNode(relPath); return true; } catch (PathNotFoundException e) { return false; } }
/** * Returns the UUID of this node. * <p> * The default implementation checks if this node is referenceable (i.e. of * type <code>mix:referenceable</code>) and returns the contents of the * <code>jcr:uuid</code> property if it is. * * @return node UUID * @throws UnsupportedRepositoryOperationException * if this node is not referenceable * @throws RepositoryException if an error occurs */ public String getUUID() throws UnsupportedRepositoryOperationException, RepositoryException { if (isNodeType(getName("mix:referenceable"))) { return getProperty(getName("jcr:uuid")).getString(); } else { throw new UnsupportedRepositoryOperationException( "This node is not referenceable: " + getPath()); } }
/** * Checks whether this node is checked out. * <p> * The default implementation checks the <code>jcr:isCheckedOut</code> * property if this node is versionable, and recursively calls this method * on the parent node if this node is not versionable. A non-versionable * root node always returns <code>true</code> from this method. * * @return <code>true</code> if this node is checked out, * <code>false</code> otherwise * @throws RepositoryException if an error occurs */ public boolean isCheckedOut() throws RepositoryException { if (isNodeType(getName("jcr:versionable"))) { // This node is versionable, check the jcr:isCheckedOut property return getProperty(getName("jcr:isCheckedOut")).getBoolean(); } else { try { // This node is not versionable, is the parent checked out? return getParent().isCheckedOut(); } catch (ItemNotFoundException e) { // This node is the root node, always checked out return true; } } }
/** * Returns the path of this node. * <p> * The default implementation recursively calls this method on the * parent node and appends the name and optionally the index of this * node to construct the full path. Returns "/" if the parent node is * not available (i.e. this is the root node). * * @return node path * @throws RepositoryException if an error occurs */ public String getPath() throws RepositoryException { try { StringBuffer buffer = new StringBuffer(getParent().getPath()); if (buffer.length() > 1) { buffer.append('/'); } buffer.append(getName()); int index = getIndex(); if (index != 1) { buffer.append('['); buffer.append(index); buffer.append(']'); } return buffer.toString(); } catch (ItemNotFoundException e) { return "/"; } }
NodeType type = getPrimaryNodeType(); if (name.equals(type.getName())) { return true; NodeType[] mixins = getMixinNodeTypes(); for (int i = 0; i < mixins.length; i++) { if (name.equals(mixins[i].getName())) {
int slash = relPath.lastIndexOf('/'); if (slash == 0) { node = getSession().getRootNode(); relPath = relPath.substring(1); } else if (slash > 0) { node = getNode(relPath.substring(0, slash)); relPath = relPath.substring(slash + 1);
/** * Checks if this node has one or more properties. * <p> * The default implementation calls {@link Node#getNodes()} and returns * <code>true</code> iff returned iterator has at least one element. * * @return <code>true</code> if this node has child nodes, * <code>false</code> otherwise * @throws RepositoryException if an error occurs */ public boolean hasNodes() throws RepositoryException { return getNodes().hasNext(); }
/** * Returns the version history of this node. * <p> * The default implementation returns the containing version history of * the base version of this node. * * @return version history * @throws RepositoryException if an error occurs */ public VersionHistory getVersionHistory() throws RepositoryException { return getBaseVersion().getContainingHistory(); }
/** * Checks if this node is locked. * <p> * The default implementation calls {@link Node#getLock()} and returns * <code>true</code> iff a {@link LockException} is not thrown. * * @return <code>true</code> if this node is locked, * <code>false</code> otherwise * @throws RepositoryException if an error occurs */ public boolean isLocked() throws RepositoryException { try { getLock(); return true; } catch (LockException e) { return false; } }
/** * Returns the UUID of this node. * <p> * The default implementation checks if this node is referenceable (i.e. of * type <code>mix:referenceable</code>) and returns the contents of the * <code>jcr:uuid</code> property if it is. * * @return node UUID * @throws UnsupportedRepositoryOperationException * if this node is not referenceable * @throws RepositoryException if an error occurs */ public String getUUID() throws UnsupportedRepositoryOperationException, RepositoryException { if (isNodeType(getName("mix:referenceable"))) { return getProperty(getName("jcr:uuid")).getString(); } else { throw new UnsupportedRepositoryOperationException( "This node is not referenceable: " + getPath()); } }
/** * Checks whether this node is checked out. * <p> * The default implementation checks the <code>jcr:isCheckedOut</code> * property if this node is versionable, and recursively calls this method * on the parent node if this node is not versionable. A non-versionable * root node always returns <code>true</code> from this method. * * @return <code>true</code> if this node is checked out, * <code>false</code> otherwise * @throws RepositoryException if an error occurs */ public boolean isCheckedOut() throws RepositoryException { if (isNodeType(getName("jcr:versionable"))) { // This node is versionable, check the jcr:isCheckedOut property return getProperty(getName("jcr:isCheckedOut")).getBoolean(); } else { try { // This node is not versionable, is the parent checked out? return getParent().isCheckedOut(); } catch (ItemNotFoundException e) { // This node is the root node, always checked out return true; } } }
/** * Returns the path of this node. * <p> * The default implementation recursively calls this method on the * parent node and appends the name and optionally the index of this * node to construct the full path. Returns "/" if the parent node is * not available (i.e. this is the root node). * * @return node path * @throws RepositoryException if an error occurs */ public String getPath() throws RepositoryException { try { StringBuffer buffer = new StringBuffer(getParent().getPath()); if (buffer.length() > 1) { buffer.append('/'); } buffer.append(getName()); int index = getIndex(); if (index != 1) { buffer.append('['); buffer.append(index); buffer.append(']'); } return buffer.toString(); } catch (ItemNotFoundException e) { return "/"; } }
NodeType type = getPrimaryNodeType(); if (name.equals(type.getName())) { return true; NodeType[] mixins = getMixinNodeTypes(); for (int i = 0; i < mixins.length; i++) { if (name.equals(mixins[i].getName())) {
int slash = relPath.lastIndexOf('/'); if (slash == 0) { node = getSession().getRootNode(); relPath = relPath.substring(1); } else if (slash > 0) { node = getNode(relPath.substring(0, slash)); relPath = relPath.substring(slash + 1);
/** * Checks if this node has one or more properties. * <p> * The default implementation calls {@link Node#getNodes()} and returns * <code>true</code> iff returned iterator has at least one element. * * @return <code>true</code> if this node has child nodes, * <code>false</code> otherwise * @throws RepositoryException if an error occurs */ public boolean hasNodes() throws RepositoryException { return getNodes().hasNext(); }
/** * Returns the version history of this node. * <p> * The default implementation returns the containing version history of * the base version of this node. * * @return version history * @throws RepositoryException if an error occurs */ public VersionHistory getVersionHistory() throws RepositoryException { return getBaseVersion().getContainingHistory(); }
/** * Checks if this node is locked. * <p> * The default implementation calls {@link Node#getLock()} and returns * <code>true</code> iff a {@link LockException} is not thrown. * * @return <code>true</code> if this node is locked, * <code>false</code> otherwise * @throws RepositoryException if an error occurs */ public boolean isLocked() throws RepositoryException { try { getLock(); return true; } catch (LockException e) { return false; } }
/** * Returns the primary node type of this node. * <p> * The default implementation uses the value of the * <code>jcr:primaryType</code> property to look up the primary * node type from the {@link NodeTypeManager} of the current workspace. * * @return primary node type * @throws RepositoryException if an error occurs */ public NodeType getPrimaryNodeType() throws RepositoryException { NodeTypeManager manager = getSession().getWorkspace().getNodeTypeManager(); Property property = getProperty(getName("jcr:primaryType")); return manager.getNodeType(property.getString()); }