Search in sources :

Example 1 with DavPropertyNameSet

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

the class ValueLoader method loadType.

int loadType(String uri) throws RepositoryException, IOException {
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
    HttpPropfind request = null;
    try {
        request = new HttpPropfind(uri, nameSet, DavConstants.DEPTH_0);
        HttpResponse response = client.execute(request, context);
        request.checkSuccess(response);
        MultiStatusResponse[] responses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (responses.length == 1) {
            DavPropertySet props = responses[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 " + uri);
            }
        } else {
            throw new ItemNotFoundException("Internal error. Cannot retrieve property type at " + uri);
        }
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) DavException(org.apache.jackrabbit.webdav.DavException) 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)

Example 2 with DavPropertyNameSet

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

the class URIResolverImpl method getNodeId.

private NodeId getNodeId(String uri, SessionInfo sessionInfo, boolean nodeIsGone) throws RepositoryException {
    IdURICache cache = getCache(sessionInfo.getWorkspaceName());
    if (cache.containsUri(uri)) {
        // id has been accessed before and is cached
        ItemId id = cache.getItemId(uri);
        if (id.denotesNode()) {
            return (NodeId) id;
        }
    }
    if (nodeIsGone) {
        throw new RepositoryException("Can't reconstruct nodeId from URI when the remote node is gone.");
    }
    // retrieve parentId from cache or by recursive calls
    NodeId parentId;
    if (isSameURI(uri, getRootItemUri(sessionInfo.getWorkspaceName()))) {
        parentId = null;
    } else {
        String parentUri = Text.getRelativeParent(uri, 1, true);
        parentId = getNodeId(parentUri, sessionInfo, false);
    }
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(JcrRemotingConstants.JCR_UUID_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_NAME_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_INDEX_LN, ItemResourceConstants.NAMESPACE);
    HttpPropfind request = null;
    try {
        request = new HttpPropfind(uri, nameSet, DavConstants.DEPTH_0);
        HttpResponse response = service.executeRequest(sessionInfo, request);
        MultiStatusResponse[] responses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (responses.length != 1) {
            throw new ItemNotFoundException("Unable to retrieve the node with id " + uri);
        }
        return buildNodeId(parentId, uri, responses[0], sessionInfo.getWorkspaceName(), service.getNamePathResolver(sessionInfo));
    } 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) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ItemId(org.apache.jackrabbit.spi.ItemId) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) NodeId(org.apache.jackrabbit.spi.NodeId) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 3 with DavPropertyNameSet

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

the class RepositoryServiceImpl method getReferences.

@Override
public Iterator<PropertyId> getReferences(SessionInfo sessionInfo, NodeId nodeId, Name propertyName, boolean weakReferences) throws RepositoryException {
    // set of properties to be retrieved
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    String refType = weakReferences ? JcrRemotingConstants.JCR_WEAK_REFERENCES_LN : JcrRemotingConstants.JCR_REFERENCES_LN;
    nameSet.add(refType, ItemResourceConstants.NAMESPACE);
    HttpPropfind request = null;
    try {
        String uri = getItemUri(nodeId, sessionInfo);
        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 ItemNotFoundException("Unable to retrieve the node with id " + saveGetIdString(nodeId, sessionInfo));
        }
        List<PropertyId> refIds = Collections.emptyList();
        for (MultiStatusResponse mresponse : mresponses) {
            if (isSameResource(uri, mresponse)) {
                DavPropertySet props = mresponse.getProperties(DavServletResponse.SC_OK);
                DavProperty<?> p = props.get(refType, ItemResourceConstants.NAMESPACE);
                if (p != null) {
                    refIds = new ArrayList<PropertyId>();
                    HrefProperty hp = new HrefProperty(p);
                    for (String propHref : hp.getHrefs()) {
                        PropertyId propId = uriResolver.getPropertyId(resolve(uri, propHref), sessionInfo);
                        if (propertyName == null || propertyName.equals(propId.getName())) {
                            refIds.add(propId);
                        }
                    }
                }
            }
        }
        return refIds.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) 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) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 4 with DavPropertyNameSet

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

the class DavPropertyTest method testCheckedInVersionableNode.

