Search in sources :

Example 21 with DavPropertyNameSet

use of org.apache.jackrabbit.webdav.property.DavPropertyNameSet in project jackrabbit by apache.

the class RepositoryServiceImpl method update.

private void update(String uri, Path relPath, String[] updateSource, int updateType, boolean removeExisting, SessionInfo sessionInfo) throws RepositoryException {
    HttpUpdate request = null;
    try {
        UpdateInfo uInfo;
        String[] tmpUpdateSource = obtainAbsolutePathsFromUris(updateSource);
        if (removeExisting || relPath != null) {
            Element uElem = UpdateInfo.createUpdateElement(tmpUpdateSource, updateType, DomUtil.createDocument());
            if (removeExisting) {
                DomUtil.addChildElement(uElem, JcrRemotingConstants.XML_REMOVEEXISTING, ItemResourceConstants.NAMESPACE);
            }
            if (relPath != null) {
                DomUtil.addChildElement(uElem, JcrRemotingConstants.XML_RELPATH, ItemResourceConstants.NAMESPACE, getNamePathResolver(sessionInfo).getJCRPath(relPath));
            }
            uInfo = new UpdateInfo(uElem);
        } else {
            uInfo = new UpdateInfo(tmpUpdateSource, updateType, new DavPropertyNameSet());
        }
        request = new HttpUpdate(uri, uInfo);
        initMethod(request, sessionInfo, !isUnLockMethod(request));
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
    } 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 : HttpUpdate(org.apache.jackrabbit.webdav.client.methods.HttpUpdate) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) UpdateInfo(org.apache.jackrabbit.webdav.version.UpdateInfo)

Example 22 with DavPropertyNameSet

use of org.apache.jackrabbit.webdav.property.DavPropertyNameSet in project jackrabbit by apache.

the class RepositoryServiceImpl method getNodeInfo.

