Search in sources :

Example 11 with DavResourceLocator

use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.

the class RootCollection method getMembers.

/**
     * Returns an iterator over the member resources, which are all
     * workspace resources available.
     *
     * @return members of this collection
     * @see org.apache.jackrabbit.webdav.DavResource#getMembers()
     */
@Override
public DavResourceIterator getMembers() {
    List<DavResource> memberList = new ArrayList();
    try {
        String[] wsNames = getRepositorySession().getWorkspace().getAccessibleWorkspaceNames();
        for (String wsName : wsNames) {
            String wspPath = "/" + wsName;
            DavResourceLocator childLoc = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), wspPath, wspPath);
            memberList.add(createResourceFromLocator(childLoc));
        }
    } catch (RepositoryException e) {
        log.error(e.getMessage());
    } catch (DavException e) {
        // should never occur
        log.error(e.getMessage());
    }
    return new DavResourceIteratorImpl(memberList);
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) DavResourceIteratorImpl(org.apache.jackrabbit.webdav.DavResourceIteratorImpl) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 12 with DavResourceLocator

use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.

the class VersionControlledItemCollection method getVersionHistory.

/**
     * Returns the {@link VersionHistory} associated with the repository node.
     * If the node is not versionable an exception is thrown.
     *
     * @return the {@link VersionHistoryResource} associated with this resource.
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#getVersionHistory()
     * @see javax.jcr.Node#getVersionHistory()
     */
@Override
public VersionHistoryResource getVersionHistory() throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    try {
        VersionHistory vh = ((Node) item).getVersionHistory();
        DavResourceLocator loc = getLocatorFromItem(vh);
        return (VersionHistoryResource) createResourceFromLocator(loc);
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) Node(javax.jcr.Node) VersionHistoryResource(org.apache.jackrabbit.webdav.version.VersionHistoryResource) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 13 with DavResourceLocator

use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.

the class JcrRemotingServlet method doPost.

@Override
protected void doPost(WebdavRequest webdavRequest, WebdavResponse webdavResponse, DavResource davResource) throws IOException, DavException {
    if (canHandle(DavMethods.DAV_POST, webdavRequest, davResource)) {
        // special remoting request: the defined parameters are exclusive
        // and cannot be combined.
        Session session = getRepositorySession(webdavRequest);
        RequestData data = new RequestData(webdavRequest, getTempDirectory(getServletContext()));
        String loc = null;
        try {
            String[] pValues;
            // multi-read over POST
            String[] includes = null;
            if ((pValues = data.getParameterValues(PARAM_CLONE)) != null) {
                loc = clone(session, pValues, davResource.getLocator());
            } else if ((pValues = data.getParameterValues(PARAM_COPY)) != null) {
                loc = copy(session, pValues, davResource.getLocator());
            } else if (data.getParameterValues(PARAM_DIFF) != null) {
                String targetPath = davResource.getLocator().getRepositoryPath();
                processDiff(session, targetPath, data, protectedRemoveManager);
            } else if ((pValues = data.getParameterValues(PARAM_INCLUDE)) != null && canHandle(DavMethods.DAV_GET, webdavRequest, davResource)) {
                includes = pValues;
            } else {
                String targetPath = davResource.getLocator().getRepositoryPath();
                loc = modifyContent(session, targetPath, data, protectedRemoveManager);
            }
            // TODO: append entity
            if (loc == null) {
                webdavResponse.setStatus(HttpServletResponse.SC_OK);
                if (includes != null) {
                    webdavResponse.setContentType("text/plain;charset=utf-8");
                    JsonWriter writer = new JsonWriter(webdavResponse.getWriter());
                    DavResourceLocator locator = davResource.getLocator();
                    String path = locator.getRepositoryPath();
                    Node node = session.getNode(path);
                    int depth = ((WrappingLocator) locator).getDepth();
                    writeMultiple(writer, node, includes, depth);
                }
            } else {
                webdavResponse.setHeader(DeltaVConstants.HEADER_LOCATION, loc);
                webdavResponse.setStatus(HttpServletResponse.SC_CREATED);
            }
        } catch (RepositoryException e) {
            log.warn(e.getMessage(), e);
            throw new JcrDavException(e);
        } catch (DiffException e) {
            log.warn(e.getMessage());
            Throwable cause = e.getCause();
            if (cause instanceof RepositoryException) {
                throw new JcrDavException((RepositoryException) cause);
            } else {
                throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid diff format.");
            }
        } finally {
            data.dispose();
        }
    } else {
        super.doPost(webdavRequest, webdavResponse, davResource);
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) RequestData(org.apache.jackrabbit.server.util.RequestData) JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) Session(javax.jcr.Session) DavSession(org.apache.jackrabbit.webdav.DavSession) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 14 with DavResourceLocator

use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.

the class JcrRemotingServlet method buildLocationHref.

private static String buildLocationHref(Session s, String destPath, DavResourceLocator reqLocator) throws RepositoryException {
    if (destPath != null) {
        NodeIterator it = s.getRootNode().getNodes(destPath.substring(1));
        Node n = null;
        while (it.hasNext()) {
            n = it.nextNode();
        }
        if (n != null) {
            DavResourceLocator loc = reqLocator.getFactory().createResourceLocator(reqLocator.getPrefix(), reqLocator.getWorkspacePath(), n.getPath(), false);
            return loc.getHref(true);
        }
    }
    // unable to determine -> no location header sent back.
    return null;
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 15 with DavResourceLocator

use of org.apache.jackrabbit.webdav.DavResourceLocator 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)

Aggregations

DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)34 DavException (org.apache.jackrabbit.webdav.DavException)25 RepositoryException (javax.jcr.RepositoryException)20 DavResource (org.apache.jackrabbit.webdav.DavResource)19 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)11 Node (javax.jcr.Node)10 ArrayList (java.util.ArrayList)7 VersionHistory (javax.jcr.version.VersionHistory)7 NodeIterator (javax.jcr.NodeIterator)5 DavResourceIteratorImpl (org.apache.jackrabbit.webdav.DavResourceIteratorImpl)5 VersionHistoryResource (org.apache.jackrabbit.webdav.version.VersionHistoryResource)5 PathNotFoundException (javax.jcr.PathNotFoundException)4 Item (javax.jcr.Item)3 Session (javax.jcr.Session)3 Version (javax.jcr.version.Version)3 VersionIterator (javax.jcr.version.VersionIterator)3 MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)3 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)3 VersionResource (org.apache.jackrabbit.webdav.version.VersionResource)3 Element (org.w3c.dom.Element)3