Search in sources :

Example 41 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit by apache.

the class JcrRemotingServlet method doGet.

@Override
protected void doGet(WebdavRequest webdavRequest, WebdavResponse webdavResponse, DavResource davResource) throws IOException, DavException {
    if (canHandle(DavMethods.DAV_GET, webdavRequest, davResource)) {
        // return json representation of the requested resource
        DavResourceLocator locator = davResource.getLocator();
        String path = locator.getRepositoryPath();
        Session session = getRepositorySession(webdavRequest);
        try {
            Node node = session.getNode(path);
            int depth = ((WrappingLocator) locator).getDepth();
            webdavResponse.setContentType("text/plain;charset=utf-8");
            webdavResponse.setStatus(DavServletResponse.SC_OK);
            JsonWriter writer = new JsonWriter(webdavResponse.getWriter());
            String[] includes = webdavRequest.getParameterValues(PARAM_INCLUDE);
            if (includes == null) {
                if (depth < BatchReadConfig.DEPTH_INFINITE) {
                    NodeType type = node.getPrimaryNodeType();
                    depth = brConfig.getDepth(type.getName());
                }
                writer.write(node, depth);
            } else {
                writeMultiple(writer, node, includes, depth);
            }
        } catch (PathNotFoundException e) {
            // properties cannot be requested as json object.
            throw new JcrDavException(new ItemNotFoundException("No node at " + path), DavServletResponse.SC_NOT_FOUND);
        } catch (RepositoryException e) {
            // should only get here if the item does not exist.
            log.debug(e.getMessage());
            throw new JcrDavException(e);
        }
    } else {
        super.doGet(webdavRequest, webdavResponse, davResource);
    }
}
Also used : Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) NodeType(javax.jcr.nodetype.NodeType) PathNotFoundException(javax.jcr.PathNotFoundException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator) JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) Session(javax.jcr.Session) DavSession(org.apache.jackrabbit.webdav.DavSession) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 42 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit by apache.

the class AbstractItemResource method move.

/**
     * Moves the underlying repository item to the indicated destination.
     *
     * @param destination
     * @throws DavException
     * @see DavResource#move(DavResource)
     * @see javax.jcr.Session#move(String, String)
     */
@Override
public void move(DavResource destination) throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    DavResourceLocator destLocator = destination.getLocator();
    if (!getLocator().isSameWorkspace(destLocator)) {
        throw new DavException(DavServletResponse.SC_FORBIDDEN);
    }
    try {
        String itemPath = getLocator().getRepositoryPath();
        String destItemPath = destination.getLocator().getRepositoryPath();
        if (getTransactionId() == null) {
            // if not part of a transaction directly import on workspace
            getRepositorySession().getWorkspace().move(itemPath, destItemPath);
        } else {
            // changes will not be persisted unless the tx is completed.
            getRepositorySession().move(itemPath, destItemPath);
        }
    // no use in calling 'complete' that would fail for a moved item anyway.
    } catch (PathNotFoundException e) {
        // according to rfc 2518
        throw new DavException(DavServletResponse.SC_CONFLICT, e.getMessage());
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 43 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit by apache.

the class TreeComparator method init.

/**
     * Makes sure that the source and target folder exist, and are empty
     */
private void init() throws RepositoryException {
    root = sc.testroot;
    sourceFolder = root + "/" + sc.sourceFolderName;
    targetFolder = root + "/" + sc.targetFolderName;
    // make sure the node does not have a and target sub node.
    try {
        session.getItem(sourceFolder).remove();
        session.save();
    } catch (PathNotFoundException e) {
    // item does not exist
    }
    try {
        Item tgt = session.getItem(targetFolder);
        tgt.remove();
        session.save();
    } catch (PathNotFoundException e) {
    // item does not exist
    }
    // add the source and target nodes
    Node rootNode = (Node) session.getItem(root);
    rootNode.addNode(sc.sourceFolderName);
    rootNode.addNode(sc.targetFolderName);
    session.save();
}
Also used : Item(javax.jcr.Item) Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 44 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit by apache.

the class ValueFactoryTest method createReferenceableNode.

/**
     * Create a referenceable node under the testRootNode
     * or null if it is not possible to create one.
     * @param name
     * @return
     * @throws RepositoryException
     */
public Node createReferenceableNode(String name) throws RepositoryException {
    // remove a yet existing node at the target
    try {
        Node node = testRootNode.getNode(name);
        node.remove();
        session.save();
    } catch (PathNotFoundException pnfe) {
    // ok
    }
    // a referenceable node
    Node n1 = testRootNode.addNode(name, testNodeType);
    if (n1.canAddMixin(mixReferenceable)) {
        n1.addMixin(mixReferenceable);
        // make sure jcr:uuid is available
        testRootNode.getSession().save();
        return n1;
    } else {
        return null;
    }
}
Also used : Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 45 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit by apache.

the class MoveSNSTest method testAccessMovedNodeByOldPath.

/**
     * Test if a moved node is 'replaced' by its SNS.
     */
public void testAccessMovedNodeByOldPath() throws RepositoryException, NotExecutableException {
    String oldPath = moveNode.getPath();
    //move the node
    doMove(oldPath, destinationPath);
    try {
        Item item = superuser.getItem(oldPath);
        // Implementation specific:
        assertTrue("A moved SNS node must be 'replaced' but is successor sibling.", item.isSame(sourceSibling));
    } catch (PathNotFoundException e) {
        fail("A moved SNS node must be 'replaced' but is successor sibling.");
    }
}
Also used : Item(javax.jcr.Item) PathNotFoundException(javax.jcr.PathNotFoundException)

Aggregations

PathNotFoundException (javax.jcr.PathNotFoundException)136 Node (javax.jcr.Node)58 RepositoryException (javax.jcr.RepositoryException)46 ItemNotFoundException (javax.jcr.ItemNotFoundException)24 Session (javax.jcr.Session)23 Path (org.apache.jackrabbit.spi.Path)22 AccessDeniedException (javax.jcr.AccessDeniedException)14 Property (javax.jcr.Property)14 Test (org.junit.Test)14 Item (javax.jcr.Item)11 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)10 NodeIterator (javax.jcr.NodeIterator)9 Value (javax.jcr.Value)9 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)9 Name (org.apache.jackrabbit.spi.Name)8 PropertyIterator (javax.jcr.PropertyIterator)7 NodeDelegate (org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate)7 HashSet (java.util.HashSet)6 ItemExistsException (javax.jcr.ItemExistsException)6 ValueFormatException (javax.jcr.ValueFormatException)6