Search in sources :

Example 11 with HrefProperty

use of org.apache.jackrabbit.webdav.property.HrefProperty 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 12 with HrefProperty

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

the class RepositoryServiceImpl method buildNodeInfo.

private NodeInfoImpl buildNodeInfo(String baseUri, MultiStatusResponse nodeResponse, NodeId parentId, DavPropertySet propSet, SessionInfo sessionInfo, NamePathResolver resolver) throws RepositoryException {
    NodeId id = uriResolver.buildNodeId(parentId, baseUri, nodeResponse, sessionInfo.getWorkspaceName(), getNamePathResolver(sessionInfo));
    NodeInfoImpl nInfo = new NodeInfoImpl(id, propSet, resolver);
    DavProperty p = propSet.get(JcrRemotingConstants.JCR_REFERENCES_LN, ItemResourceConstants.NAMESPACE);
    if (p != null) {
        HrefProperty refProp = new HrefProperty(p);
        for (String propertyHref : refProp.getHrefs()) {
            PropertyId propertyId = uriResolver.getPropertyId(propertyHref, sessionInfo);
            nInfo.addReference(propertyId);
        }
    }
    return nInfo;
}
Also used : HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) NodeId(org.apache.jackrabbit.spi.NodeId) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) PropertyId(org.apache.jackrabbit.spi.PropertyId)

Example 13 with HrefProperty

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

the class VersionHistoryResourceImpl method initProperties.

// --------------------------------------------------------------------------
/**
 * Fill the property set for this resource.
 */
@Override
protected void initProperties() {
    if (!propsInitialized) {
        super.initProperties();
        // change resource type defined by default item collection
        properties.add(new ResourceType(new int[] { ResourceType.COLLECTION, ResourceType.VERSION_HISTORY }));
        // required root-version property for version-history resource
        try {
            String rootVersionHref = getLocatorFromNode(((VersionHistory) getNode()).getRootVersion()).getHref(false);
            properties.add(new HrefProperty(VersionHistoryResource.ROOT_VERSION, rootVersionHref, false));
        } catch (RepositoryException e) {
            log.error(e.getMessage());
        }
        // required, protected version-set property for version-history resource
        try {
            VersionIterator vIter = ((VersionHistory) getNode()).getAllVersions();
            ArrayList<Version> l = new ArrayList<Version>();
            while (vIter.hasNext()) {
                l.add(vIter.nextVersion());
            }
            properties.add(getHrefProperty(VersionHistoryResource.VERSION_SET, l.toArray(new Version[l.size()]), true, false));
        } catch (RepositoryException e) {
            log.error(e.getMessage());
        }
    }
}
Also used : HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Version(javax.jcr.version.Version) ArrayList(java.util.ArrayList) VersionIterator(javax.jcr.version.VersionIterator) ResourceType(org.apache.jackrabbit.webdav.property.ResourceType) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory)

Example 14 with HrefProperty

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

the class VersionControlledResourceImpl method initProperties.

/**
 * Fill the property set for this resource.
 * @see DavResourceImpl#initProperties()
 */
@Override
protected void initProperties() {
    if (!propsInitialized) {
        super.initProperties();
        if (isVersionControlled()) {
            Node n = getNode();
            // properties defined by RFC 3253 for version-controlled resources
            try {
                // DAV:version-history (computed)
                String vhHref = getLocatorFromNode(n.getVersionHistory()).getHref(true);
                properties.add(new HrefProperty(VERSION_HISTORY, vhHref, true));
                // DAV:auto-version property: there is no auto version, explicit CHECKOUT is required.
                properties.add(new DefaultDavProperty(AUTO_VERSION, null, true));
                // baseVersion -> used for DAV:checked-out or DAV:checked-in
                String baseVHref = getLocatorFromNode(n.getBaseVersion()).getHref(false);
                if (n.isCheckedOut()) {
                    // DAV:predecessors property
                    if (n.hasProperty(JcrConstants.JCR_PREDECESSORS)) {
                        Value[] pv = n.getProperty(JcrConstants.JCR_PREDECESSORS).getValues();
                        Node[] predecessors = new Node[pv.length];
                        for (int i = 0; i < pv.length; i++) {
                            predecessors[i] = n.getSession().getNodeByIdentifier(pv[i].getString());
                        }
                        properties.add(getHrefProperty(VersionResource.PREDECESSOR_SET, predecessors, true, false));
                    }
                    // DAV:checked-out property (protected)
                    properties.add(new HrefProperty(CHECKED_OUT, baseVHref, true));
                } else {
                    // DAV:checked-in property (protected)
                    properties.add(new HrefProperty(CHECKED_IN, baseVHref, true));
                }
            } catch (RepositoryException e) {
                log.error(e.getMessage());
            }
        }
    }
}
Also used : DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Node(javax.jcr.Node) Value(javax.jcr.Value) RepositoryException(javax.jcr.RepositoryException)

