Search in sources :

Example 11 with UnsupportedRepositoryOperationException

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);
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) InvalidItemStateException(javax.jcr.InvalidItemStateException) Element(org.w3c.dom.Element) RepositoryException(javax.jcr.RepositoryException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) ItemNotFoundException(javax.jcr.ItemNotFoundException) PathNotFoundException(javax.jcr.PathNotFoundException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) DavException(org.apache.jackrabbit.webdav.DavException) RepositoryException(javax.jcr.RepositoryException) LockException(javax.jcr.lock.LockException) InvalidItemStateException(javax.jcr.InvalidItemStateException) LockException(javax.jcr.lock.LockException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) PathNotFoundException(javax.jcr.PathNotFoundException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 12 with UnsupportedRepositoryOperationException

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();
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException)

Example 13 with UnsupportedRepositoryOperationException

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();
}
Also used : NodeIterator(javax.jcr.NodeIterator) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) ParentElement(org.apache.jackrabbit.webdav.bind.ParentElement) HashSet(java.util.HashSet) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 14 with UnsupportedRepositoryOperationException

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
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) Node(javax.jcr.Node) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) Workspace(javax.jcr.Workspace)

Example 15 with UnsupportedRepositoryOperationException

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
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) Node(javax.jcr.Node) Workspace(javax.jcr.Workspace)

Aggregations

UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)57 RepositoryException (javax.jcr.RepositoryException)17 Node (javax.jcr.Node)14 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)12 NodeId (org.apache.jackrabbit.core.id.NodeId)8 ArrayList (java.util.ArrayList)7 Workspace (javax.jcr.Workspace)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 Session (javax.jcr.Session)4 VersionManager (javax.jcr.version.VersionManager)4 NodeState (org.apache.jackrabbit.core.state.NodeState)4 Name (org.apache.jackrabbit.spi.Name)4 Path (org.apache.jackrabbit.spi.Path)4 IOException (java.io.IOException)3 ItemExistsException (javax.jcr.ItemExistsException)3 ItemNotFoundException (javax.jcr.ItemNotFoundException)3 NodeType (javax.jcr.nodetype.NodeType)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AccessDeniedException (javax.jcr.AccessDeniedException)2