Package javax.jcr

Examples of javax.jcr.Node


            } else if (propertyValue instanceof Long[]) {
                values = toValueArray((Long[]) propertyValue, session);
                ensurePropertyDefinitionMatchers(property, PropertyType.LONG, true);
                // TODO - distinguish between weak vs strong references
            } else if (propertyValue instanceof UUID) {
                Node reference = session.getNodeByIdentifier(((UUID) propertyValue).toString());
                value = valueFactory.createValue(reference);
                ensurePropertyDefinitionMatchers(property, PropertyType.REFERENCE, false);
            } else if (propertyValue instanceof UUID[]) {
                values = toValueArray((UUID[]) propertyValue, session);
                ensurePropertyDefinitionMatchers(property, PropertyType.REFERENCE, true);
View Full Code Here


        if (!hasFileLikePrimaryNodeType(node)) {
            return;
        }

        Node contentNode;

        if (node.hasNode(JCR_CONTENT)) {
            contentNode = node.getNode(JCR_CONTENT);
        } else {
            if (node.getProperty(JCR_PRIMARYTYPE).getString().equals(NT_RESOURCE)) {
                contentNode = node;
            } else {
                contentNode = node.addNode(JCR_CONTENT, NT_RESOURCE);
            }
        }

        getLogger().trace("Updating {0} property on node at {1} ", JCR_DATA, contentNode.getPath());

        FileInputStream inputStream = new FileInputStream(file);
        try {
            Binary binary = node.getSession().getValueFactory().createBinary(inputStream);
            contentNode.setProperty(JCR_DATA, binary);
            // TODO: might have to be done differently since the client and server's clocks can differ
            // and the last_modified should maybe be taken from the server's time..
            contentNode.setProperty(JCR_LASTMODIFIED, Calendar.getInstance());

        } finally {
            try {
                inputStream.close();
            } catch (IOException e) {
View Full Code Here

        Value[] values = new Value[uuids.length];

        for (int i = 0; i < uuids.length; i++) {

            Node reference = session.getNodeByIdentifier(uuids[i].toString());

            values[i] = session.getValueFactory().createValue(reference);
        }

        return values;
View Full Code Here

    }

    @Override
    protected ResourceProxy execute0(Session session) throws RepositoryException {

        Node node = session.getNode(getPath());

        ResourceProxy parent = nodeToResource(node);

        addChildren(parent, node, levels-1);
       
View Full Code Here

        final long start = System.currentTimeMillis();
        NodeIterator nodes = node.getNodes();
        final long end = System.currentTimeMillis();
        log("ListTreeCommand.child -> "+node.getPath(), start, end);
        while (nodes.hasNext()) {
            Node childNode = nodes.nextNode();

            // TODO - this should not be needed if we obey the vlt filters
            if (childNode.getPath().equals("/jcr:system")) {
                continue;
            }

            final ResourceProxy childResourceProxy = nodeToResource(childNode);
            parent.addChild(childResourceProxy);
View Full Code Here

        boolean nodeExists = session.nodeExists(getPath());
        if (!nodeExists) {
            return null;
        }

        Node node = session.getNode(getPath());

        NodeType primaryNodeType = node.getPrimaryNodeType();

        if (primaryNodeType.hasOrderableChildNodes()) {
            reorderChildNodes(node, resource);
        }
       
View Full Code Here

        Set<String> nodeChildNames = new HashSet<String>(children.size());

        List<Node> nodeChildren = new LinkedList<Node>();
        NodeIterator nodeChildrenIt = nodeToReorder.getNodes();
        while (nodeChildrenIt.hasNext()) {
            Node node = nodeChildrenIt.nextNode();
            nodeChildren.add(node);
            nodeChildNames.add(node.getName());
        }

        for (ResourceProxy childResources : children) {
            resourceChildNames.add(Text.getName(childResources.getPath()));
        }
        ListIterator<Node> nodeChildrenListIt = nodeChildren.listIterator();

        // the sorting is conditioned on the local workspace and the repository having the same child names
        // if that precondition is not met abort processing since there can be no meaningful result

        traceResourcesAndNodes(children, nodeChildren);

        if (! resourceChildNames.equals(nodeChildNames)) {
            getLogger().warn(
                    "Different child names between the local workspace ( " + resourceChildNames
                            + ") and the repository (" + nodeChildNames + ") for path " + resource.getPath()
                            + ". Reordering will not be performed");
            return;
        }

        while (childrenIterator.hasNext() || nodeChildrenListIt.hasNext()) {

            ResourceProxy childResource = childrenIterator.next();
            Node childNode = nodeChildrenListIt.next();

            // order is as expected, skip reordering
            if (Text.getName(childResource.getPath()).equals(childNode.getName())) {
                // descend into covered child resources once they are properly arranged and perform reordering
                if (resourceToReorder.covers(childResource.getPath())) {
                    reorderChildNodes(childNode, childResource);
                }
                continue;
View Full Code Here

                throw new RuntimeException("Exception occurred: " + e, e);
            }
        } else if (type.equals(ValueMap.class)) {
            try {
                Session session = getSession();
                Node node = session.getNode(getPath());
                HashMap<String, Object> map = new HashMap<String, Object>();

                PropertyIterator properties = node.getProperties();
                while (properties.hasNext()) {
                    Property p = properties.nextProperty();
                    if (p.getType() == PropertyType.BOOLEAN) {
                        map.put(p.getName(), p.getBoolean());
                    } else if (p.getType() == PropertyType.STRING) {
                        map.put(p.getName(), p.getString());
                    } else if (p.getType() == PropertyType.DATE) {
                        map.put(p.getName(), p.getDate().getTime());
                    } else if (p.getType() == PropertyType.NAME) {
                        map.put(p.getName(), p.getName());
                    } else {
                        throw new RuntimeException(
                                "Unsupported property type: " + p.getType());
                    }
                }
                ValueMap valueMap = new ValueMapDecorator(map);
                return (AdapterType) valueMap;
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        } else if (type.equals(ModifiableValueMap.class)) {
            return (AdapterType) new ModifiableValueMap() {
               
                public Collection<Object> values() {
                    throw new UnsupportedOperationException();
                }
               
                public int size() {
                    throw new UnsupportedOperationException();
                }
               
                public Object remove(Object arg0) {
                    Session session = getSession();
                    try{
                        final Node node = session.getNode(getPath());
                        final Property p = node.getProperty(String.valueOf(arg0));
                        if (p!=null) {
                          p.remove();
                        }
                        // this is not according to the spec - but OK for tests since
                        // the return value is never used
                        return null;
                    } catch(PathNotFoundException pnfe) {
                      // perfectly fine
                      return null;
                    } catch(RepositoryException e) {
                        throw new RuntimeException(e);
                    }
                }
               
                public void putAll(Map<? extends String, ? extends Object> arg0) {
                    throw new UnsupportedOperationException();
                }
               
                public Object put(String arg0, Object arg1) {
                    Session session = getSession();
                    try{
                        final Node node = session.getNode(getPath());
                        Object result = null;
                        if (node.hasProperty(arg0)) {
                            final Property previous = node.getProperty(arg0);
                            if (previous==null) {
                                // null
                            } else if (previous.getType() == PropertyType.STRING) {
                                result = previous.getString();
                            } else if (previous.getType() == PropertyType.DATE) {
                                result = previous.getDate();
                            } else if (previous.getType() == PropertyType.BOOLEAN) {
                                result = previous.getBoolean();
                            } else {
                                throw new UnsupportedOperationException();
                            }
                        }
                        if (arg1 instanceof String) {
                            node.setProperty(arg0, (String)arg1);
                        } else if (arg1 instanceof Calendar) {
                            node.setProperty(arg0, (Calendar)arg1);
                        } else if (arg1 instanceof Boolean) {
                            node.setProperty(arg0, (Boolean)arg1);
                        } else {
                            throw new UnsupportedOperationException();
                        }
                        return result;
                    } catch(RepositoryException e) {
                        throw new RuntimeException(e);
                    }
                }
               
                public Set<String> keySet() {
                    Session session = getSession();
                    try {
                        final Node node = session.getNode(getPath());
                        final PropertyIterator pi = node.getProperties();
                        final Set<String> result = new HashSet<String>();
                        while(pi.hasNext()) {
                            final Property p = pi.nextProperty();
                            result.add(p.getName());
                        }
                        return result;
                    } catch (RepositoryException e) {
                        throw new RuntimeException(e);
                    }
                }
               
                public boolean isEmpty() {
                    throw new UnsupportedOperationException();
                }
               
                public Object get(Object arg0) {
                    Session session = getSession();
                    try{
                        final Node node = session.getNode(getPath());
                        final String key = String.valueOf(arg0);
                        if (node.hasProperty(key)) {
                            return node.getProperty(key);
                        } else {
                            return null;
                        }
                    } catch(RepositoryException re) {
                        throw new RuntimeException(re);
                    }
                }
               
                public Set<Entry<String, Object>> entrySet() {
                    throw new UnsupportedOperationException();
                }
               
                public boolean containsValue(Object arg0) {
                    throw new UnsupportedOperationException();
                }
               
                public boolean containsKey(Object arg0) {
                    Session session = getSession();
                    try{
                        final Node node = session.getNode(getPath());
                        return node.hasProperty(String.valueOf(arg0));
                    } catch(RepositoryException re) {
                        throw new RuntimeException(re);
                    }
                }
               
                public void clear() {
                    throw new UnsupportedOperationException();
                }
               
                public <T> T get(String name, T defaultValue) {
                    throw new UnsupportedOperationException();
                }
               
                public <T> T get(String name, Class<T> type) {
                    Session session = getSession();
                    try{
                        final Node node = session.getNode(getPath());
                        if (node==null) {
                          return null;
                        }
                        Property p = node.getProperty(name);
                        if (p==null) {
                          return null;
                        }
                        if (type.equals(Calendar.class)) {
                          return (T) p.getDate();
View Full Code Here

        this.session = MockJcr.newSession();
    }

    @Test
    public void testEmptySession() throws RepositoryException {
        Node rootNode = this.session.getRootNode();
        assertNotNull(rootNode);
        assertFalse(rootNode.getProperties().hasNext());
        assertFalse(rootNode.getNodes().hasNext());
    }
View Full Code Here

        assertFalse(rootNode.getNodes().hasNext());
    }

    @Test
    public void testNodePropertyCreateRead() throws RepositoryException {
        Node rootNode = this.session.getNode("/");
        assertEquals(rootNode, this.session.getRootNode());

        Node node1 = rootNode.addNode("node1");
        node1.setProperty("prop1a", "value1a");
        node1.setProperty("prop1b", "value1b");

        Node node2 = rootNode.addNode("node2");
        node2.setProperty("prop2", "value2");

        assertEquals(node1, rootNode.getNode("node1"));
        assertEquals(node1, this.session.getNode("/node1"));
        assertEquals(node1, this.session.getItem("/node1"));
        assertEquals(node1, this.session.getNodeByIdentifier(node1.getIdentifier()));
        assertTrue(this.session.nodeExists("/node1"));
        assertTrue(this.session.itemExists("/node1"));
        assertEquals(node2, rootNode.getNode("node2"));
        assertEquals(node2, this.session.getNode("/node2"));
        assertEquals(node2, this.session.getItem("/node2"));
        assertEquals(node2, this.session.getNodeByIdentifier(node2.getIdentifier()));
        assertTrue(this.session.nodeExists("/node2"));
        assertTrue(this.session.itemExists("/node2"));

        Property prop1a = node1.getProperty("prop1a");
        Property prop1b = node1.getProperty("prop1b");
        Property prop2 = node2.getProperty("prop2");

        assertEquals(prop1a, this.session.getProperty("/node1/prop1a"));
        assertEquals(prop1a, this.session.getItem("/node1/prop1a"));
        assertTrue(this.session.propertyExists("/node1/prop1a"));
        assertTrue(this.session.itemExists("/node1/prop1a"));
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.