public void testCheckedInVersionableNode() throws Exception {
    NodeId nid = getNodeId("/test");
    Batch b = rs.createBatch(si, nid);
    b.setMixins(nid, new Name[] { NameConstants.MIX_VERSIONABLE });
    rs.submit(b);
    rs.checkin(si, nid);
    String uri = rs.getItemUri(nid, si);
    DavPropertyNameSet set = doPropFindNames(uri);
    DavPropertyNameSet expected = new DavPropertyNameSet(BASE_SET);
    expected.addAll(EXISTING_ITEM_BASE_SET);
    expected.addAll(NODE_SET);
    expected.addAll(VERSIONABLE_SET);
    expected.add(OrderingConstants.ORDERING_TYPE);
    expected.add(JCR_PARENT);
    expected.add(JCR_UUID);
    expected.add(VersionControlledResource.CHECKED_IN);
    /*
         Expected property names

        {DAV:}getlastmodified
        {DAV:}ordering-type
        {http://www.day.com/jcr/webdav/1.0}definition
        {DAV:}comment
        {http://www.day.com/jcr/webdav/1.0}references
        {http://www.day.com/jcr/webdav/1.0}parent
        {DAV:}displayname
        {http://www.day.com/jcr/webdav/1.0}workspaceName
        {http://www.day.com/jcr/webdav/1.0}subscriptiondiscovery
        {http://www.day.com/jcr/webdav/1.0}uuid
        {DAV:}checked-in
        {http://www.day.com/jcr/webdav/1.0}name
        {DAV:}current-user-privilege-set
        {http://www.day.com/jcr/webdav/1.0}primarynodetype
        {DAV:}version-history
        {DAV:}lockdiscovery
        {DAV:}resourcetype
        {DAV:}workspace
        {http://www.day.com/jcr/webdav/1.0}depth
        {http://www.day.com/jcr/webdav/1.0}index
        {DAV:}supportedlock
        {DAV:}supported-method-set
        {DAV:}iscollection
        {http://www.day.com/jcr/webdav/1.0}weakreferences
        {DAV:}creator-displayname
        {DAV:}getcontenttype
        {DAV:}creationdate
        {DAV:}supported-report-set
        {DAV:}auto-version
        {http://www.day.com/jcr/webdav/1.0}mixinnodetypes
        {http://www.day.com/jcr/webdav/1.0}path
        */
    assertPropertyNames(expected, set);
    DavPropertyNameSet all = doPropFindAll(uri);
    expected.remove(DeltaVConstants.COMMENT);
    expected.remove(DeltaVConstants.CREATOR_DISPLAYNAME);
    expected.remove(DeltaVConstants.SUPPORTED_METHOD_SET);
    expected.remove(DeltaVConstants.SUPPORTED_REPORT_SET);
    expected.remove(DeltaVConstants.WORKSPACE);
    expected.remove(OrderingConstants.ORDERING_TYPE);
    expected.remove(SecurityConstants.CURRENT_USER_PRIVILEGE_SET);
    expected.remove(ObservationConstants.SUBSCRIPTIONDISCOVERY);
    expected.remove(JCR_DEFINITION);
    expected.remove(JCR_INDEX);
    expected.remove(JCR_REFERENCES);
    expected.remove(JCR_WEAK_REFERENCES);
    expected.remove(JCR_UUID);
    expected.remove(VersionControlledResource.CHECKED_IN);
    expected.remove(VersionControlledResource.VERSION_HISTORY);
    /*
        Expected all-props

        {DAV:}getlastmodified
        {DAV:}getlastmodified
        {http://www.day.com/jcr/webdav/1.0}depth
        {http://www.day.com/jcr/webdav/1.0}workspaceName
        {DAV:}displayname
        {http://www.day.com/jcr/webdav/1.0}parent
        {DAV:}supportedlock
        {DAV:}iscollection
        {DAV:}getcontenttype
        {http://www.day.com/jcr/webdav/1.0}name
        {DAV:}creationdate
        {DAV:}auto-version
        {http://www.day.com/jcr/webdav/1.0}mixinnodetypes
        {http://www.day.com/jcr/webdav/1.0}path
        {http://www.day.com/jcr/webdav/1.0}primarynodetype
        {DAV:}lockdiscovery
        {DAV:}resourcetype
         */
    assertPropertyNames(expected, all);
    DavPropertyNameSet props = new DavPropertyNameSet();
    props.add(DeltaVConstants.COMMENT);
    props.add(DeltaVConstants.CREATOR_DISPLAYNAME);
    props.add(DeltaVConstants.SUPPORTED_METHOD_SET);
    props.add(DeltaVConstants.SUPPORTED_REPORT_SET);
    props.add(DeltaVConstants.WORKSPACE);
    props.add(OrderingConstants.ORDERING_TYPE);
    props.add(SecurityConstants.CURRENT_USER_PRIVILEGE_SET);
    props.add(ObservationConstants.SUBSCRIPTIONDISCOVERY);
    props.add(JCR_DEFINITION);
    props.add(JCR_INDEX);
    props.add(JCR_REFERENCES);
    props.add(JCR_WEAK_REFERENCES);
    props.add(JCR_UUID);
    props.add(VersionControlledResource.CHECKED_IN);
    props.add(VersionControlledResource.VERSION_HISTORY);
    DavPropertyNameSet result = doPropFindByProp(uri, props);
    assertPropertyNames(props, result);
}
Also used : Batch(org.apache.jackrabbit.spi.Batch) NodeId(org.apache.jackrabbit.spi.NodeId) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet)

Example 5 with DavPropertyNameSet

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

the class DavPropertyTest method testReferenceableNode.

