Package javax.jcr

Examples of javax.jcr.NodeIterator


        assertEquals("3", freemarker.evalToString("${node?size}"));
    }

    public void testIteration() throws Exception {
        String expect = "";
        NodeIterator iter = rootNode.getNodes();
        while (iter.hasNext()) {
            expect += iter.nextNode().getPath();
        }
        assertEquals(expect, freemarker.evalToString("<#list node as child>${child}</#list>"));
    }
View Full Code Here


        assertStream(new ByteArrayInputStream(BIG_DATA), nis);
    }
   
    private int getChildCount(Node n) throws RepositoryException {
        int result = 0;
        final NodeIterator it = n.getNodes();
        while(it.hasNext()) {
            result++;
            final Node kid = it.nextNode();
            result += getChildCount(kid);
        }
        return result;
    }
View Full Code Here

        if (root != null) {
            try {

                // get all child nodes of the demo content root node
                final NodeIterator nodes = root.getNodes();
                while (nodes.hasNext()) {

                    Node node = nodes.nextNode();
                    // for every child node, that has the correct properties set, create a POJO and add it to the list
                    if (node.hasProperty(PN_NOTETITLE) && node.hasProperty(PN_NOTETEXT)) {

                        final Note note = new Note();
                        note.setTitle(node.getProperty(PN_NOTETITLE).getString());
View Full Code Here

    }

    public Iterator<Resource> listChildren(Resource parent) {
        try {
            Node node = parent.adaptTo(Node.class);
            final NodeIterator nodes = node.getNodes();
            return new Iterator<Resource>() {

                public void remove() {
                    throw new UnsupportedOperationException();
                }

                public Resource next() {
                    Node next = nodes.nextNode();
                    try {
                        return new MockedResource(MockedResourceResolver.this,
                                next.getPath(), "nt:unstructured");
                    } catch (RepositoryException e) {
                        throw new RuntimeException("RepositoryException: " + e,
                                e);
                    }
                }

                public boolean hasNext() {
                    return nodes.hasNext();
                }
            };
        } catch (RepositoryException e) {
            throw new RuntimeException("RepositoryException: " + e, e);
        }
View Full Code Here

        return executionEngine.getMatchingJobStatus(null);
    }
   
    private Iterator<JobStatus> getStoredJobs(Session s) throws RepositoryException {
        final Query q = s.getWorkspace().getQueryManager().createQuery(JOB_QUERY, Query.SQL);
        final NodeIterator it = q.execute().getNodes();
        return new Iterator<JobStatus>() {

            public boolean hasNext() {
                return it.hasNext();
            }

            public JobStatus next() {
                try {
                    return jobStatusFactory.getJobStatus(it.nextNode());
                } catch(RepositoryException re) {
                    throw new JobStorageException("RepositoryException in next()", re);
                }
            }
View Full Code Here

            public Iterator<Resource> findResources(String query,
                    String language) {
                try {
                    final Query q = getSession().getWorkspace().getQueryManager().createQuery(query, language);
                    final QueryResult result = q.execute();
                    final NodeIterator nodes = result.getNodes();
                    return new Iterator<Resource>() {
                        public boolean hasNext() {
                            return nodes.hasNext();
                        }

                        public Resource next() {
                            Node node = nodes.nextNode();
                            try {
                                return new JcrNodeResource(resolver, node, null ,null);
                            } catch (RepositoryException e) {
                                throw new IllegalStateException(e);
                            }
View Full Code Here

        createTestContent();
    }

    public void cleanRepository() throws Exception {
        NodeIterator nodes = getSession().getRootNode().getNodes();
        while (nodes.hasNext()) {
            Node node = nodes.nextNode();
            if (!node.getDefinition().isProtected() && !node.getDefinition().isMandatory()) {
                try {
                    node.remove();
                } catch (RepositoryException e) {
                    log.error("Test clean repo: Cannot remove node: " + node.getPath(), e);
View Full Code Here

            long chunkOffset = prop.getChunk().getOffset();
            if (chunkOffset == 0) {
                // first chunk
                // check if another chunk upload is already in progress. throw
                // exception
                NodeIterator itr = res.getNodes(SlingPostConstants.CHUNK_NODE_NAME
                    + "*");
                if (itr.hasNext()) {
                    throw new RepositoryException(
                        "Chunk upload already in progress at {" + res.getPath()
                            + "}");
                }
                res.addMixin(SlingPostConstants.NT_SLING_CHUNK_MIXIN);
                changes.add(Modification.onModified(res.setProperty(
                    SlingPostConstants.NT_SLING_CHUNKS_LENGTH, 0).getPath()));
                if (!res.hasProperty(JCR_DATA)) {
                    // create a empty jcr:data property
                    res.setProperty(JCR_DATA,
                        new ByteArrayInputStream("".getBytes()));
                }
            }
            if (!res.hasProperty(SlingPostConstants.NT_SLING_CHUNKS_LENGTH)) {
                throw new RepositoryException("no chunk upload found at {"
                    + res.getPath() + "}");
            }
            long currentLength = res.getProperty(
                SlingPostConstants.NT_SLING_CHUNKS_LENGTH).getLong();
            long totalLength = prop.getChunk().getLength();
            if (chunkOffset != currentLength) {
                throw new RepositoryException("Chunk's offset {"
                    + chunkOffset
                    + "} doesn't match expected offset {"
                    + res.getProperty(
                        SlingPostConstants.NT_SLING_CHUNKS_LENGTH).getLong()
                    + "}");
            }
            if (totalLength != 0) {
                if (res.hasProperty(SlingPostConstants.NT_SLING_FILE_LENGTH)) {
                    long expectedLength = res.getProperty(
                        SlingPostConstants.NT_SLING_FILE_LENGTH).getLong();
                    if (totalLength != expectedLength) {
                        throw new RepositoryException("File length {"
                            + totalLength + "} doesn't match expected length {"
                            + expectedLength + "}");
                    }
                } else {
                    res.setProperty(SlingPostConstants.NT_SLING_FILE_LENGTH,
                        totalLength);
                }
            }
            NodeIterator itr = res.getNodes(SlingPostConstants.CHUNK_NODE_NAME
                + "_" + String.valueOf(chunkOffset) + "*");
            if (itr.hasNext()) {
                throw new RepositoryException("Chunk already present at {"
                    + itr.nextNode().getPath() + "}");
            }
            String nodeName = SlingPostConstants.CHUNK_NODE_NAME + "_"
                + String.valueOf(chunkOffset) + "_"
                + String.valueOf(chunkOffset + value.getSize() - 1);
            if (totalLength == (currentLength + value.getSize())
                || prop.getChunk().isCompleted()) {
                File file = null;
                InputStream fileIns = null;
                try {
                    file = mergeChunks(res, value.getInputStream());
                    fileIns = new FileInputStream(file);
                    changes.add(Modification.onModified(res.setProperty(
                        JCR_DATA, fileIns).getPath()));
                    NodeIterator nodeItr = res.getNodes(SlingPostConstants.CHUNK_NODE_NAME
                        + "*");
                    while (nodeItr.hasNext()) {
                        Node nodeRange = nodeItr.nextNode();
                        changes.add(Modification.onDeleted(nodeRange.getPath()));
                        nodeRange.remove();
                    }
                    if (res.hasProperty(SlingPostConstants.NT_SLING_FILE_LENGTH)) {
                        javax.jcr.Property expLenProp = res.getProperty(SlingPostConstants.NT_SLING_FILE_LENGTH);
View Full Code Here

        try {
            file = File.createTempFile("tmp-", "-mergechunk");
            out = new FileOutputStream(file);
            String startPattern = SlingPostConstants.CHUNK_NODE_NAME + "_"
                + "0_*";
            NodeIterator nodeItr = parentNode.getNodes(startPattern);
            InputStream ins = null;
            int i = 0;
            Set<InputStream> inpStrmSet = new LinkedHashSet<InputStream>();
            while (nodeItr.hasNext()) {
                if (nodeItr.getSize() > 1) {
                    throw new RepositoryException(
                        "more than one node found for pattern: " + startPattern);
                }
                Node rangeNode = nodeItr.nextNode();

                inpStrmSet.add(rangeNode.getProperty(
                    javax.jcr.Property.JCR_DATA).getBinary().getStream());
                log.debug("added chunk {} to merge stream", rangeNode.getName());
                String[] indexBounds = rangeNode.getName().substring(
View Full Code Here

            && hasChunks((jcrContentNode = node.getNode(JCR_CONTENT)))) {
            chunkParent = jcrContentNode;

        }
        if (chunkParent != null) {
            NodeIterator nodeItr = chunkParent.getNodes(SlingPostConstants.CHUNK_NODE_NAME
                + "*");
            while (nodeItr.hasNext()) {
                Node rangeNode = nodeItr.nextNode();
                rangeNode.remove();
            }
            if (chunkParent.hasProperty(SlingPostConstants.NT_SLING_FILE_LENGTH)) {
                chunkParent.getProperty(SlingPostConstants.NT_SLING_FILE_LENGTH).remove();
            }
View Full Code Here

TOP

Related Classes of javax.jcr.NodeIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.