Search in sources :

Example 31 with DavResourceLocator

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

the class AbstractItemResource method getCollection.

/**
     * Returns the resource representing the parent item of the repository item
     * represented by this resource. If this resoure represents the root item
     * a {@link RootCollection} is returned.
     *
     * @return the collection this resource is internal member of. Except for the
     * repository root, the returned collection always represent the parent
     * repository node.
     * @see org.apache.jackrabbit.webdav.DavResource#getCollection()
     */
@Override
public DavResource getCollection() {
    DavResource collection = null;
    String parentPath = Text.getRelativeParent(getResourcePath(), 1);
    DavResourceLocator parentLoc = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), getLocator().getWorkspacePath(), parentPath);
    try {
        collection = createResourceFromLocator(parentLoc);
    } catch (DavException e) {
        log.error("Unexpected error while retrieving collection: " + e.getMessage());
    }
    return collection;
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 32 with DavResourceLocator

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

the class JcrRemotingServlet method canHandle.

private boolean canHandle(int methodCode, WebdavRequest request, DavResource davResource) {
    DavResourceLocator locator = davResource.getLocator();
    switch(methodCode) {
        case DavMethods.DAV_GET:
            return davResource.exists() && (locator instanceof WrappingLocator) && ((WrappingLocator) locator).isJsonRequest;
        case DavMethods.DAV_POST:
            String ct = request.getContentType();
            if (ct == null) {
                return false;
            } else {
                int semicolon = ct.indexOf(';');
                if (semicolon >= 0) {
                    ct = ct.substring(0, semicolon);
                }
                ct = ct.trim().toLowerCase(Locale.ENGLISH);
                return "multipart/form-data".equals(ct) || "application/x-www-form-urlencoded".equals(ct);
            }
        default:
            return false;
    }
}
Also used : DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 33 with DavResourceLocator

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

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

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