public void testReferenceableNode() throws Exception {
    NodeId nid = getNodeId("/test");
    Batch b = rs.createBatch(si, nid);
    b.setMixins(nid, new Name[] { NameConstants.MIX_REFERENCEABLE });
    rs.submit(b);
    String uri = rs.getItemUri(nid, si);
    DavPropertyNameSet set = doPropFindNames(uri);
    DavPropertyNameSet expected = new DavPropertyNameSet(BASE_SET);
    expected.addAll(EXISTING_ITEM_BASE_SET);
    expected.addAll(NODE_SET);
    expected.add(OrderingConstants.ORDERING_TYPE);
    expected.add(JCR_PARENT);
    expected.add(JCR_UUID);
    /*
         Expected property names

        {DAV:}getlastmodified
        {DAV:}ordering-type
        {http://www.day.com/jcr/webdav/1.0}definition
        {DAV:}comment
        {http://www.day.com/jcr/webdav/1.0}references
        {http://www.day.com/jcr/webdav/1.0}parent
        {DAV:}displayname
        {http://www.day.com/jcr/webdav/1.0}workspaceName
        {http://www.day.com/jcr/webdav/1.0}subscriptiondiscovery
        {http://www.day.com/jcr/webdav/1.0}uuid
        {http://www.day.com/jcr/webdav/1.0}name
        {DAV:}current-user-privilege-set
        {http://www.day.com/jcr/webdav/1.0}primarynodetype
        {DAV:}lockdiscovery
        {DAV:}resourcetype
        {DAV:}workspace
        {http://www.day.com/jcr/webdav/1.0}depth
        {http://www.day.com/jcr/webdav/1.0}index
        {DAV:}supportedlock
        {DAV:}supported-method-set
        {DAV:}iscollection
        {http://www.day.com/jcr/webdav/1.0}weakreferences
        {DAV:}creator-displayname
        {DAV:}getcontenttype
        {DAV:}creationdate
        {DAV:}supported-report-set
        {http://www.day.com/jcr/webdav/1.0}mixinnodetypes
        {http://www.day.com/jcr/webdav/1.0}path
        */
    assertPropertyNames(expected, set);
    DavPropertyNameSet all = doPropFindAll(uri);
    expected.remove(DeltaVConstants.COMMENT);
    expected.remove(DeltaVConstants.CREATOR_DISPLAYNAME);
    expected.remove(DeltaVConstants.SUPPORTED_METHOD_SET);
    expected.remove(DeltaVConstants.SUPPORTED_REPORT_SET);
    expected.remove(DeltaVConstants.WORKSPACE);
    expected.remove(SecurityConstants.CURRENT_USER_PRIVILEGE_SET);
    expected.remove(ObservationConstants.SUBSCRIPTIONDISCOVERY);
    expected.remove(OrderingConstants.ORDERING_TYPE);
    expected.remove(JCR_DEFINITION);
    expected.remove(JCR_INDEX);
    expected.remove(JCR_REFERENCES);
    expected.remove(JCR_WEAK_REFERENCES);
    expected.remove(JCR_UUID);
    /*
        Expected all-props

        {DAV:}getlastmodified
        {http://www.day.com/jcr/webdav/1.0}depth
        {http://www.day.com/jcr/webdav/1.0}workspaceName
        {DAV:}displayname
        {http://www.day.com/jcr/webdav/1.0}parent
        {DAV:}supportedlock
        {DAV:}iscollection
        {DAV:}getcontenttype
        {http://www.day.com/jcr/webdav/1.0}name
        {DAV:}creationdate
        {http://www.day.com/jcr/webdav/1.0}mixinnodetypes
        {http://www.day.com/jcr/webdav/1.0}path
        {http://www.day.com/jcr/webdav/1.0}primarynodetype
        {DAV:}lockdiscovery
        {DAV:}resourcetype
         */
    assertPropertyNames(expected, all);
    DavPropertyNameSet props = new DavPropertyNameSet();
    props.add(DeltaVConstants.COMMENT);
    props.add(DeltaVConstants.CREATOR_DISPLAYNAME);
    props.add(DeltaVConstants.SUPPORTED_METHOD_SET);
    props.add(DeltaVConstants.SUPPORTED_REPORT_SET);
    props.add(DeltaVConstants.WORKSPACE);
    props.add(SecurityConstants.CURRENT_USER_PRIVILEGE_SET);
    props.add(ObservationConstants.SUBSCRIPTIONDISCOVERY);
    props.add(OrderingConstants.ORDERING_TYPE);
    props.add(JCR_DEFINITION);
    props.add(JCR_INDEX);
    props.add(JCR_REFERENCES);
    props.add(JCR_WEAK_REFERENCES);
    props.add(JCR_UUID);
    DavPropertyNameSet result = doPropFindByProp(uri, props);
    assertPropertyNames(props, result);
}
Also used : Batch(org.apache.jackrabbit.spi.Batch) NodeId(org.apache.jackrabbit.spi.NodeId) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet)

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