Search in sources :

Example 1 with ChildInfo

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

the class NodeEntryImpl method setNodeEntries.

/**
 * @see NodeEntry#setNodeEntries(Iterator)
 */
public void setNodeEntries(Iterator<ChildInfo> childInfos) throws RepositoryException {
    if (childNodeAttic.isEmpty()) {
        ((ChildNodeEntriesImpl) childNodeEntries).update(childInfos);
    } else {
        // filter those entries that have been moved to the attic.
        List<ChildInfo> remaining = new ArrayList<ChildInfo>();
        while (childInfos.hasNext()) {
            ChildInfo ci = childInfos.next();
            if (!childNodeAttic.contains(ci.getName(), ci.getIndex(), ci.getUniqueID())) {
                remaining.add(ci);
            }
        }
        ((ChildNodeEntriesImpl) childNodeEntries).update(remaining.iterator());
    }
}
Also used : ArrayList(java.util.ArrayList) ChildInfo(org.apache.jackrabbit.spi.ChildInfo)

Example 2 with ChildInfo

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

the class ChildNodeEntriesImpl method reload.

/**
 * @see ChildNodeEntries#reload()
 */
public synchronized void reload() throws ItemNotFoundException, RepositoryException {
    if (isComplete()) {
        // nothing to do
        return;
    }
    NodeId id = parent.getWorkspaceId();
    Iterator<ChildInfo> childNodeInfos = factory.getItemStateFactory().getChildNodeInfos(id);
    update(childNodeInfos);
}
Also used : NodeId(org.apache.jackrabbit.spi.NodeId) ChildInfo(org.apache.jackrabbit.spi.ChildInfo)

Example 3 with ChildInfo

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

the class RepositoryServiceImpl method getChildInfos.

@Override
public Iterator<ChildInfo> getChildInfos(SessionInfo sessionInfo, NodeId parentId) throws RepositoryException {
    // set of properties to be retrieved
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(JcrRemotingConstants.JCR_NAME_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_INDEX_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_PARENT_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_UUID_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(DavPropertyName.RESOURCETYPE);
    HttpPropfind request = null;
    try {
        String uri = getItemUri(parentId, sessionInfo);
        request = new HttpPropfind(uri, nameSet, DEPTH_1);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        List<ChildInfo> childEntries;
        MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (mresponses.length < 1) {
            throw new ItemNotFoundException("Unable to retrieve the node with id " + saveGetIdString(parentId, sessionInfo));
        } else if (mresponses.length == 1) {
            // no child nodes nor properties
            childEntries = Collections.emptyList();
            return childEntries.iterator();
        }
        childEntries = new ArrayList<ChildInfo>();
        for (MultiStatusResponse mresponse : mresponses) {
            if (!isSameResource(uri, mresponse)) {
                DavPropertySet childProps = mresponse.getProperties(DavServletResponse.SC_OK);
                if (childProps.contains(DavPropertyName.RESOURCETYPE) && childProps.get(DavPropertyName.RESOURCETYPE).getValue() != null) {
                    childEntries.add(buildChildInfo(childProps, sessionInfo));
                }
            // else: property -> ignore
            }
        // else: ignore the response related to the parent
        }
        return childEntries.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) ChildInfo(org.apache.jackrabbit.spi.ChildInfo) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 4 with ChildInfo

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

the class BatchTest method testReorder1.

public void testReorder1() throws RepositoryException {
    NodeId nid = getNodeId(testPath);
    Batch b = rs.createBatch(si, nid);
    b.addNode(nid, resolver.getQName("2"), NameConstants.NT_UNSTRUCTURED, null);
    b.addNode(nid, resolver.getQName("3"), NameConstants.NT_UNSTRUCTURED, null);
    b.addNode(nid, resolver.getQName("1"), NameConstants.NT_UNSTRUCTURED, null);
    rs.submit(b);
    b = rs.createBatch(si, nid);
    b.reorderNodes(nid, getNodeId(testPath + "/1"), getNodeId(testPath + "/2"));
    rs.submit(b);
    Iterator<ChildInfo> it = rs.getChildInfos(si, nid);
    int i = 1;
    while (it.hasNext()) {
        ChildInfo ci = it.next();
        assertEquals(i, Integer.parseInt(ci.getName().getLocalName()));
        i++;
    }
}
Also used : Batch(org.apache.jackrabbit.spi.Batch) NodeId(org.apache.jackrabbit.spi.NodeId) ChildInfo(org.apache.jackrabbit.spi.ChildInfo)

Example 5 with ChildInfo

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

the class BatchTest method testAddNode.

public void testAddNode() throws RepositoryException {
    NodeId nid = getNodeId(testPath);
    Batch b = rs.createBatch(si, nid);
    b.addNode(nid, resolver.getQName("aNode"), NameConstants.NT_UNSTRUCTURED, null);
    b.addProperty(nid, resolver.getQName("aString"), rs.getQValueFactory().create("ba", PropertyType.STRING));
    b.addProperty(nid, resolver.getQName("aName"), new QValue[] { rs.getQValueFactory().create(NameConstants.JCR_ENCODING), rs.getQValueFactory().create(NameConstants.JCR_DATA) });
    b.addProperty(nid, resolver.getQName("aBinary"), rs.getQValueFactory().create(new byte[] { 'a', 'b', 'c' }));
    rs.submit(b);
    NodeId id = rs.getIdFactory().createNodeId(nid, resolver.getQPath("aNode"));
    Iterator<? extends ItemInfo> it = rs.getItemInfos(si, id);
    while (it.hasNext()) {
        ItemInfo info = it.next();
        if (info.denotesNode()) {
            NodeInfo nInfo = (NodeInfo) info;
            assertEquals(NameConstants.NT_UNSTRUCTURED, nInfo.getNodetype());
            Iterator<ChildInfo> childIt = nInfo.getChildInfos();
            assertTrue(childIt == null || !childIt.hasNext());
            assertEquals(id, nInfo.getId());
        }
    }
    b = rs.createBatch(si, nid);
    b.remove(id);
    rs.submit(b);
}
Also used : Batch(org.apache.jackrabbit.spi.Batch) ItemInfo(org.apache.jackrabbit.spi.ItemInfo) NodeInfo(org.apache.jackrabbit.spi.NodeInfo) NodeId(org.apache.jackrabbit.spi.NodeId) ChildInfo(org.apache.jackrabbit.spi.ChildInfo)

Aggregations

ChildInfo (org.apache.jackrabbit.spi.ChildInfo)11 NodeId (org.apache.jackrabbit.spi.NodeId)5 ArrayList (java.util.ArrayList)4 RepositoryException (javax.jcr.RepositoryException)3 Batch (org.apache.jackrabbit.spi.Batch)3 IOException (java.io.IOException)2 NodeInfo (org.apache.jackrabbit.spi.NodeInfo)2 PropertyId (org.apache.jackrabbit.spi.PropertyId)2 Serializable (java.io.Serializable)1 ItemExistsException (javax.jcr.ItemExistsException)1 ItemNotFoundException (javax.jcr.ItemNotFoundException)1 NodeIterator (javax.jcr.NodeIterator)1 HttpResponse (org.apache.http.HttpResponse)1 NodeEntry (org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry)1 ItemInfo (org.apache.jackrabbit.spi.ItemInfo)1 Name (org.apache.jackrabbit.spi.Name)1 Path (org.apache.jackrabbit.spi.Path)1 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)1 DavException (org.apache.jackrabbit.webdav.DavException)1 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)1