Search in sources :

Example 31 with DavResource

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

the class AclPrincipalReport method init.

/**
     * @see Report#init(DavResource, ReportInfo)
     */
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
    super.init(resource, info);
    // build the DAV:responses objects.
    DavProperty<?> acl = resource.getProperty(SecurityConstants.ACL);
    if (!(acl instanceof AclProperty)) {
        throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "DAV:acl property expected.");
    }
    DavResourceLocator loc = resource.getLocator();
    Map<String, MultiStatusResponse> respMap = new HashMap<String, MultiStatusResponse>();
    List<AclProperty.Ace> list = (List<AclProperty.Ace>) ((AclProperty) acl).getValue();
    for (AclProperty.Ace ace : list) {
        String href = ace.getPrincipal().getHref();
        if (href == null || respMap.containsKey(href)) {
            // ignore non-href principals and principals that have been listed before
            continue;
        }
        // href-principal that has not been found before
        DavResourceLocator princLocator = loc.getFactory().createResourceLocator(loc.getPrefix(), href);
        DavResource principalResource = resource.getFactory().createResource(princLocator, resource.getSession());
        respMap.put(href, new MultiStatusResponse(principalResource, info.getPropertyNameSet()));
    }
    this.responses = respMap.values().toArray(new MultiStatusResponse[respMap.size()]);
}
Also used : AclProperty(org.apache.jackrabbit.webdav.security.AclProperty) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) HashMap(java.util.HashMap) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) List(java.util.List) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

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

Example 33 with DavResource

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

the class CompareBaselineReport method init.

/**
     *
     * @param resource
     * @param info
     * @throws DavException
     * @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:compare-baseline element expected.");
    }
    // make sure the report is applied to a version history resource
    if (resource != null && (resource instanceof BaselineResource)) {
        this.requestBaseline = (BaselineResource) resource;
    } else {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:compare-baseline report can only be created for a baseline resource.");
    }
    // make sure the DAV:href element inside the request body points to
    // an baseline resource (precondition for this report).
    String compareHref = DomUtil.getText(info.getContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE));
    DavResourceLocator locator = resource.getLocator();
    DavResourceLocator compareLocator = locator.getFactory().createResourceLocator(locator.getPrefix(), compareHref);
    DavResource compRes = resource.getFactory().createResource(compareLocator, resource.getSession());
    if (compRes instanceof BaselineResource) {
        compareBaseline = (BaselineResource) compRes;
    } else {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:latest-activity-version report: The DAV:href in the request body MUST identify an activity.");
    }
// TODO: eventually add check for 'same-baseline-history' (RFC: "A server MAY require that the baselines being compared be from the same baseline history.")
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) BaselineResource(org.apache.jackrabbit.webdav.version.BaselineResource) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 34 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 35 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 {
    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)

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