Search in sources :

Example 76 with NodeId

use of org.apache.jackrabbit.spi.NodeId 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)

Example 77 with NodeId

use of org.apache.jackrabbit.spi.NodeId 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 78 with NodeId

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

the class ItemInfoJsonHandler method object.

public void object() throws IOException {
    if (name != null) {
        try {
            NodeInfo current = getCurrentNodeInfo();
            Path relPath = pFactory.create(name, index);
            NodeId id = idFactory.createNodeId(current.getId(), relPath);
            Path currentPath = current.getPath();
            Path p = pFactory.create(currentPath, relPath, true);
            NodeInfo nInfo = new NodeInfoImpl(id, p);
            nodeInfos.push(nInfo);
            propInfoLists.push(new ArrayList<PropertyInfoImpl>(8));
        } catch (RepositoryException e) {
            throw new IOException(e.getMessage());
        }
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeInfo(org.apache.jackrabbit.spi.NodeInfo) NodeId(org.apache.jackrabbit.spi.NodeId) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Example 79 with NodeId

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

the class URIResolverImpl method getPropertyId.

/**
     * @inheritDoc
     */
public PropertyId getPropertyId(String uri, SessionInfo sessionInfo) throws RepositoryException {
    IdURICache cache = getCache(sessionInfo.getWorkspaceName());
    ItemId id = cache.getItemId(uri);
    if (id != null) {
        if (!id.denotesNode()) {
            return (PropertyId) id;
        }
    }
    // separate parent uri and property JCRName
    String parentUri = Text.getRelativeParent(uri, 1, true);
    // make sure propName is unescaped
    String propName = Text.unescape(Text.getName(uri, true));
    // retrieve parent node id
    NodeId parentId = getNodeId(parentUri, sessionInfo, false);
    // build property id
    try {
        Name name = service.getNamePathResolver(sessionInfo).getQName(propName);
        PropertyId propertyId = service.getIdFactory().createPropertyId(parentId, name);
        cache.add(uri, propertyId);
        return propertyId;
    } catch (NameException e) {
        throw new RepositoryException(e);
    }
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) NodeId(org.apache.jackrabbit.spi.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemId(org.apache.jackrabbit.spi.ItemId) PropertyId(org.apache.jackrabbit.spi.PropertyId) Name(org.apache.jackrabbit.spi.Name)

Example 80 with NodeId

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

the class RepositoryServiceImpl method restore.

/**
     * {@inheritDoc}
     */
public void restore(final SessionInfo sessionInfo, final NodeId nodeId, final NodeId versionId, final boolean removeExisting) throws VersionException, PathNotFoundException, ItemExistsException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException {
    final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    executeWithLocalEvents(new Callable() {

        public Object run() throws RepositoryException {
            Version v = (Version) getNode(versionId, sInfo);
            if (hasNode(sessionInfo, nodeId)) {
                Node n = getNode(nodeId, sInfo);
                n.restore(v, removeExisting);
            } else {
                // restore with rel-Path part
                Node n = null;
                Path relPath = null;
                Path path = nodeId.getPath();
                if (nodeId.getUniqueID() != null) {
                    n = getNode(idFactory.createNodeId(nodeId.getUniqueID()), sInfo);
                    relPath = (path.isAbsolute()) ? getPathFactory().getRootPath().computeRelativePath(nodeId.getPath()) : path;
                } else {
                    int degree = 0;
                    while (degree < path.getLength()) {
                        Path ancestorPath = path.getAncestor(degree);
                        NodeId parentId = idFactory.createNodeId(nodeId.getUniqueID(), ancestorPath);
                        if (hasNode(sessionInfo, parentId)) {
                            n = getNode(parentId, sInfo);
                            relPath = ancestorPath.computeRelativePath(path);
                        }
                        degree++;
                    }
                }
                if (n == null) {
                    throw new PathNotFoundException("Path not found " + nodeId);
                } else {
                    n.restore(v, sInfo.getNamePathResolver().getJCRPath(relPath), removeExisting);
                }
            }
            return null;
        }
    }, sInfo);
}
Also used : Path(org.apache.jackrabbit.spi.Path) Version(javax.jcr.version.Version) Node(javax.jcr.Node) NodeId(org.apache.jackrabbit.spi.NodeId) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException)

Aggregations

NodeId (org.apache.jackrabbit.spi.NodeId)80 Batch (org.apache.jackrabbit.spi.Batch)35 Name (org.apache.jackrabbit.spi.Name)32 PropertyInfo (org.apache.jackrabbit.spi.PropertyInfo)23 RepositoryException (javax.jcr.RepositoryException)21 QValue (org.apache.jackrabbit.spi.QValue)21 PropertyId (org.apache.jackrabbit.spi.PropertyId)13 Path (org.apache.jackrabbit.spi.Path)11 NodeInfo (org.apache.jackrabbit.spi.NodeInfo)10 ArrayList (java.util.ArrayList)9 ItemNotFoundException (javax.jcr.ItemNotFoundException)9 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)9 IOException (java.io.IOException)6 Node (javax.jcr.Node)5 HttpResponse (org.apache.http.HttpResponse)5 ItemId (org.apache.jackrabbit.spi.ItemId)5 DavException (org.apache.jackrabbit.webdav.DavException)5 InputStream (java.io.InputStream)4 ChildInfo (org.apache.jackrabbit.spi.ChildInfo)4 PathNotFoundException (javax.jcr.PathNotFoundException)3