Search in sources :

Example 26 with PropertyInfo

use of org.apache.jackrabbit.spi.PropertyInfo in project jackrabbit by apache.

the class RepositoryServiceImpl method getItemInfos.

/**
     * @see RepositoryService#getItemInfos(SessionInfo, ItemId)
     */
@Override
public Iterator<? extends ItemInfo> getItemInfos(SessionInfo sessionInfo, ItemId itemId) throws RepositoryException {
    if (!itemId.denotesNode()) {
        PropertyInfo propertyInfo = getPropertyInfo(sessionInfo, (PropertyId) itemId);
        return Iterators.singleton(propertyInfo);
    } else {
        NodeId nodeId = (NodeId) itemId;
        Path path = getPath(itemId, sessionInfo);
        String uri = getURI(path, sessionInfo);
        int depth = batchReadConfig.getDepth(path, this.getNamePathResolver(sessionInfo));
        HttpGet request = new HttpGet(uri + "." + depth + ".json");
        HttpResponse response = null;
        try {
            response = executeRequest(sessionInfo, request);
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == DavServletResponse.SC_OK) {
                HttpEntity entity = response.getEntity();
                if (entity.getContentLength() == 0) {
                    // no JSON response -> no such node on the server
                    throw new ItemNotFoundException("No such item " + nodeId);
                }
                NamePathResolver resolver = getNamePathResolver(sessionInfo);
                NodeInfoImpl nInfo = new NodeInfoImpl(nodeId, path);
                ItemInfoJsonHandler handler = new ItemInfoJsonHandler(resolver, nInfo, getRootURI(sessionInfo), getQValueFactory(sessionInfo), getPathFactory(), getIdFactory());
                JsonParser ps = new JsonParser(handler);
                ps.parse(entity.getContent(), ContentType.get(entity).getCharset().name());
                Iterator<? extends ItemInfo> it = handler.getItemInfos();
                if (!it.hasNext()) {
                    throw new ItemNotFoundException("No such node " + uri);
                }
                return handler.getItemInfos();
            } else {
                throw ExceptionConverter.generate(new DavException(statusCode, "Unable to retrieve NodeInfo for " + uri), request);
            }
        } catch (IOException e) {
            log.error("Internal error while retrieving NodeInfo.", e);
            throw new RepositoryException(e.getMessage());
        } finally {
            request.releaseConnection();
        }
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) HttpEntity(org.apache.http.HttpEntity) DavException(org.apache.jackrabbit.webdav.DavException) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) ItemNotFoundException(javax.jcr.ItemNotFoundException) JsonParser(org.apache.jackrabbit.commons.json.JsonParser)

Example 27 with PropertyInfo

use of org.apache.jackrabbit.spi.PropertyInfo in project jackrabbit by apache.

the class RepositoryServiceImpl method buildPropertyInfos.

private List<PropertyInfo> buildPropertyInfos(NodeInfo nInfo) throws RepositoryException {
    List<PropertyInfo> l = new ArrayList<PropertyInfo>(3);
    NodeId nid = nInfo.getId();
    Path nPath = nInfo.getPath();
    if (nid.getPath() == null) {
        PropertyId id = getIdFactory().createPropertyId(nid, NameConstants.JCR_UUID);
        QValue[] vs = new QValue[] { getQValueFactory().create(nid.getUniqueID(), PropertyType.STRING) };
        Path p = getPathFactory().create(nPath, NameConstants.JCR_UUID, true);
        PropertyInfo pi = new PropertyInfoImpl(id, p, PropertyType.STRING, false, vs);
        l.add(pi);
    }
    Name pName = NameConstants.JCR_PRIMARYTYPE;
    QValue[] vs = new QValue[] { getQValueFactory().create(nInfo.getNodetype()) };
    PropertyInfo pi = new PropertyInfoImpl(getIdFactory().createPropertyId(nid, pName), getPathFactory().create(nPath, pName, true), PropertyType.NAME, false, vs);
    l.add(pi);
    Name[] mixins = nInfo.getMixins();
    if (mixins.length > 0) {
        pName = NameConstants.JCR_MIXINTYPES;
        vs = new QValue[mixins.length];
        for (int i = 0; i < mixins.length; i++) {
            vs[i] = getQValueFactory().create(mixins[i]);
        }
        pi = new PropertyInfoImpl(getIdFactory().createPropertyId(nid, pName), getPathFactory().create(nPath, pName, true), PropertyType.NAME, true, vs);
        l.add(pi);
    }
    return l;
}
Also used : Path(org.apache.jackrabbit.spi.Path) QValue(org.apache.jackrabbit.spi.QValue) ArrayList(java.util.ArrayList) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) PropertyId(org.apache.jackrabbit.spi.PropertyId) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) Name(org.apache.jackrabbit.spi.Name)

Aggregations

PropertyInfo (org.apache.jackrabbit.spi.PropertyInfo)27 NodeId (org.apache.jackrabbit.spi.NodeId)23 Name (org.apache.jackrabbit.spi.Name)22 Batch (org.apache.jackrabbit.spi.Batch)19 QValue (org.apache.jackrabbit.spi.QValue)18 ItemInfo (org.apache.jackrabbit.spi.ItemInfo)5 NodeInfo (org.apache.jackrabbit.spi.NodeInfo)5 PropertyId (org.apache.jackrabbit.spi.PropertyId)5 ArrayList (java.util.ArrayList)4 ItemNotFoundException (javax.jcr.ItemNotFoundException)3 InputStream (java.io.InputStream)2 PathNotFoundException (javax.jcr.PathNotFoundException)2 RepositoryException (javax.jcr.RepositoryException)2 Path (org.apache.jackrabbit.spi.Path)2 IOException (java.io.IOException)1 ItemVisitor (javax.jcr.ItemVisitor)1 Node (javax.jcr.Node)1 Property (javax.jcr.Property)1 TraversingItemVisitor (javax.jcr.util.TraversingItemVisitor)1 HttpEntity (org.apache.http.HttpEntity)1