use of javax.jcr.UnsupportedRepositoryOperationException 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.UnsupportedRepositoryOperationException in project jackrabbit by apache.
the class UserManagerTest method testGetAuthorizableByPath.
public void testGetAuthorizableByPath() throws RepositoryException, NotExecutableException {
String uid = superuser.getUserID();
Authorizable a = userMgr.getAuthorizable(uid);
if (a == null) {
throw new NotExecutableException();
}
try {
String path = a.getPath();
Authorizable a2 = userMgr.getAuthorizableByPath(path);
assertNotNull(a2);
assertEquals(a.getID(), a2.getID());
} catch (UnsupportedRepositoryOperationException e) {
throw new NotExecutableException();
}
}
use of javax.jcr.UnsupportedRepositoryOperationException in project jackrabbit by apache.
the class DavResourceImpl method getParentElements.
/**
* @see org.apache.jackrabbit.webdav.bind.BindableResource#getParentElements()
*/
public Set<ParentElement> getParentElements() {
try {
if (node.getDepth() > 0) {
Set<ParentElement> ps = new HashSet<ParentElement>();
NodeIterator sharedSetIterator = node.getSharedSet();
while (sharedSetIterator.hasNext()) {
Node sharednode = sharedSetIterator.nextNode();
DavResourceLocator loc = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), sharednode.getParent().getPath(), false);
ps.add(new ParentElement(loc.getHref(true), sharednode.getName()));
}
return ps;
}
} catch (UnsupportedRepositoryOperationException e) {
log.debug("unable to calculate parent set", e);
} catch (RepositoryException e) {
log.warn("unable to calculate parent set", e);
}
return Collections.emptySet();
}
use of javax.jcr.UnsupportedRepositoryOperationException in project jackrabbit by apache.
the class ShareableNodeTest method testRemoveMixinFromSharedNode.
/**
* Remove mix:shareable from a shareable node that has 2 nodes in the shared set.
*/
public void testRemoveMixinFromSharedNode() throws Exception {
// setup parent nodes and first child
Node a1 = testRootNode.addNode("a1");
Node a2 = testRootNode.addNode("a2");
Node b1 = a1.addNode("b1");
testRootNode.getSession().save();
// add mixin
ensureMixinType(b1, mixShareable);
b1.getSession().save();
// clone
Workspace workspace = b1.getSession().getWorkspace();
workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
Node[] shared = getSharedSet(b1);
assertEquals(2, shared.length);
b1 = shared[0];
Node b2 = shared[1];
assertTrue(b2.isSame(b1));
// (per Section 14.15 of JSR-283 specification)
try {
// remove mixin
b1.removeMixin(mixShareable);
b1.getSession().save();
// If this happens, then b1 shouldn't be shareable anymore
// ...
assertFalse(b1.isNodeType(mixShareable));
assertFalse(b2.isSame(b1));
} catch (ConstraintViolationException e) {
// one possible outcome if removing 'mix:shareable' isn't supported
} catch (UnsupportedRepositoryOperationException e) {
// also possible if the implementation doesn't support this
// capability
}
}
use of javax.jcr.UnsupportedRepositoryOperationException in project jackrabbit by apache.
the class ShareableNodeTest method testCloneToSameParent.
//--------------------------------------------------------- limitation tests
/**
* Clone a mix:shareable node to the same workspace, with the same
* parent. This is unsupported in Jackrabbit.
*/
public void testCloneToSameParent() throws Exception {
// setup parent nodes and first child
Node a = testRootNode.addNode("a");
Node b1 = a.addNode("b1");
testRootNode.getSession().save();
// add mixin
ensureMixinType(b1, mixShareable);
b1.save();
Workspace workspace = b1.getSession().getWorkspace();
try {
// clone to same parent
workspace.clone(workspace.getName(), b1.getPath(), a.getPath() + "/b2", false);
fail("Cloning inside same parent should fail.");
} catch (UnsupportedRepositoryOperationException e) {
// expected
}
}
Aggregations