Search in sources :

Example 1 with HttpMerge

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

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 RepositoryException (javax.jcr.RepositoryException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 HttpResponse (org.apache.http.HttpResponse)1 NodeId (org.apache.jackrabbit.spi.NodeId)1 DavException (org.apache.jackrabbit.webdav.DavException)1 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)1 HttpMerge (org.apache.jackrabbit.webdav.client.methods.HttpMerge)1 MergeInfo (org.apache.jackrabbit.webdav.version.MergeInfo)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1