Package javax.jcr

Examples of javax.jcr.Property


        // still be two times "foo" in the list, even if this is not a real set.
        List<String> oldValues = new ArrayList<String>();

        if (parent.valueMap.containsKey(name)) {
            if ( parent.node != null ) {
                final Property p = parent.node.getProperty(name);

                // can only patch multi-value props
                if (!p.getDefinition().isMultiple()) {
                    return null;
                }

                for (Value v : p.getValues()) {
                    oldValues.add(v.getString());
                }
            } else {
                final String[] setValues = parent.valueMap.get(name, String[].class);
                if ( setValues != null ) {
View Full Code Here


            final String[] values,
            final int type,
            final boolean multiValued)
                    throws RepositoryException, PersistenceException {
        if ( parent.node != null ) {
            Property p = null;

            if (multiValued) {
                if (type == PropertyType.UNDEFINED) {
                    p = parent.node.setProperty(name, values);
                } else {
                    p = parent.node.setProperty(name, values, type);
                }
            } else if (values.length >= 1) {
                if (type == PropertyType.UNDEFINED) {
                    p = parent.node.setProperty(name, values[0]);
                } else {
                    p = parent.node.setProperty(name, values[0], type);
                }
            }

            if (p != null) {
                changes.add(Modification.onModified(p.getPath()));
            }
        } else {
            if (multiValued) {
                parent.valueMap.put(name, toJavaObject(values, type));
                changes.add(Modification.onModified(parent.resource.getPath() + '/' + name));
View Full Code Here

        }

        PropertyIterator pi = node.getProperties();
        StringBuilder sb = new StringBuilder();
        while (pi.hasNext()) {
            Property p = pi.nextProperty();
            sb.append(" ");
            sb.append(p.getName());
            sb.append("=");
            if (p.getType() == PropertyType.BOOLEAN) {
                sb.append(p.getBoolean());
            } else if (p.getType() == PropertyType.STRING) {
                sb.append(p.getString());
            } else if (p.getType() == PropertyType.DATE) {
                sb.append(p.getDate().getTime());
            } else {
                sb.append("<unknown type=" + p.getType() + "/>");
            }
        }

        StringBuffer depth = new StringBuffer();
        for(int i=0; i<node.getDepth(); i++) {
View Full Code Here

    }

    @Test
    public void testRemove() throws RepositoryException {
        this.node1.setProperty("prop1", "value1");
        Property prop1 = this.node1.getProperty("prop1");
        assertEquals("value1", prop1.getString());

        prop1.remove();
        assertFalse(this.node1.hasProperty("prop1"));
    }
View Full Code Here

    }

    @Test
    public void testString() throws RepositoryException {
        this.node1.setProperty("prop1", "value1");
        Property prop1 = this.node1.getProperty("prop1");
        assertEquals("value1", prop1.getString());
        assertEquals("value1", prop1.getValue().getString());

        prop1.setValue("value2");
        assertEquals("value2", prop1.getString());
        assertEquals("value2", prop1.getValue().getString());

        assertFalse(prop1.isMultiple());
        assertFalse(prop1.getDefinition().isMultiple());
        assertEquals(6, prop1.getLength());
    }
View Full Code Here

        }

        Set<String> propertiesToRemove = new HashSet<String>();
        PropertyIterator properties = node.getProperties();
        while (properties.hasNext()) {
            Property property = properties.nextProperty();
            if (property.getDefinition().isProtected()
                    || property.getDefinition().getRequiredType() == PropertyType.BINARY) {
                continue;
            }
            propertiesToRemove.add(property.getName());
        }

        propertiesToRemove.removeAll(resource.getProperties().keySet());

        Session session = node.getSession();

        // update the mixin types ahead of type as contraints are enforced before
        // the session is committed
        Object mixinTypes = resource.getProperties().get(JcrConstants.JCR_MIXINTYPES);
        if (mixinTypes != null) {
            updateMixins(node, mixinTypes);
        }

        // remove old properties first
        // this supports the scenario where the node type is changed to a less permissive one
        for (String propertyToRemove : propertiesToRemove) {
            node.getProperty(propertyToRemove).remove();
            getLogger().trace("Removed property {0} from node at {1}", propertyToRemove, node.getPath());
        }
       
        String primaryType = (String) resource.getProperties().get(JcrConstants.JCR_PRIMARYTYPE);
        if (!node.getPrimaryNodeType().getName().equals(primaryType) && node.getDepth() != 0) {
            node.setPrimaryType(primaryType);
            session.save();
            getLogger().trace("Set new primary type {0} for node at {1}", primaryType, node.getPath());
        }

        // TODO - review for completeness and filevault compatibility
        for (Map.Entry<String, Object> entry : resource.getProperties().entrySet()) {

            String propertyName = entry.getKey();
            Object propertyValue = entry.getValue();
            Property property = null;

            if (node.hasProperty(propertyName)) {
                property = node.getProperty(propertyName);
            }

            if (property != null && property.getDefinition().isProtected()) {
                continue;
            }

            ValueFactory valueFactory = session.getValueFactory();
            Value value = null;
View Full Code Here

                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();
                        } else if (type.equals(String.class)) {
                          return (T) p.getString();
                        } else {
                            throw new UnsupportedOperationException();
                        }
                    } catch(RepositoryException e) {
                      throw new RuntimeException(e);
View Full Code Here

        ResourceProxy resource = new ResourceProxy(node.getPath());
        resource.addAdapted(Node.class, node);

        PropertyIterator properties = node.getProperties();
        while (properties.hasNext()) {
            Property property = properties.nextProperty();
            String propertyName = property.getName();
            Object propertyValue = ConversionUtils.getPropertyValue(property);
   
            if (propertyValue != null) {
                resource.addProperty(propertyName, propertyValue);
            }
View Full Code Here

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

        assertEquals("value1a", prop1a.getString());
        assertEquals("value1b", prop1b.getString());
        assertEquals("value2", prop2.getString());

        assertFalse(this.session.propertyExists("/node1"));
        assertFalse(this.session.nodeExists("/node1/prop1a"));

        assertEquals(JcrConstants.NT_UNSTRUCTURED, node1.getPrimaryNodeType().getName());
View Full Code Here

    }

    @Override
    public Property setProperty(final String name, final Value value) throws RepositoryException {
        ItemData itemData = ItemData.newProperty(getPath() + "/" + name);
        Property property = new MockProperty(itemData, getSession());
        property.setValue(value);
        getMockedSession().addItem(itemData);
        return property;
    }
View Full Code Here

TOP

Related Classes of javax.jcr.Property

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.