use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class NodeImpl method resolveRelativeNodePath.
/**
* Returns the <code>NodeEntry</code> at <code>relPath</code> or
* <code>null</code> if no node exists at <code>relPath</code>.
* <p>
* Note that access rights are not checked.
*
* @param relPath relative path of a (possible) node.
* @return the HierarchyEntry of the node at <code>relPath</code> or
* <code>null</code> if no node exists at <code>relPath</code>.
* @throws RepositoryException if <code>relPath</code> is not a valid
* relative path.
*/
private NodeEntry resolveRelativeNodePath(String relPath) throws RepositoryException {
NodeEntry targetEntry = null;
try {
Path rp = session.getPathResolver().getQPath(relPath);
// shortcut
if (rp.getLength() == 1) {
if (rp.denotesCurrent()) {
targetEntry = getNodeEntry();
} else if (rp.denotesParent()) {
targetEntry = getNodeEntry().getParent();
} else {
// try to get child entry + force loading of not known yet
targetEntry = getNodeEntry().getNodeEntry(rp.getName(), rp.getNormalizedIndex(), true);
}
} else {
// rp length > 1
Path p = getPath(rp);
targetEntry = session.getHierarchyManager().getNodeEntry(p.getCanonicalPath());
}
} catch (PathNotFoundException e) {
// item does not exist -> ignore and return null
} catch (NameException e) {
String msg = "Invalid relative path: " + relPath;
log.debug(msg);
throw new RepositoryException(msg, e);
}
return targetEntry;
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class RepositoryServiceImpl method internalGetPrivilegeDefinitions.
private PrivilegeDefinition[] internalGetPrivilegeDefinitions(SessionInfo sessionInfo, String uri) throws RepositoryException {
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(SecurityConstants.SUPPORTED_PRIVILEGE_SET);
HttpPropfind request = null;
try {
request = new HttpPropfind(uri, nameSet, DEPTH_0);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length < 1) {
throw new PathNotFoundException("Unable to retrieve privileges definitions.");
}
DavPropertyName displayName = SecurityConstants.SUPPORTED_PRIVILEGE_SET;
DavProperty<?> p = mresponses[0].getProperties(DavServletResponse.SC_OK).get(displayName);
if (p == null) {
return new PrivilegeDefinition[0];
} else {
// build PrivilegeDefinition(s) from the supported-privileges dav property
Map<Name, SupportedPrivilege> spMap = new HashMap<Name, SupportedPrivilege>();
fillSupportedPrivilegeMap(new SupportedPrivilegeSetProperty(p).getValue(), spMap, getNameFactory());
List<PrivilegeDefinition> pDefs = new ArrayList<PrivilegeDefinition>();
for (Name privilegeName : spMap.keySet()) {
SupportedPrivilege sp = spMap.get(privilegeName);
Set<Name> aggrnames = null;
SupportedPrivilege[] aggregates = sp.getSupportedPrivileges();
if (aggregates != null && aggregates.length > 0) {
aggrnames = new HashSet<Name>();
for (SupportedPrivilege aggregate : aggregates) {
Name aggregateName = nameFactory.create(aggregate.getPrivilege().getNamespace().getURI(), aggregate.getPrivilege().getName());
aggrnames.add(aggregateName);
}
}
PrivilegeDefinition def = new PrivilegeDefinitionImpl(privilegeName, sp.isAbstract(), aggrnames);
pDefs.add(def);
}
return pDefs.toArray(new PrivilegeDefinition[pDefs.size()]);
}
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class ExceptionConverter method generate.
public static RepositoryException generate(DavException davExc, int methodCode, String name) {
String msg = davExc.getMessage();
if (davExc.hasErrorCondition()) {
try {
Element error = davExc.toXml(DomUtil.createDocument());
if (DomUtil.matches(error, DavException.XML_ERROR, DavConstants.NAMESPACE)) {
if (DomUtil.hasChildElement(error, "exception", null)) {
Element exc = DomUtil.getChildElement(error, "exception", null);
if (DomUtil.hasChildElement(exc, "message", null)) {
msg = DomUtil.getChildText(exc, "message", null);
}
if (DomUtil.hasChildElement(exc, "class", null)) {
Class<?> cl = Class.forName(DomUtil.getChildText(exc, "class", null));
Constructor<?> excConstr = cl.getConstructor(String.class);
if (excConstr != null) {
Object o = excConstr.newInstance(msg);
if (o instanceof PathNotFoundException && methodCode == DavMethods.DAV_POST) {
// see JCR-2536
return new InvalidItemStateException(msg);
} else if (o instanceof RepositoryException) {
return (RepositoryException) o;
} else if (o instanceof Exception) {
return new RepositoryException(msg, (Exception) o);
}
}
}
}
}
} catch (Exception e) {
return new RepositoryException(e);
}
}
// make sure an exception is generated
switch(davExc.getErrorCode()) {
// TODO: mapping DAV_error to jcr-exception is ambiguous. to be improved
case DavServletResponse.SC_NOT_FOUND:
switch(methodCode) {
case DavMethods.DAV_DELETE:
case DavMethods.DAV_MKCOL:
case DavMethods.DAV_PUT:
case DavMethods.DAV_POST:
// been made.
return new InvalidItemStateException(msg, davExc);
default:
return new ItemNotFoundException(msg, davExc);
}
case DavServletResponse.SC_LOCKED:
return new LockException(msg, davExc);
case DavServletResponse.SC_METHOD_NOT_ALLOWED:
return new ConstraintViolationException(msg, davExc);
case DavServletResponse.SC_CONFLICT:
return new InvalidItemStateException(msg, davExc);
case DavServletResponse.SC_PRECONDITION_FAILED:
return new LockException(msg, davExc);
case DavServletResponse.SC_NOT_IMPLEMENTED:
if (methodCode > 0 && name != null) {
return new UnsupportedRepositoryOperationException("Missing implementation: Method " + name + " could not be executed", davExc);
} else {
return new UnsupportedRepositoryOperationException("Missing implementation", davExc);
}
default:
return new RepositoryException(msg, davExc);
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit-oak by apache.
the class AccessControlManagerImplTest method testRemovePolicyPropertyPath.
@Test
public void testRemovePolicyPropertyPath() throws Exception {
try {
String path = "/jcr:primaryType";
AccessControlPolicy acl = createPolicy(path);
acMgr.removePolicy(path, acl);
fail("Removing access control policy at property path should fail");
} catch (PathNotFoundException e) {
// success
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class ItemManager method getNode.
/**
* @param path
* @return
* @throws PathNotFoundException
* @throws AccessDeniedException
* @throws RepositoryException
*/
public NodeImpl getNode(Path path) throws PathNotFoundException, AccessDeniedException, RepositoryException {
NodeId id = hierMgr.resolveNodePath(path);
if (id == null) {
throw new PathNotFoundException(safeGetJCRPath(path));
}
NodeId parentId = null;
if (!path.denotesRoot()) {
parentId = hierMgr.resolveNodePath(path.getAncestor(1));
}
try {
if (parentId == null) {
return (NodeImpl) getItem(id, path, true);
}
// parent
return getNode(id, parentId);
} catch (ItemNotFoundException infe) {
throw new PathNotFoundException(safeGetJCRPath(path));
}
}
Aggregations