Search in sources :

Example 26 with DavResource

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

the class VersionResourceImpl method getVersionHistory.

/**
     * Returns the {@link VersionHistory} associated with the repository version.
     * Note: in contrast to a versionable node, the version history of a version
     * item is always represented by its nearest ancestor.
     *
     * @return the {@link org.apache.jackrabbit.webdav.version.VersionHistoryResource} associated with this resource.
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.version.VersionResource#getVersionHistory()
     * @see javax.jcr.Item#getParent()
     */
public VersionHistoryResource getVersionHistory() throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    try {
        VersionHistory vh = getVersionHistoryItem();
        DavResourceLocator loc = getLocatorFromNode(vh);
        DavResource vhr = createResourceFromLocator(loc);
        if (vhr instanceof VersionHistoryResource) {
            return (VersionHistoryResource) vhr;
        } else {
            // severe error since resource factory doesn't behave correctly.
            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) VersionHistoryResource(org.apache.jackrabbit.webdav.version.VersionHistoryResource) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 27 with DavResource

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

the class DavResourceImpl method getMembers.

/**
     * @see DavResource#getMembers()
     */
public DavResourceIterator getMembers() {
    ArrayList<DavResource> list = new ArrayList<DavResource>();
    if (exists() && isCollection()) {
        try {
            NodeIterator it = node.getNodes();
            while (it.hasNext()) {
                Node n = it.nextNode();
                if (!isFilteredItem(n)) {
                    DavResourceLocator resourceLocator = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), n.getPath(), false);
                    DavResource childRes = factory.createResource(resourceLocator, session);
                    list.add(childRes);
                } else {
                    log.debug("Filtered resource '" + n.getName() + "'.");
                }
            }
        } catch (RepositoryException e) {
        // should not occur
        } catch (DavException e) {
        // should not occur
        }
    }
    return new DavResourceIteratorImpl(list);
}
Also used : NodeIterator(javax.jcr.NodeIterator) DavResource(org.apache.jackrabbit.webdav.DavResource) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) DavResourceIteratorImpl(org.apache.jackrabbit.webdav.DavResourceIteratorImpl) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 28 with DavResource

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

the class ResourceFactoryImpl method createResource.

/**
     * Create a new <code>DavResource</code> from the given locator and
     * request.
     *
     * @param locator
     * @param request
     * @param response
     * @return DavResource
     * @throws DavException
     * @see DavResourceFactory#createResource(DavResourceLocator,
     *      DavServletRequest, DavServletResponse)
     */
public DavResource createResource(DavResourceLocator locator, DavServletRequest request, DavServletResponse response) throws DavException {
    try {
        Node node = getNode(request.getDavSession(), locator);
        DavResource resource;
        if (node == null) {
            log.debug("Creating resource for non-existing repository node.");
            boolean isCollection = DavMethods.isCreateCollectionRequest(request);
            resource = createNullResource(locator, request.getDavSession(), isCollection);
        } else {
            resource = createResource(node, locator, request.getDavSession());
        }
        resource.addLockManager(lockMgr);
        return resource;
    } catch (RepositoryException e) {
        throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e);
    }
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Example 29 with DavResource

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

the class ResourceFactoryImpl method createResource.

/**
     * Tries to retrieve the repository item defined by the locator's resource
     * path and build the corresponding WebDAV resource. If the repository
     * supports the versioning option different resources are created for
     * version, versionhistory and common nodes.
     *
     * @param node
     * @param locator
     * @param session
     * @return
     * @throws DavException
     */
private DavResource createResource(Node node, DavResourceLocator locator, DavSession session) throws DavException {
    JcrDavSession.checkImplementation(session);
    JcrDavSession sessionImpl = (JcrDavSession) session;
    DavResource resource;
    if (versioningSupported(sessionImpl.getRepositorySession())) {
        // create special resources for Version and VersionHistory
        if (node instanceof Version) {
            resource = new VersionResourceImpl(locator, this, sessionImpl, resourceConfig, node);
        } else if (node instanceof VersionHistory) {
            resource = new VersionHistoryResourceImpl(locator, this, sessionImpl, resourceConfig, node);
        } else {
            resource = new VersionControlledResourceImpl(locator, this, sessionImpl, resourceConfig, node);
        }
    } else {
        resource = new DavResourceImpl(locator, this, session, resourceConfig, node);
    }
    return resource;
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) Version(javax.jcr.version.Version) JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) VersionHistory(javax.jcr.version.VersionHistory)

Example 30 with DavResource

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

the class AbstractWebdavServlet method doMkActivity.

/**
     * The MKACTIVITY method
     *
     * @param request
     * @param response
     * @param resource
     * @throws DavException
     * @throws IOException
     */
protected void doMkActivity(WebdavRequest request, WebdavResponse response, DavResource resource) throws DavException, IOException {
    if (resource.exists()) {
        AbstractWebdavServlet.log.warn("Unable to create activity: A resource already exists at the request-URL " + request.getRequestURL());
        response.sendError(DavServletResponse.SC_FORBIDDEN);
        return;
    }
    DavResource parentResource = resource.getCollection();
    if (parentResource == null || !parentResource.exists() || !parentResource.isCollection()) {
        // parent does not exist or is not a collection
        response.sendError(DavServletResponse.SC_CONFLICT);
        return;
    }
    // TODO: improve. see http://issues.apache.org/jira/browse/JCR-394
    if (!parentResource.getComplianceClass().contains(DavCompliance.ACTIVITY)) {
        response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
        return;
    }
    if (!(resource instanceof ActivityResource)) {
        AbstractWebdavServlet.log.error("Unable to create activity: ActivityResource expected");
        response.sendError(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
        return;
    }
    // try to add the new activity resource
    parentResource.addMember(resource, getInputContext(request, request.getInputStream()));
    // Note: mandatory cache control header has already been set upon response creation.
    response.setStatus(DavServletResponse.SC_CREATED);
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) ActivityResource(org.apache.jackrabbit.webdav.version.ActivityResource)

Aggregations

DavResource (org.apache.jackrabbit.webdav.DavResource)40 DavException (org.apache.jackrabbit.webdav.DavException)21 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)19 RepositoryException (javax.jcr.RepositoryException)16 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)7 ArrayList (java.util.ArrayList)6 Node (javax.jcr.Node)6 VersionHistory (javax.jcr.version.VersionHistory)6 DavResourceIteratorImpl (org.apache.jackrabbit.webdav.DavResourceIteratorImpl)5 Version (javax.jcr.version.Version)4 DavResourceIterator (org.apache.jackrabbit.webdav.DavResourceIterator)4 OutputStreamWriter (java.io.OutputStreamWriter)3 PrintWriter (java.io.PrintWriter)3 Item (javax.jcr.Item)3 NodeIterator (javax.jcr.NodeIterator)3 Repository (javax.jcr.Repository)3 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)3 Session (javax.jcr.Session)2 VersionIterator (javax.jcr.version.VersionIterator)2 MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)2