Search in sources :

Example 36 with NodeId

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

the class DavPropertyTest method testVersion.

public void testVersion() throws Exception {
    NodeId nid = getNodeId("/test");
    Batch b = rs.createBatch(si, nid);
    b.setMixins(nid, new Name[] { NameConstants.MIX_VERSIONABLE });
    rs.submit(b);
    NodeId vID = rs.checkin(si, nid);
    String uri = rs.getItemUri(vID, si);
    DavPropertyNameSet set = doPropFindNames(uri);
    DavPropertyNameSet expected = new DavPropertyNameSet(BASE_SET);
    expected.addAll(EXISTING_ITEM_BASE_SET);
    expected.addAll(NODE_SET);
    expected.addAll(VERSION_SET);
    expected.add(JCR_PARENT);
    expected.add(JCR_UUID);
    /*
         Expected property names

        {DAV:}getlastmodified
        {DAV:}version-name
        {http://www.day.com/jcr/webdav/1.0}definition
        {DAV:}comment
        {http://www.day.com/jcr/webdav/1.0}references
        {http://www.day.com/jcr/webdav/1.0}parent
        {DAV:}displayname
        {http://www.day.com/jcr/webdav/1.0}workspaceName
        {http://www.day.com/jcr/webdav/1.0}subscriptiondiscovery
        {http://www.day.com/jcr/webdav/1.0}uuid
        {DAV:}checkout-set
        {DAV:}predecessor-set
        {http://www.day.com/jcr/webdav/1.0}name
        {DAV:}current-user-privilege-set
        {http://www.day.com/jcr/webdav/1.0}primarynodetype
        {DAV:}version-history
        {DAV:}successor-set
        {DAV:}lockdiscovery
        {DAV:}resourcetype
        {DAV:}workspace
        {http://www.day.com/jcr/webdav/1.0}depth
        {http://www.day.com/jcr/webdav/1.0}index
        {DAV:}label-name-set
        {DAV:}supportedlock
        {DAV:}supported-method-set
        {DAV:}iscollection
        {http://www.day.com/jcr/webdav/1.0}weakreferences
        {DAV:}creator-displayname
        {DAV:}getcontenttype
        {DAV:}creationdate
        {DAV:}supported-report-set
        {http://www.day.com/jcr/webdav/1.0}mixinnodetypes
        {http://www.day.com/jcr/webdav/1.0}path
        */
    assertPropertyNames(expected, set);
    DavPropertyNameSet all = doPropFindAll(uri);
    expected.remove(DeltaVConstants.COMMENT);
    expected.remove(DeltaVConstants.CREATOR_DISPLAYNAME);
    expected.remove(DeltaVConstants.SUPPORTED_METHOD_SET);
    expected.remove(DeltaVConstants.SUPPORTED_REPORT_SET);
    expected.remove(DeltaVConstants.WORKSPACE);
    expected.remove(SecurityConstants.CURRENT_USER_PRIVILEGE_SET);
    expected.remove(ObservationConstants.SUBSCRIPTIONDISCOVERY);
    expected.remove(JCR_DEFINITION);
    expected.remove(JCR_INDEX);
    expected.remove(JCR_REFERENCES);
    expected.remove(JCR_WEAK_REFERENCES);
    expected.remove(JCR_UUID);
    expected.remove(VersionResource.VERSION_NAME);
    expected.remove(VersionResource.LABEL_NAME_SET);
    expected.remove(VersionResource.PREDECESSOR_SET);
    expected.remove(VersionResource.SUCCESSOR_SET);
    expected.remove(VersionResource.VERSION_HISTORY);
    expected.remove(VersionResource.CHECKOUT_SET);
    /*
        Expected all-props

        {DAV:}getlastmodified
        {http://www.day.com/jcr/webdav/1.0}depth
        {http://www.day.com/jcr/webdav/1.0}workspaceName
        {DAV:}displayname
        {http://www.day.com/jcr/webdav/1.0}parent
        {DAV:}supportedlock
        {DAV:}iscollection
        {DAV:}getcontenttype
        {http://www.day.com/jcr/webdav/1.0}name
        {DAV:}creationdate
        {http://www.day.com/jcr/webdav/1.0}mixinnodetypes
        {http://www.day.com/jcr/webdav/1.0}path
        {http://www.day.com/jcr/webdav/1.0}primarynodetype
        {DAV:}lockdiscovery
        {DAV:}resourcetype
         */
    assertPropertyNames(expected, all);
    DavPropertyNameSet props = new DavPropertyNameSet();
    props.add(DeltaVConstants.COMMENT);
    props.add(DeltaVConstants.CREATOR_DISPLAYNAME);
    props.add(DeltaVConstants.SUPPORTED_METHOD_SET);
    props.add(DeltaVConstants.SUPPORTED_REPORT_SET);
    props.add(DeltaVConstants.WORKSPACE);
    props.add(SecurityConstants.CURRENT_USER_PRIVILEGE_SET);
    props.add(ObservationConstants.SUBSCRIPTIONDISCOVERY);
    props.add(JCR_DEFINITION);
    props.add(JCR_INDEX);
    props.add(JCR_REFERENCES);
    props.add(JCR_WEAK_REFERENCES);
    props.add(JCR_UUID);
    props.add(VersionResource.VERSION_NAME);
    props.add(VersionResource.LABEL_NAME_SET);
    props.add(VersionResource.PREDECESSOR_SET);
    props.add(VersionResource.SUCCESSOR_SET);
    props.add(VersionResource.VERSION_HISTORY);
    props.add(VersionResource.CHECKOUT_SET);
    DavPropertyNameSet result = doPropFindByProp(uri, props);
    assertPropertyNames(props, result);
}
Also used : Batch(org.apache.jackrabbit.spi.Batch) NodeId(org.apache.jackrabbit.spi.NodeId) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet)

