Package javax.jcr

Examples of javax.jcr.Node


    /**
     * Return a test root node, created on demand, with a unique path
     */
    private Node getTestRootNode() throws RepositoryException {
        if (testRoot == null) {
            final Node root = session.getRootNode();
            if (getResourceResolverType() == ResourceResolverType.JCR_JACKRABBIT) {
                final Node classRoot = root.addNode(getClass().getSimpleName());
                testRoot = classRoot.addNode(System.currentTimeMillis() + "_" + (rootNodeCounter++));
            } else {
                testRoot = root.addNode("test", JcrConstants.NT_UNSTRUCTURED);
            }
        }
        return testRoot;
View Full Code Here


            throws InterruptedException {

        poller.pollUntil(new Callable<Node>() {
            @Override
            public Node call() throws RepositoryException {
                Node node = repo.getNode(nodePath);
                return node;

            }
        }, matcher);
    }
View Full Code Here

            depth.append(" ");
        }
        logger.info(depth + "/" + node.getName() + " -- " + sb);
        NodeIterator it = node.getNodes();
        while (it.hasNext()) {
            Node child = it.nextNode();
            dump(child);
        }
    }
View Full Code Here

        if (!item.isNode()) {
            return;
        }

        Node parent = item.getParent();

        String next = null;
        if (command.equals(SlingPostConstants.ORDER_FIRST)) {

            next = parent.getNodes().nextNode().getName();

        } else if (command.equals(SlingPostConstants.ORDER_LAST)) {

            next = "";

        } else if (command.startsWith(SlingPostConstants.ORDER_BEFORE)) {

            next = command.substring(SlingPostConstants.ORDER_BEFORE.length());

        } else if (command.startsWith(SlingPostConstants.ORDER_AFTER)) {

            String name = command.substring(SlingPostConstants.ORDER_AFTER.length());
            NodeIterator iter = parent.getNodes();
            while (iter.hasNext()) {
                Node n = iter.nextNode();
                if (n.getName().equals(name)) {
                    if (iter.hasNext()) {
                        next = iter.nextNode().getName();
                    } else {
                        next = "";
                    }
                }
            }

        } else {
            // check for integer
            try {
                // 01234
                // abcde move a -> 2 (above 3)
                // bcade move a -> 1 (above 1)
                // bacde
                int newPos = Integer.parseInt(command);
                next = "";
                NodeIterator iter = parent.getNodes();
                while (iter.hasNext() && newPos >= 0) {
                    Node n = iter.nextNode();
                    if (n.getName().equals(item.getName())) {
                        // if old node is found before index, need to
                        // inc index
                        newPos++;
                    }
                    if (newPos == 0) {
                        next = n.getName();
                        break;
                    }
                    newPos--;
                }
            } catch (NumberFormatException e) {
View Full Code Here

    public void setUp() throws Exception {
        value = RandomStringUtils.randomAlphanumeric(10);

        resolver = rrFactory.getAdministrativeResourceResolver(null);    
        Session session = resolver.adaptTo(Session.class);
        Node rootNode = session.getRootNode();
        createdNode = rootNode.addNode("test_" + RandomStringUtils.randomAlphanumeric(10));
        createdNode.setProperty("testProperty", value);
        session.save();

        resource = resolver.getResource(createdNode.getPath());
    }
View Full Code Here

        throw new UnsupportedOperationException("Not implemented");
    }

    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);
                    }
                }
View Full Code Here

    }

    public void delete(Resource resource) throws PersistenceException {
        if (resources.contains(resource)) {
            resources.remove(resource);
            Node node = resource.adaptTo(Node.class);
            try {
                node.remove();
            } catch (RepositoryException e) {
                throw new PersistenceException("RepositoryException: "+e, e);
            }
        } else {
            throw new UnsupportedOperationException("Not implemented");
View Full Code Here

        }
    }

    public Resource create(Resource parent, String name,
            Map<String, Object> properties) throws PersistenceException {
        final Node parentNode = parent.adaptTo(Node.class);
        try {
            final Node child;
            if (properties!=null && properties.containsKey("jcr:primaryType")) {
                child = parentNode.addNode(name, (String) properties.get("jcr:primaryType"));
            } else {
                child = parentNode.addNode(name);
            }
            if (properties!=null) {
                final Iterator<Entry<String, Object>> it = properties.entrySet().iterator();
                while(it.hasNext()) {
                    final Entry<String, Object> entry = it.next();
                    if (entry.getKey().equals("jcr:primaryType")) {
                        continue;
                    }
                    if (entry.getValue() instanceof String) {
                        child.setProperty(entry.getKey(), (String)entry.getValue());
                    } else if (entry.getValue() instanceof Boolean) {
                        child.setProperty(entry.getKey(), (Boolean)entry.getValue());
                    } else {
                        throw new UnsupportedOperationException("Not implemented");
                    }
                }
            }
View Full Code Here

    private void update(ResourceProxy resource, Session session) throws RepositoryException, IOException {

        String path = resource.getPath();
        boolean nodeExists = session.nodeExists(path);

        Node node;
        if (nodeExists) {
            node = session.getNode(path);
            getLogger().trace("Found existing node at {0} with primaryType {1}", path,
                    node.getPrimaryNodeType().getName());
        } else {
            node = createNode(resource, session);
            getLogger().trace("Created node at {0} with primaryType {1}", path, node.getPrimaryNodeType().getName());
        }

        updateNode(node, resource);
        processDeletedNodes(node, resource);
View Full Code Here

            resourceChildrenPaths.put(child.getPath(), child);
        }

        for (NodeIterator it = node.getNodes(); it.hasNext();) {

            Node child = it.nextNode();

            if (resourceChildrenPaths.containsKey(child.getPath())) {
                // only descend for reordering when the child node is covered ; otherwise we
                // don't have enough information
                if (resource2.covers(child.getPath())) {
                    processDeletedNodes(child, resourceChildrenPaths.get(child.getPath()));
                }
                continue;
            }

            getLogger()
                    .trace("Deleting node {0} as it is no longer present in the local checkout", child.getPath());
            child.remove();
        }
    }
View Full Code Here

TOP

Related Classes of javax.jcr.Node

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.