Example 15 with HrefProperty

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

the class VersionResourceImpl method initProperties.

/**
 * Fill the property set for this resource.
 */
@Override
protected void initProperties() {
    if (!propsInitialized) {
        super.initProperties();
        Version v = (Version) getNode();
        try {
            String creationDate = HttpDateFormat.creationDateFormat().format(v.getCreated().getTime());
            // replace dummy creation date from default collection
            properties.add(new DefaultDavProperty<String>(DavPropertyName.CREATIONDATE, creationDate));
            // required, protected DAV:version-name property
            properties.add(new DefaultDavProperty<String>(VERSION_NAME, v.getName(), true));
            // required, protected DAV:label-name-set property
            String[] labels = getVersionHistoryItem().getVersionLabels(v);
            properties.add(new LabelSetProperty(labels));
            // required DAV:predecessor-set (protected) and DAV:successor-set (computed) properties
            properties.add(getHrefProperty(VersionResource.PREDECESSOR_SET, v.getPredecessors(), true, false));
            properties.add(getHrefProperty(SUCCESSOR_SET, v.getSuccessors(), true, false));
            // required DAV:version-history (computed) property
            String vhHref = getLocatorFromNode(getVersionHistoryItem()).getHref(true);
            properties.add(new HrefProperty(VersionResource.VERSION_HISTORY, vhHref, true));
            // required DAV:checkout-set (computed) property
            PropertyIterator it = v.getReferences();
            List<Node> nodeList = new ArrayList<Node>();
            while (it.hasNext()) {
                Property p = it.nextProperty();
                if (JcrConstants.JCR_BASEVERSION.equals(p.getName())) {
                    Node n = p.getParent();
                    if (n.isCheckedOut()) {
                        nodeList.add(n);
                    }
                }
            }
            properties.add(getHrefProperty(CHECKOUT_SET, nodeList.toArray(new Node[nodeList.size()]), true, false));
        } catch (RepositoryException e) {
            log.error(e.getMessage());
        }
    }
}
Also used : HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Version(javax.jcr.version.Version) LabelSetProperty(org.apache.jackrabbit.webdav.version.LabelSetProperty) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) LabelSetProperty(org.apache.jackrabbit.webdav.version.LabelSetProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty)

Aggregations

HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)20 RepositoryException (javax.jcr.RepositoryException)14 DavException (org.apache.jackrabbit.webdav.DavException)7 DefaultDavProperty (org.apache.jackrabbit.webdav.property.DefaultDavProperty)7 Node (javax.jcr.Node)6 DavProperty (org.apache.jackrabbit.webdav.property.DavProperty)6 ArrayList (java.util.ArrayList)5 IOException (java.io.IOException)4 Version (javax.jcr.version.Version)4 HttpResponse (org.apache.http.HttpResponse)4 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)4 Value (javax.jcr.Value)3 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)3 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)3 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)3 Property (javax.jcr.Property)2 PropertyIterator (javax.jcr.PropertyIterator)2 VersionHistory (javax.jcr.version.VersionHistory)2 VersionIterator (javax.jcr.version.VersionIterator)2 NodeId (org.apache.jackrabbit.spi.NodeId)2