Search in sources :

Example 1 with PropertyId

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

the class NodeEntryImpl method getDeepPropertyEntry.

/**
 * @see NodeEntry#getDeepPropertyEntry(Path)
 */
public PropertyEntry getDeepPropertyEntry(Path path) throws PathNotFoundException, RepositoryException {
    NodeEntryImpl entry = this;
    Path.Element[] elems = path.getElements();
    int i = 0;
    for (; i < elems.length - 1; i++) {
        Path.Element elem = elems[i];
        if (elems[i].denotesRoot()) {
            if (entry.getParent() != null) {
                throw new RepositoryException("NodeEntry out of 'hierarchy' " + path.toString());
            }
            continue;
        }
        int index = elem.getNormalizedIndex();
        Name name = elem.getName();
        // first try to resolve to known node or property entry
        NodeEntry cne = entry.getNodeEntry(name, index, false);
        if (cne != null) {
            entry = (NodeEntryImpl) cne;
        } else {
            // on the persistent layer.
            if (entry.childNodeEntries.isComplete()) {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
            // -> check for moved child entry in node-attic
            // -> check if child points to a removed/moved sns
            List<NodeEntry> siblings = entry.childNodeEntries.get(name);
            if (entry.containsAtticChild(siblings, name, index)) {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
            // break out of the loop and start deep loading the property
            break;
        }
    }
    int st = entry.getStatus();
    PropertyEntry pe;
    if (i == elems.length - 1 && Status.INVALIDATED != st && Status._UNDEFINED_ != st) {
        // all node entries present in the hierarchy and the direct ancestor
        // has already been resolved and isn't invalidated -> no need to
        // retrieve property entry from SPI
        pe = entry.properties.get(path.getName());
    } else {
        /*
            * Unknown parent entry (not-existing or not yet loaded) or a parent
            * entry that has been invalidated:
            * Skip all intermediate entries and directly try to load the
            * PropertyState (including building the intermediate entries. If that
            * fails ItemNotFoundException is thrown.
            */
        PathBuilder pb = new PathBuilder(getPathFactory());
        for (int j = i; j < elems.length; j++) {
            pb.addLast(elems[j]);
        }
        Path remainingPath = pb.getPath();
        IdFactory idFactory = getIdFactory();
        NodeId parentId = entry.getWorkspaceId();
        if (remainingPath.getLength() != 1) {
            parentId = idFactory.createNodeId(parentId, remainingPath.getAncestor(1));
        }
        PropertyId propId = idFactory.createPropertyId(parentId, remainingPath.getName());
        pe = entry.loadPropertyEntry(propId);
    }
    if (pe == null) {
        throw new PathNotFoundException(factory.saveGetJCRPath(path));
    }
    return pe;
}
Also used : Path(org.apache.jackrabbit.spi.Path) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.spi.PropertyId) PathBuilder(org.apache.jackrabbit.spi.commons.name.PathBuilder) IdFactory(org.apache.jackrabbit.spi.IdFactory) NodeId(org.apache.jackrabbit.spi.NodeId) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 2 with PropertyId

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

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

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

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

the class RepositoryServiceImpl method getPath.

private Path getPath(ItemId itemId, SessionInfo sessionInfo, String workspaceName) throws RepositoryException {
    if (itemId.denotesNode()) {
        Path p = itemId.getPath();
        String uid = itemId.getUniqueID();
        if (uid == null) {
            return p;
        } else {
            NamePathResolver resolver = getNamePathResolver(sessionInfo);
            String uri = super.getItemUri(itemId, sessionInfo, workspaceName);
            String rootUri = getRootURI(sessionInfo);
            String jcrPath;
            if (uri.startsWith(rootUri)) {
                jcrPath = uri.substring(rootUri.length());
            } else {
                log.warn("ItemURI " + uri + " doesn't start with rootURI (" + rootUri + ").");
                // fallback:
                // calculated uri does not start with the rootURI
                // -> search /jcr:root and start sub-string behind.
                String rootSegment = Text.escapePath(JcrRemotingConstants.ROOT_ITEM_RESOURCEPATH);
                jcrPath = uri.substring(uri.indexOf(rootSegment) + rootSegment.length());
            }
            jcrPath = Text.unescape(jcrPath);
            return resolver.getQPath(jcrPath);
        }
    } else {
        PropertyId pId = (PropertyId) itemId;
        Path parentPath = getPath(pId.getParentId(), sessionInfo, workspaceName);
        return getPathFactory().create(parentPath, pId.getName(), true);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) PropertyId(org.apache.jackrabbit.spi.PropertyId)

Aggregations

PropertyId (org.apache.jackrabbit.spi.PropertyId)21 NodeId (org.apache.jackrabbit.spi.NodeId)13 Name (org.apache.jackrabbit.spi.Name)10 RepositoryException (javax.jcr.RepositoryException)8 ArrayList (java.util.ArrayList)6 Path (org.apache.jackrabbit.spi.Path)6 PropertyInfo (org.apache.jackrabbit.spi.PropertyInfo)5 QValue (org.apache.jackrabbit.spi.QValue)5 Batch (org.apache.jackrabbit.spi.Batch)4 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)4 IOException (java.io.IOException)3 ItemNotFoundException (javax.jcr.ItemNotFoundException)3 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)3 Serializable (java.io.Serializable)2 Node (javax.jcr.Node)2 HttpResponse (org.apache.http.HttpResponse)2 ChildInfo (org.apache.jackrabbit.spi.ChildInfo)2 ItemId (org.apache.jackrabbit.spi.ItemId)2 ItemInfo (org.apache.jackrabbit.spi.ItemInfo)2 NamePathResolver (org.apache.jackrabbit.spi.commons.conversion.NamePathResolver)2