Search in sources :

Example 6 with MultiStatusResponse

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

the class ExpandPropertyReport method getResponse.

/**
     * Builds a <code>MultiStatusResponse</code> for the given resource respecting
     * the properties specified. Any property that represents a {@link HrefProperty}
     * is expanded: It's name equals the name of a valid {@link HrefProperty}.
     * However the value of that given property (consisting of one or multiple DAV:href elements)
     * is replaced by the Xml representation of a separate
     * {@link MultiStatusResponse multistatus responses} for the
     * resource referenced by the given DAV:href elements. The responses may
     * themselves have properties, which are defined by the separate list.
     *
     * @param res
     * @param propertyElements
     * @return <code>MultiStatusResponse</code> for the given resource.
     * @see ExpandProperty
     */
private MultiStatusResponse getResponse(DavResource res, Iterator<Element> propertyElements) {
    MultiStatusResponse resp = new MultiStatusResponse(res.getHref(), null);
    while (propertyElements.hasNext()) {
        Element propertyElem = propertyElements.next();
        // retrieve the localName present in the "name" attribute
        String nameAttr = propertyElem.getAttribute(ATTR_NAME);
        if (nameAttr == null || "".equals(nameAttr)) {
            // NOTE: this is not valid according to the DTD
            continue;
        }
        // retrieve the namespace present in the "namespace" attribute
        // NOTE: if this attribute is missing the DAV: namespace represents the default.
        String namespaceAttr = propertyElem.getAttribute(ATTR_NAMESPACE);
        Namespace namespace = (namespaceAttr != null) ? Namespace.getNamespace(namespaceAttr) : NAMESPACE;
        DavPropertyName propName = DavPropertyName.create(nameAttr, namespace);
        DavProperty<?> p = res.getProperty(propName);
        if (p != null) {
            if (p instanceof HrefProperty && res instanceof DeltaVResource) {
                ElementIterator it = DomUtil.getChildren(propertyElem, XML_PROPERTY, NAMESPACE);
                resp.add(new ExpandProperty((DeltaVResource) res, (HrefProperty) p, it));
            } else {
                resp.add(p);
            }
        } else {
            resp.add(propName, DavServletResponse.SC_NOT_FOUND);
        }
    }
    return resp;
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Element(org.w3c.dom.Element) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) DeltaVResource(org.apache.jackrabbit.webdav.version.DeltaVResource) Namespace(org.apache.jackrabbit.webdav.xml.Namespace) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName)

Example 7 with MultiStatusResponse

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

the class RepositoryServiceImpl method internalGetPrivilegeDefinitions.

private PrivilegeDefinition[] internalGetPrivilegeDefinitions(SessionInfo sessionInfo, String uri) throws RepositoryException {
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(SecurityConstants.SUPPORTED_PRIVILEGE_SET);
    HttpPropfind request = null;
    try {
        request = new HttpPropfind(uri, nameSet, DEPTH_0);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (mresponses.length < 1) {
            throw new PathNotFoundException("Unable to retrieve privileges definitions.");
        }
        DavPropertyName displayName = SecurityConstants.SUPPORTED_PRIVILEGE_SET;
        DavProperty<?> p = mresponses[0].getProperties(DavServletResponse.SC_OK).get(displayName);
        if (p == null) {
            return new PrivilegeDefinition[0];
        } else {
            // build PrivilegeDefinition(s) from the supported-privileges dav property
            Map<Name, SupportedPrivilege> spMap = new HashMap<Name, SupportedPrivilege>();
            fillSupportedPrivilegeMap(new SupportedPrivilegeSetProperty(p).getValue(), spMap, getNameFactory());
            List<PrivilegeDefinition> pDefs = new ArrayList<PrivilegeDefinition>();
            for (Name privilegeName : spMap.keySet()) {
                SupportedPrivilege sp = spMap.get(privilegeName);
                Set<Name> aggrnames = null;
                SupportedPrivilege[] aggregates = sp.getSupportedPrivileges();
                if (aggregates != null && aggregates.length > 0) {
                    aggrnames = new HashSet<Name>();
                    for (SupportedPrivilege aggregate : aggregates) {
                        Name aggregateName = nameFactory.create(aggregate.getPrivilege().getNamespace().getURI(), aggregate.getPrivilege().getName());
                        aggrnames.add(aggregateName);
                    }
                }
                PrivilegeDefinition def = new PrivilegeDefinitionImpl(privilegeName, sp.isAbstract(), aggrnames);
                pDefs.add(def);
            }
            return pDefs.toArray(new PrivilegeDefinition[pDefs.size()]);
        }
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) PrivilegeDefinition(org.apache.jackrabbit.spi.PrivilegeDefinition) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) Name(org.apache.jackrabbit.spi.Name) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) PrivilegeDefinitionImpl(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) SupportedPrivilegeSetProperty(org.apache.jackrabbit.webdav.security.SupportedPrivilegeSetProperty) PathNotFoundException(javax.jcr.PathNotFoundException) SupportedPrivilege(org.apache.jackrabbit.webdav.security.SupportedPrivilege)

Example 8 with MultiStatusResponse

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