Example 37 with NodeId

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

Example 38 with NodeId

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

the class VersionManagerImpl method getVersionHistoryEntry.

public NodeEntry getVersionHistoryEntry(NodeState versionableState) throws RepositoryException {
    PropertyState ps = versionableState.getPropertyState(NameConstants.JCR_VERSIONHISTORY);
    String uniqueID = ps.getValue().getString();
    NodeId vhId = workspaceManager.getIdFactory().createNodeId(uniqueID);
    return workspaceManager.getHierarchyManager().getNodeEntry(vhId);
}
Also used : NodeId(org.apache.jackrabbit.spi.NodeId) PropertyState(org.apache.jackrabbit.jcr2spi.state.PropertyState)

Example 39 with NodeId

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

the class NodeEntryImpl method getDeepNodeEntry.

/**
     * @see NodeEntry#getDeepNodeEntry(Path)
     */
public NodeEntry getDeepNodeEntry(Path path) throws PathNotFoundException, RepositoryException {
    NodeEntryImpl entry = this;
    Path.Element[] elems = path.getElements();
    for (int i = 0; i < elems.length; i++) {
        Path.Element elem = elems[i];
        // check for root element
        if (elem.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));
            }
            // elements -> hierarchy doesn't exist anyway.
            if (entry.getStatus() == Status.NEW) {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
            /*
                * Unknown entry (not-existing or not yet loaded):
                * Skip all intermediate entries and directly try to load the ItemState
                * (including building the intermediate entries. If that fails
                * ItemNotFoundException is thrown.
                *
                * Since 'path' might be ambiguous (Node or Property):
                * 1) first try Node
                * 2) if the NameElement does not have SNS-index => try Property
                * 3) else throw
                */
            PathBuilder pb = new PathBuilder(getPathFactory());
            for (int j = i; j < elems.length; j++) {
                pb.addLast(elems[j]);
            }
            Path remainingPath = pb.getPath();
            NodeId parentId = entry.getWorkspaceId();
            IdFactory idFactory = factory.getIdFactory();
            NodeId nodeId = idFactory.createNodeId(parentId, remainingPath);
            NodeEntry ne = entry.loadNodeEntry(nodeId);
            if (ne != null) {
                return ne;
            } else {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
        }
    }
    return entry;
}
Also used : Path(org.apache.jackrabbit.spi.Path) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) 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 40 with NodeId

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

the class NodeEntryImpl method getNodeEntry.

/**
     * @see NodeEntry#getNodeEntry(Name, int, boolean)
     */
public NodeEntry getNodeEntry(Name nodeName, int index, boolean loadIfNotFound) throws RepositoryException {
    List<NodeEntry> entries = childNodeEntries.get(nodeName);
    NodeEntry cne = null;
    if (entries.size() >= index) {
        // position of entry might differ from index-1 if a SNS with lower
        // index has been transiently removed.
        int eIndex = 1;
        for (int i = 0; i < entries.size() && cne == null; i++) {
            NodeEntry ne = entries.get(i);
            if (EntryValidation.isValidNodeEntry(ne)) {
                if (eIndex == index) {
                    cne = ne;
                }
                eIndex++;
            }
        }
    }
    if (cne == null && loadIfNotFound && !containsAtticChild(entries, nodeName, index) && !childNodeEntries.isComplete()) {
        NodeId cId = getIdFactory().createNodeId(getWorkspaceId(), getPathFactory().create(nodeName, index));
        cne = loadNodeEntry(cId);
    }
    return cne;
}
Also used : NodeId(org.apache.jackrabbit.spi.NodeId)

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