Search in sources :

Example 1 with DavPropertySet

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

the class RepositoryServiceImpl method getPropertyInfo.

/**
     * @see RepositoryService#getPropertyInfo(SessionInfo, PropertyId)
     */
@Override
public PropertyInfo getPropertyInfo(SessionInfo sessionInfo, PropertyId propertyId) throws RepositoryException {
    Path p = getPath(propertyId, sessionInfo);
    String uri = getURI(p, sessionInfo);
    HttpPropfind request = null;
    try {
        request = new HttpPropfind(uri, LAZY_PROPERTY_NAME_SET, DavConstants.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 PropertyInfo. No such property " + uri);
        }
        MultiStatusResponse mresponse = mresponses[0];
        DavPropertySet props = mresponse.getProperties(DavServletResponse.SC_OK);
        int propertyType = PropertyType.valueFromName(props.get(JCR_TYPE).getValue().toString());
        if (propertyType == PropertyType.BINARY) {
            DavProperty<?> lengthsProp = props.get(JCR_LENGTHS);
            if (lengthsProp != null) {
                // multivalued binary property
                long[] lengths = ValueUtil.lengthsFromXml(lengthsProp.getValue());
                QValue[] qValues = new QValue[lengths.length];
                for (int i = 0; i < lengths.length; i++) {
                    qValues[i] = getQValueFactory(sessionInfo).create(lengths[i], uri, i);
                }
                return new PropertyInfoImpl(propertyId, p, propertyType, qValues);
            } else {
                // single valued binary property
                long length = Long.parseLong(props.get(JCR_LENGTH).getValue().toString());
                QValue qValue = getQValueFactory(sessionInfo).create(length, uri, QValueFactoryImpl.NO_INDEX);
                return new PropertyInfoImpl(propertyId, p, propertyType, qValue);
            }
        } else if (props.contains(JCR_GET_STRING)) {
            // single valued non-binary property
            Object v = props.get(JCR_GET_STRING).getValue();
            String str = (v == null) ? "" : v.toString();
            QValue qValue = ValueFormat.getQValue(str, propertyType, getNamePathResolver(sessionInfo), getQValueFactory(sessionInfo));
            return new PropertyInfoImpl(propertyId, p, propertyType, qValue);
        } else {
            // didn't expose the JCR_GET_STRING dav property.
            return super.getPropertyInfo(sessionInfo, propertyId);
        }
    } catch (IOException e) {
        log.error("Internal error while retrieving ItemInfo.", e);
        throw new RepositoryException(e.getMessage());
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) QValue(org.apache.jackrabbit.spi.QValue) 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) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 2 with DavPropertySet

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

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

the class URIResolverImpl method buildPropertyId.

PropertyId buildPropertyId(NodeId parentId, MultiStatusResponse response, String workspaceName, NamePathResolver resolver) throws RepositoryException {
    IdURICache cache = getCache(workspaceName);
    if (cache.containsUri(response.getHref())) {
        ItemId id = cache.getItemId(response.getHref());
        if (!id.denotesNode()) {
            return (PropertyId) id;
        }
    }
    try {
        DavPropertySet propSet = response.getProperties(DavServletResponse.SC_OK);
        Name name = resolver.getQName(propSet.get(JcrRemotingConstants.JCR_NAME_LN, ItemResourceConstants.NAMESPACE).getValue().toString());
        PropertyId propertyId = service.getIdFactory().createPropertyId(parentId, name);
        cache.add(response.getHref(), propertyId);
        return propertyId;
    } catch (NameException e) {
        throw new RepositoryException(e);
    }
}
Also used : DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) RepositoryException(javax.jcr.RepositoryException) ItemId(org.apache.jackrabbit.spi.ItemId) PropertyId(org.apache.jackrabbit.spi.PropertyId) Name(org.apache.jackrabbit.spi.Name)

Example 4 with DavPropertySet

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

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

the class URIResolverImpl method buildNodeId.

protected NodeId buildNodeId(NodeId parentId, String baseUri, MultiStatusResponse response, String workspaceName, NamePathResolver resolver) throws RepositoryException {
    IdURICache cache = getCache(workspaceName);
    NodeId nodeId;
    DavPropertySet propSet = response.getProperties(DavServletResponse.SC_OK);
    String uniqueID = service.getUniqueID(propSet);
    if (uniqueID != null) {
        nodeId = service.getIdFactory().createNodeId(uniqueID);
    } else {
        Name qName = service.getQName(propSet, resolver);
        if (NameConstants.ROOT.equals(qName)) {
            nodeId = service.getIdFactory().createNodeId((String) null, service.getPathFactory().getRootPath());
        } else {
            int index = service.getIndex(propSet);
            nodeId = service.getIdFactory().createNodeId(parentId, service.getPathFactory().create(qName, index));
        }
    }
    // cache
    cache.add(resolve(baseUri, response.getHref()), nodeId);
    return nodeId;
}
Also used : DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) NodeId(org.apache.jackrabbit.spi.NodeId) Name(org.apache.jackrabbit.spi.Name)

Aggregations

DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)20 RepositoryException (javax.jcr.RepositoryException)14 HttpResponse (org.apache.http.HttpResponse)14 DavException (org.apache.jackrabbit.webdav.DavException)13 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)13 IOException (java.io.IOException)11 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)11 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)11 ItemNotFoundException (javax.jcr.ItemNotFoundException)8 NodeId (org.apache.jackrabbit.spi.NodeId)3 PropertyId (org.apache.jackrabbit.spi.PropertyId)3 HttpProppatch (org.apache.jackrabbit.webdav.client.methods.HttpProppatch)3 LockDiscovery (org.apache.jackrabbit.webdav.lock.LockDiscovery)3 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)3 ArrayList (java.util.ArrayList)2 Name (org.apache.jackrabbit.spi.Name)2 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)2 NamePathResolver (org.apache.jackrabbit.spi.commons.conversion.NamePathResolver)2 CodedUrlHeader (org.apache.jackrabbit.webdav.header.CodedUrlHeader)2 Element (org.w3c.dom.Element)2