the class RepositoryServiceImpl method getChildInfos.

@Override
public Iterator<ChildInfo> getChildInfos(SessionInfo sessionInfo, NodeId parentId) throws RepositoryException {
    // set of properties to be retrieved
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(JcrRemotingConstants.JCR_NAME_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_INDEX_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_PARENT_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_UUID_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(DavPropertyName.RESOURCETYPE);
    HttpPropfind request = null;
    try {
        String uri = getItemUri(parentId, sessionInfo);
        request = new HttpPropfind(uri, nameSet, DEPTH_1);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        List<ChildInfo> childEntries;
        MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (mresponses.length < 1) {
            throw new ItemNotFoundException("Unable to retrieve the node with id " + saveGetIdString(parentId, sessionInfo));
        } else if (mresponses.length == 1) {
            // no child nodes nor properties
            childEntries = Collections.emptyList();
            return childEntries.iterator();
        }
        childEntries = new ArrayList<ChildInfo>();
        for (MultiStatusResponse mresponse : mresponses) {
            if (!isSameResource(uri, mresponse)) {
                DavPropertySet childProps = mresponse.getProperties(DavServletResponse.SC_OK);
                if (childProps.contains(DavPropertyName.RESOURCETYPE) && childProps.get(DavPropertyName.RESOURCETYPE).getValue() != null) {
                    childEntries.add(buildChildInfo(childProps, sessionInfo));
                }
            // else: property -> ignore
            }
        // else: ignore the response related to the parent
        }
        return childEntries.iterator();
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) HttpResponse(org.apache.http.HttpResponse) ChildInfo(org.apache.jackrabbit.spi.ChildInfo) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 9 with MultiStatusResponse

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

the class RepositoryServiceImpl method merge.

@Override
public Iterator<NodeId> merge(SessionInfo sessionInfo, NodeId nodeId, String srcWorkspaceName, boolean bestEffort, boolean isShallow) throws RepositoryException {
    HttpMerge request = null;
    try {
        Document doc = DomUtil.createDocument();
        String wspHref = obtainAbsolutePathFromUri(uriResolver.getWorkspaceUri(srcWorkspaceName));
        Element mElem = MergeInfo.createMergeElement(new String[] { wspHref }, !bestEffort, false, doc);
        if (isShallow) {
            mElem.appendChild(DomUtil.depthToXml(false, doc));
        }
        MergeInfo mInfo = new MergeInfo(mElem);
        String uri = getItemUri(nodeId, sessionInfo);
        request = new HttpMerge(uri, mInfo);
        initMethod(request, sessionInfo, !isUnLockMethod(request));
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatusResponse[] resps = request.getResponseBodyAsMultiStatus(response).getResponses();
        List<NodeId> failedIds = new ArrayList<NodeId>(resps.length);
        for (MultiStatusResponse resp : resps) {
            String href = resolve(uri, resp.getHref());
            failedIds.add(uriResolver.getNodeId(href, sessionInfo));
        }
        return failedIds.iterator();
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (ParserConfigurationException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : MergeInfo(org.apache.jackrabbit.webdav.version.MergeInfo) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) Document(org.w3c.dom.Document) HttpMerge(org.apache.jackrabbit.webdav.client.methods.HttpMerge) NodeId(org.apache.jackrabbit.spi.NodeId) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 10 with MultiStatusResponse

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

the class RepositoryServiceImpl method loadType.

private int loadType(String propertyURI, HttpClient client, PropertyId propertyId, SessionInfo sessionInfo, NamePathResolver resolver) throws IOException, DavException, RepositoryException {
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
    HttpPropfind request = null;
    try {
        request = new HttpPropfind(propertyURI, nameSet, DEPTH_0);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (mresponses.length == 1) {
            DavPropertySet props = mresponses[0].getProperties(DavServletResponse.SC_OK);
            DavProperty<?> type = props.get(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
            if (type != null) {
                return PropertyType.valueFromName(type.getValue().toString());
            } else {
                throw new RepositoryException("Internal error. Cannot retrieve property type at " + saveGetIdString(propertyId, resolver));
            }
        } else {
            throw new ItemNotFoundException("Internal error. Cannot retrieve property type at " + saveGetIdString(propertyId, resolver));
        }
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Aggregations

MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)27 RepositoryException (javax.jcr.RepositoryException)18 HttpResponse (org.apache.http.HttpResponse)18 DavException (org.apache.jackrabbit.webdav.DavException)17 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)16 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)15 IOException (java.io.IOException)13 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)11 ItemNotFoundException (javax.jcr.ItemNotFoundException)10 ArrayList (java.util.ArrayList)5 MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)5 NodeId (org.apache.jackrabbit.spi.NodeId)4 DavProperty (org.apache.jackrabbit.webdav.property.DavProperty)4 DavPropertyName (org.apache.jackrabbit.webdav.property.DavPropertyName)4 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)4 Element (org.w3c.dom.Element)4 HashSet (java.util.HashSet)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 CurrentUserPrivilegeSetProperty (org.apache.jackrabbit.webdav.security.CurrentUserPrivilegeSetProperty)3 Privilege (org.apache.jackrabbit.webdav.security.Privilege)3