Search in sources :

Example 1 with ActivityResource

use of org.apache.jackrabbit.webdav.version.ActivityResource in project jackrabbit by apache.

the class LatestActivityVersionReport method init.

/**
     * Check all the preconditions for this report.
     *
     * @throws DavException if a precondition is not met.
     * @see Report#init(DavResource, ReportInfo)
     */
public void init(DavResource resource, ReportInfo info) throws DavException {
    // validate info
    if (!getType().isRequestedReportType(info)) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:latest-activity-version element expected.");
    }
    // make sure the report is applied to a vh-resource
    if (resource != null && (resource instanceof VersionHistoryResource)) {
        vhResource = (VersionHistoryResource) resource;
    } else {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:latest-activity-version report can only be created for a version history resource.");
    }
    // make sure the DAV:href element inside the request body points to
    // an activity resource (precondition for this report).
    String activityHref = DomUtil.getText(info.getContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE));
    DavResourceLocator vhLocator = resource.getLocator();
    DavResourceLocator activityLocator = vhLocator.getFactory().createResourceLocator(vhLocator.getPrefix(), activityHref);
    activity = resource.getFactory().createResource(activityLocator, resource.getSession());
    if (!(activity instanceof ActivityResource)) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:latest-activity-version report: The DAV:href in the request body MUST identify an activity.");
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) ActivityResource(org.apache.jackrabbit.webdav.version.ActivityResource) VersionHistoryResource(org.apache.jackrabbit.webdav.version.VersionHistoryResource) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 2 with ActivityResource

use of org.apache.jackrabbit.webdav.version.ActivityResource 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

ActivityResource (org.apache.jackrabbit.webdav.version.ActivityResource)2 DavException (org.apache.jackrabbit.webdav.DavException)1 DavResource (org.apache.jackrabbit.webdav.DavResource)1 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)1 VersionHistoryResource (org.apache.jackrabbit.webdav.version.VersionHistoryResource)1