use of javax.jcr.Item in project jackrabbit by apache.
the class FilteringItemVisitor method visit.
/**
* Called when the Visitor is passed to a <code>Node</code>.
* <p>
* It calls <code>TraversingItemVisitor.entering(Node, int)</code> followed by
* <code>TraversingItemVisitor.leaving(Node, int)</code>. Implement these abstract methods to
* specify behaviour on 'arrival at' and 'after leaving' the <code>Node</code>.
* <p>
* If this method throws, the visiting process is aborted.
*
* @param node the <code>Node</code> that is accepting this visitor.
* @throws RepositoryException if an error occurrs
*/
public void visit(Node node) throws RepositoryException {
if (this.traversalPredicate.evaluate(node)) {
if (this.includePredicate == this.traversalPredicate || this.includePredicate.evaluate(node)) {
try {
if (!breadthFirst) {
// depth-first traversal
entering(node, currentLevel);
if (maxLevel == -1 || currentLevel < maxLevel) {
currentLevel++;
if (this.walkProperties) {
PropertyIterator propIter = node.getProperties();
while (propIter.hasNext()) {
propIter.nextProperty().accept(this);
}
}
NodeIterator nodeIter = node.getNodes();
while (nodeIter.hasNext()) {
nodeIter.nextNode().accept(this);
}
currentLevel--;
}
leaving(node, currentLevel);
} else {
// breadth-first traversal
entering(node, currentLevel);
leaving(node, currentLevel);
if (maxLevel == -1 || currentLevel < maxLevel) {
if (this.walkProperties) {
PropertyIterator propIter = node.getProperties();
while (propIter.hasNext()) {
nextQueue.addLast(propIter.nextProperty());
}
}
NodeIterator nodeIter = node.getNodes();
while (nodeIter.hasNext()) {
nextQueue.addLast(nodeIter.nextNode());
}
}
while (!currentQueue.isEmpty() || !nextQueue.isEmpty()) {
if (currentQueue.isEmpty()) {
currentLevel++;
currentQueue = nextQueue;
nextQueue = new LinkedList();
}
Item e = (Item) currentQueue.removeFirst();
e.accept(this);
}
currentLevel = 0;
}
} catch (RepositoryException re) {
currentLevel = 0;
throw re;
}
}
}
}
use of javax.jcr.Item in project jackrabbit by apache.
the class GetOrNullTest method testGetItemOrNullNonExistingNode.
public void testGetItemOrNullNonExistingNode() throws RepositoryException {
JackrabbitSession js = (JackrabbitSession) superuser;
Item item = js.getItemOrNull(PATH_NON_EXISTING_NODE);
assertNull(item);
}
use of javax.jcr.Item in project jackrabbit by apache.
the class GetOrNullTest method testGetItemOrNullExistingProperty.
public void testGetItemOrNullExistingProperty() throws RepositoryException {
JackrabbitSession js = (JackrabbitSession) superuser;
Item item = js.getItemOrNull(PATH_EXISTING_PROPERTY);
assertNotNull(item);
assertTrue(item instanceof Property);
assertEquals(item.getPath(), PATH_EXISTING_PROPERTY);
}
use of javax.jcr.Item in project jackrabbit by apache.
the class LocateCorrespondingNodeReport method getCorrespondingResourceHref.
/**
* Retrieve the href of the corresponding resource in the indicated workspace.
*
* @param resource
* @param session Session object used to access the {@link Node} object
* represented by the given resource.
* @param workspaceHref
* @return
* @throws RepositoryException
*/
private static String getCorrespondingResourceHref(DavResource resource, Session session, String workspaceHref) throws RepositoryException {
DavResourceLocator rLoc = resource.getLocator();
String itemPath = rLoc.getRepositoryPath();
Item item = session.getItem(itemPath);
if (item.isNode()) {
String workspaceName = rLoc.getFactory().createResourceLocator(rLoc.getPrefix(), workspaceHref).getWorkspaceName();
String corrPath = ((Node) item).getCorrespondingNodePath(workspaceName);
DavResourceLocator corrLoc = rLoc.getFactory().createResourceLocator(rLoc.getPrefix(), "/" + workspaceName, corrPath, false);
return corrLoc.getHref(true);
} else {
throw new PathNotFoundException("Node with path " + itemPath + " does not exist.");
}
}
use of javax.jcr.Item in project jackrabbit by apache.
the class ResourceFactoryImpl method getNode.
/**
* Returns the <code>Node</code> corresponding to the given locator or
* <code>null</code> if it does not exist or if the existing item represents
* a <code>Property</code>.
*
* @param sessionImpl
* @param locator
* @return
* @throws RepositoryException
*/
private Node getNode(DavSession sessionImpl, DavResourceLocator locator) throws RepositoryException {
Node node = null;
try {
String repoPath = locator.getRepositoryPath();
if (repoPath != null) {
Session session = ((JcrDavSession) sessionImpl).getRepositorySession();
Item item = session.getItem(repoPath);
if (item instanceof Node) {
node = (Node) item;
}
// else: item is a property -> return null
}
} catch (PathNotFoundException e) {
// item does not exist (yet). return null -> create null-resource
}
return node;
}
Aggregations