Search in sources :

Example 46 with DavResource

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

the class VersionControlledItemCollection method merge.

/**
 * Merge the repository node represented by this resource according to the
 * information present in the given {@link MergeInfo} object.
 *
 * @param mergeInfo
 * @return <code>MultiStatus</code> recording all repository items modified
 * by this merge call as well as the resources that a client must modify to
 * complete the merge (see <a href="http://www.webdav.org/specs/rfc3253.html#METHOD_MERGE">RFC 3253</a>)
 * @throws org.apache.jackrabbit.webdav.DavException
 * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#merge(org.apache.jackrabbit.webdav.version.MergeInfo)
 * @see Node#merge(String, boolean)
 */
// TODO: with jcr the node must not be versionable in order to perform Node.merge
@Override
public MultiStatus merge(MergeInfo mergeInfo) throws DavException {
    if (mergeInfo == null) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST);
    }
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    MultiStatus ms = new MultiStatus();
    try {
        // NOTE: RFC requires that all modified resources are reported in the
        // multistatus response. this doesn't work however with the remoting
        // there is no way to distinguish the 'failedId's from any other
        // resources that got modified by this merge operation -> omitted.
        // todo: RFC allows multiple href elements inside the DAV:source element
        final String href = normalizeResourceHref(mergeInfo.getSourceHrefs()[0]);
        String workspaceName = getLocatorFromHref(href).getWorkspaceName();
        String depth = DomUtil.getChildTextTrim(mergeInfo.getMergeElement(), DavConstants.XML_DEPTH, DavConstants.NAMESPACE);
        boolean isShallow = "0".equals(depth);
        NodeIterator failed = getVersionManager().merge(item.getPath(), workspaceName, !mergeInfo.isNoAutoMerge(), isShallow);
        // add resources to the multistatus, that failed to be merged
        while (failed.hasNext()) {
            Node failedNode = failed.nextNode();
            DavResourceLocator loc = getLocatorFromItem(failedNode);
            DavResource res = createResourceFromLocator(loc);
            ms.addResponse(new MultiStatusResponse(res, mergeInfo.getPropertyNameSet()));
        }
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
    return ms;
}
Also used : NodeIterator(javax.jcr.NodeIterator) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) Node(javax.jcr.Node) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) RepositoryException(javax.jcr.RepositoryException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 47 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)

Example 48 with DavResource

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

the class AbstractWebdavServlet method doPut.

/**
 * The PUT method
 *
 * @param request
 * @param response
 * @param resource
 * @throws IOException
 * @throws DavException
 */
protected void doPut(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
    if (request.getHeader("Content-Range") != null) {
        response.sendError(DavServletResponse.SC_BAD_REQUEST, "Content-Range in PUT request not supported");
        return;
    }
    DavResource parentResource = resource.getCollection();
    if (parentResource == null || !parentResource.exists()) {
        // parent does not exist
        response.sendError(DavServletResponse.SC_CONFLICT);
        return;
    }
    int status;
    // test if resource already exists
    if (resource.exists()) {
        status = DavServletResponse.SC_NO_CONTENT;
    } else {
        status = DavServletResponse.SC_CREATED;
    }
    parentResource.addMember(resource, getInputContext(request, request.getInputStream()));
    response.setStatus(status);
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource)

Example 49 with DavResource

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

the class AbstractWebdavServlet method doBind.

/**
 * The BIND method
 *
 * @param request
 * @param response
 * @param resource the collection resource to which a new member will be added
 * @throws IOException
 * @throws DavException
 */
protected void doBind(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
    if (!resource.exists()) {
        response.sendError(DavServletResponse.SC_NOT_FOUND);
    }
    BindInfo bindInfo = request.getBindInfo();
    DavResource oldBinding = getResourceFactory().createResource(request.getHrefLocator(bindInfo.getHref()), request, response);
    if (!(oldBinding instanceof BindableResource)) {
        response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
        return;
    }
    DavResource newBinding = getResourceFactory().createResource(request.getMemberLocator(bindInfo.getSegment()), request, response);
    int status = validateDestination(newBinding, request, false);
    if (status > DavServletResponse.SC_NO_CONTENT) {
        response.sendError(status);
        return;
    }
    ((BindableResource) oldBinding).bind(resource, newBinding);
    response.setStatus(status);
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) BindableResource(org.apache.jackrabbit.webdav.bind.BindableResource) BindInfo(org.apache.jackrabbit.webdav.bind.BindInfo)

Example 50 with DavResource

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

the class AbstractWebdavServlet method doUnbind.

/**
 * The UNBIND method
 *
 * @param request
 * @param response
 * @param resource the collection resource from which a member will be removed
 * @throws IOException
 * @throws DavException
 */
protected void doUnbind(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
    UnbindInfo unbindInfo = request.getUnbindInfo();
    DavResource srcResource = getResourceFactory().createResource(request.getMemberLocator(unbindInfo.getSegment()), request, response);
    resource.removeMember(srcResource);
}
Also used : UnbindInfo(org.apache.jackrabbit.webdav.bind.UnbindInfo) DavResource(org.apache.jackrabbit.webdav.DavResource)

Aggregations

DavResource (org.apache.jackrabbit.webdav.DavResource)50 DavException (org.apache.jackrabbit.webdav.DavException)30 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)22 RepositoryException (javax.jcr.RepositoryException)16 ArrayList (java.util.ArrayList)9 Path (java.nio.file.Path)7 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)7 Node (javax.jcr.Node)6 VersionHistory (javax.jcr.version.VersionHistory)6 DavResourceIteratorImpl (org.apache.jackrabbit.webdav.DavResourceIteratorImpl)6 IOException (java.io.IOException)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 ManagedRepository (org.apache.archiva.repository.ManagedRepository)3 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)3