use of javax.jcr.PathNotFoundException 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;
}
use of javax.jcr.PathNotFoundException 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.PathNotFoundException in project jackrabbit by apache.
the class ItemImpl method getAncestor.
/**
* @see javax.jcr.Item#getAncestor(int)
*/
public Item getAncestor(int depth) throws ItemNotFoundException, AccessDeniedException, RepositoryException {
checkStatus();
if (depth == 0) {
return session.getRootNode();
}
String msg = "No ancestor at depth = " + depth;
try {
// Path.getAncestor requires relative degree, i.e. we need
// to convert absolute to relative ancestor degree
Path path = getQPath();
int relDegree = path.getAncestorCount() - depth;
if (relDegree < 0) {
throw new ItemNotFoundException(msg);
}
Path ancestorPath = path.getAncestor(relDegree);
if (relDegree == 0) {
return this;
} else {
return getItemManager().getNode(ancestorPath);
}
} catch (PathNotFoundException e) {
throw new ItemNotFoundException(msg);
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class ACLEditor method setPolicy.
/**
* @see AccessControlEditor#setPolicy(String,AccessControlPolicy)
*/
public void setPolicy(String nodePath, AccessControlPolicy policy) throws AccessControlException, PathNotFoundException, RepositoryException {
checkProtectsNode(nodePath);
checkValidPolicy(nodePath, policy);
ACLTemplate acl = (ACLTemplate) policy;
NodeImpl acNode = getAcNode(nodePath);
if (acNode == null) {
throw new PathNotFoundException("No such node " + nodePath);
}
// write the entries to the node
NodeImpl aclNode;
if (acNode.hasNode(N_POLICY)) {
aclNode = acNode.getNode(N_POLICY);
// remove all existing aces
for (NodeIterator aceNodes = aclNode.getNodes(); aceNodes.hasNext(); ) {
NodeImpl aceNode = (NodeImpl) aceNodes.nextNode();
removeItem(aceNode);
}
} else {
/* doesn't exist yet -> create */
aclNode = addNode(acNode, N_POLICY, NT_REP_ACL);
}
/* add all new entries defined on the template */
AccessControlEntry[] aces = acl.getAccessControlEntries();
for (AccessControlEntry ace1 : aces) {
AccessControlEntryImpl ace = (AccessControlEntryImpl) ace1;
// create the ACE node
Name nodeName = getUniqueNodeName(aclNode, "entry");
Name ntName = (ace.isAllow()) ? NT_REP_GRANT_ACE : NT_REP_DENY_ACE;
NodeImpl aceNode = addNode(aclNode, nodeName, ntName);
ValueFactory vf = session.getValueFactory();
// write the rep:principalName property
setProperty(aceNode, P_PRINCIPAL_NAME, vf.createValue(ace.getPrincipal().getName()));
// ... and the rep:privileges property
Privilege[] privs = ace.getPrivileges();
Value[] vs = new Value[privs.length];
for (int j = 0; j < privs.length; j++) {
vs[j] = vf.createValue(privs[j].getName(), PropertyType.NAME);
}
setProperty(aceNode, P_PRIVILEGES, vs);
// store the restrictions:
Set<Name> restrNames = ace.getRestrictions().keySet();
for (Name restrName : restrNames) {
Value value = ace.getRestriction(restrName);
setProperty(aceNode, restrName, value);
}
}
// mark the parent modified.
markModified((NodeImpl) aclNode.getParent());
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class TraversingNodeResolver method findNodes.
/**
* @inheritDoc
*/
@Override
public NodeIterator findNodes(Set<Name> propertyNames, String value, Name ntName, boolean exact, long maxSize) throws RepositoryException {
String sr = getSearchRoot(ntName);
if (getSession().nodeExists(sr)) {
try {
Node root = getSession().getNode(sr);
Set<Node> matchSet = new HashSet<Node>();
collectNodes(value, propertyNames, ntName, root.getNodes(), matchSet, exact, maxSize);
return new NodeIteratorAdapter(matchSet);
} 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;
}
Aggregations