@Override
public NodeInfo getNodeInfo(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
    // set of properties to be retrieved
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(JcrRemotingConstants.JCR_INDEX_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_PARENT_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_NAME_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_PRIMARYNODETYPE_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_MIXINNODETYPES_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_REFERENCES_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_UUID_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_PATH_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(DavPropertyName.RESOURCETYPE);
    HttpPropfind request = null;
    try {
        String uri = getItemUri(nodeId, sessionInfo);
        request = new HttpPropfind(uri, nameSet, DEPTH_1);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (mresponses.length < 1) {
            throw new ItemNotFoundException("Unable to retrieve the node with id " + saveGetIdString(nodeId, sessionInfo));
        }
        MultiStatusResponse nodeResponse = null;
        List<MultiStatusResponse> childResponses = new ArrayList<MultiStatusResponse>();
        for (MultiStatusResponse mresponse : mresponses) {
            if (isSameResource(uri, mresponse)) {
                nodeResponse = mresponse;
            } else {
                childResponses.add(mresponse);
            }
        }
        if (nodeResponse == null) {
            throw new ItemNotFoundException("Unable to retrieve the node " + saveGetIdString(nodeId, sessionInfo));
        }
        DavPropertySet propSet = nodeResponse.getProperties(DavServletResponse.SC_OK);
        Object type = propSet.get(DavPropertyName.RESOURCETYPE).getValue();
        if (type == null) {
            // the given id points to a Property instead of a Node
            throw new ItemNotFoundException("No node for id " + saveGetIdString(nodeId, sessionInfo));
        }
        NamePathResolver resolver = getNamePathResolver(sessionInfo);
        NodeId parentId = getParentId(uri, propSet, sessionInfo);
        NodeInfoImpl nInfo = buildNodeInfo(uri, nodeResponse, parentId, propSet, sessionInfo, resolver);
        for (MultiStatusResponse resp : childResponses) {
            DavPropertySet childProps = resp.getProperties(DavServletResponse.SC_OK);
            if (childProps.contains(DavPropertyName.RESOURCETYPE) && childProps.get(DavPropertyName.RESOURCETYPE).getValue() != null) {
                // any other resource type than default (empty) is represented by a node item
                // --> build child info object
                nInfo.addChildInfo(buildChildInfo(childProps, sessionInfo));
            } else {
                PropertyId childId = uriResolver.buildPropertyId(nInfo.getId(), resp, sessionInfo.getWorkspaceName(), getNamePathResolver(sessionInfo));
                nInfo.addPropertyId(childId);
            }
        }
        return nInfo;
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } catch (NameException e) {
        throw new RepositoryException(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) PropertyId(org.apache.jackrabbit.spi.PropertyId) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) NodeId(org.apache.jackrabbit.spi.NodeId) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 23 with DavPropertyNameSet

use of org.apache.jackrabbit.webdav.property.DavPropertyNameSet in project jackrabbit by apache.

the class RepositoryServiceImpl method unregisterNodeTypes.

@Override
public void unregisterNodeTypes(SessionInfo sessionInfo, Name[] nodeTypeNames) throws RepositoryException {
    HttpProppatch request = null;
    try {
        DavPropertySet setProperties = new DavPropertySet();
        setProperties.add(createUnRegisterNodeTypesProperty(sessionInfo, nodeTypeNames));
        String uri = uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName());
        request = new HttpProppatch(uri, setProperties, new DavPropertyNameSet());
        initMethod(request, sessionInfo, true);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpProppatch(org.apache.jackrabbit.webdav.client.methods.HttpProppatch) DavException(org.apache.jackrabbit.webdav.DavException) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Example 24 with DavPropertyNameSet

use of org.apache.jackrabbit.webdav.property.DavPropertyNameSet in project jackrabbit by apache.

the class BindTest method getParentSet.

private DavProperty getParentSet(String uri) throws IOException, DavException, URISyntaxException {
    DavPropertyNameSet names = new DavPropertyNameSet();
    names.add(BindConstants.PARENTSET);
    HttpPropfind propfind = new HttpPropfind(uri, names, 0);
    HttpResponse response = this.client.execute(propfind, this.context);
    int status = response.getStatusLine().getStatusCode();
    assertEquals(207, status);
    MultiStatus multistatus = propfind.getResponseBodyAsMultiStatus(response);
    MultiStatusResponse[] responses = multistatus.getResponses();
    assertEquals(1, responses.length);
    DavProperty parentset = responses[0].getProperties(200).get(BindConstants.PARENTSET);
    assertNotNull(parentset);
    return parentset;
}
Also used : HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) HttpResponse(org.apache.http.HttpResponse) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus)

Example 25 with DavPropertyNameSet

use of org.apache.jackrabbit.webdav.property.DavPropertyNameSet in project jackrabbit by apache.

the class BindTest method getResourceId.

// utility methods
// see http://greenbytes.de/tech/webdav/rfc5842.html#rfc.section.3.1
private URI getResourceId(String uri) throws IOException, DavException, URISyntaxException {
    DavPropertyNameSet names = new DavPropertyNameSet();
    names.add(BindConstants.RESOURCEID);
    HttpPropfind propfind = new HttpPropfind(uri, names, 0);
    HttpResponse response = this.client.execute(propfind, this.context);
    int status = response.getStatusLine().getStatusCode();
    assertEquals(207, status);
    MultiStatus multistatus = propfind.getResponseBodyAsMultiStatus(response);
    MultiStatusResponse[] responses = multistatus.getResponses();
    assertEquals(1, responses.length);
    DavProperty resourceId = responses[0].getProperties(200).get(BindConstants.RESOURCEID);
    assertNotNull(resourceId);
    assertTrue(resourceId.getValue() instanceof Element);
    Element href = (Element) resourceId.getValue();
    assertEquals("href", href.getLocalName());
    String text = getUri(href);
    URI resid = new URI(text);
    return resid;
}
Also used : HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) ParentElement(org.apache.jackrabbit.webdav.bind.ParentElement) Element(org.w3c.dom.Element) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) HttpResponse(org.apache.http.HttpResponse) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) URI(java.net.URI)

Aggregations

DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)34 HttpResponse (org.apache.http.HttpResponse)19 RepositoryException (javax.jcr.RepositoryException)16 DavException (org.apache.jackrabbit.webdav.DavException)15 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)15 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)15 IOException (java.io.IOException)14 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)13 NodeId (org.apache.jackrabbit.spi.NodeId)9 ItemNotFoundException (javax.jcr.ItemNotFoundException)8 Batch (org.apache.jackrabbit.spi.Batch)6 MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)4 Element (org.w3c.dom.Element)4 Name (org.apache.jackrabbit.spi.Name)3 HttpProppatch (org.apache.jackrabbit.webdav.client.methods.HttpProppatch)3 DavPropertyName (org.apache.jackrabbit.webdav.property.DavPropertyName)3 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 PathNotFoundException (javax.jcr.PathNotFoundException)2