Package javax.jcr

Examples of javax.jcr.Property


    public void testSingleValueInputStream() throws RepositoryException {
        Session s = repository.loginAdministrative(null);
        try {
            final String path = getClass().getSimpleName() + System.currentTimeMillis();
            final Node child = deleteAfterTests(s.getRootNode().addNode(path));
            final Property p = child.setProperty("foo", "bar");
            s.save();
            assertNotNull(p.getBinary().getStream());
        } finally {
            s.logout();
        }

    }
View Full Code Here


    public void testMultiValueInputStream() throws RepositoryException {
        final Session s = repository.loginAdministrative(null);
        try {
            final String path = getClass().getSimpleName() + System.currentTimeMillis();
            final Node child = deleteAfterTests(s.getRootNode().addNode(path));
            final Property p = child.setProperty("foo", new String[] { "bar", "wii " });
            s.save();
            try {
                p.getBinary().getStream();
                fail("Expecting getStream() to fail on a multi-value Property");
            } catch(RepositoryException asExpected) {
            }
        } finally {
            s.logout();
View Full Code Here

    renderBreadcrumbs(pw, n);
    renderChildNodes(pw, n);

    for (PropertyIterator pi = n.getProperties(); pi.hasNext();) {
      final Property p = pi.nextProperty();
      if(displayProperty(p.getName())) {
        renderPropertyValue(pw, p);
      }
    }
  }
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    protected void readPreferences(PreferencesImpl prefs, Session session, Node node) throws RepositoryException {
        final PropertyIterator iterator = node.getProperties();
        while ( iterator.hasNext() ) {
            final Property prop = iterator.nextProperty();
            if ( prop.getName().startsWith(this.namespacePrefixSep) ) {
                prefs.getProperties().put(prop.getName(), prop.getString());
            }
        }
    }
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 Long) {
              node.setProperty(arg0, (Long)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) {
          try {
            Node node = session.getNode(getPath());
            return node.getProperty(String.valueOf(arg0));
          } catch (PathNotFoundException e) {
            return null;
          } catch (RepositoryException e) {
            e.printStackTrace();
            throw new RuntimeException();
          }
          // throw new UnsupportedOperationException();
        }

        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

    private void selectNextStream() throws IOException {
        streamPath.selectNextPath();
        final String propertyPath = streamPath.getNodePath() + "/" + NodeStreamPath.PROPERTY_NAME;
        try {
            if(node.hasProperty(propertyPath)) {
                final Property p = node.getProperty(propertyPath);
                currentStream = p.getStream();
                log.debug("Switched to the InputStream of Property {}", p.getPath());
            } else {
                currentStream = null;
                log.debug("Property {} not found, end of stream", node.getPath() + "/" + propertyPath);
            }
        } catch(RepositoryException re) {
View Full Code Here

            while(!paths.isEmpty()) {
                final String path = paths.remove(0);
                if(session.itemExists(path)) {
                    final Item it = session.getItem(path);
                    if(!it.isNode()) {
                        final Property p = (Property)it;
                        final Node n = p.getParent();
                        if(!n.hasProperty(SlingbucksConstants.LAST_MODIFIED_PROPERTY_NAME)) {
                            log.debug("Node {} doesn't have property {}, ignored", n.getPath(), SlingbucksConstants.LAST_MODIFIED_PROPERTY_NAME);
                        } else {
                            Calendar lastMod = n.getProperty(SlingbucksConstants.LAST_MODIFIED_PROPERTY_NAME).getDate();
                            if(System.currentTimeMillis() - lastMod.getTime().getTime() < WAIT_AFTER_LAST_CHANGE_MSEC) {
View Full Code Here

            if (newPropertyValues == null) {
                assertThat(session.getNode("/content").hasProperty(PROP_NAME), equalTo(false));
                return;
            }

            Property newProp = session.getNode("/content").getProperty(PROP_NAME);
            if (newPropertyValues instanceof String) {
                assertThat("property.isMultiple", newProp.isMultiple(), equalTo(Boolean.FALSE));
                assertThat(newProp.getString(), equalTo((String) newPropertyValues));

            } else {

                String[] expectedValues = (String[]) newPropertyValues;
                assertThat("property.isMultiple", newProp.isMultiple(), equalTo(Boolean.TRUE));

                Value[] values = session.getNode("/content").getProperty(PROP_NAME).getValues();

                assertThat(values.length, equalTo(expectedValues.length));
                for (int i = 0; i < values.length; i++) {
View Full Code Here

                }

            } else {

                // property move manually
                Property sourceProperty = (Property) sourceItem;

                // create destination property
                Node destParent = (Node) session.getItem(property.getParentPath());
                checkoutIfNecessary(destParent, changes, versioningConfiguration);
                CopyOperation.copy(sourceProperty, destParent, null);

                // remove source property (if not just copying)
                if (isMove) {
                    checkoutIfNecessary(sourceProperty.getParent(), changes, versioningConfiguration);
                    sourceProperty.remove();
                }
            }

            // make sure the property is not deleted even in case for a given
            // property both @MoveFrom and @Delete is set
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();
                    List valuesList;
                    if (p.isMultiple()) {
                        switch (p.getType()) {
                            case PropertyType.STRING:
                                valuesList = new ArrayList<String>();
                                for (Value v : p.getValues()) {
                                    valuesList.add(v.getString());
                                }
                                map.put(p.getName(), valuesList.toArray());
                                break;
                            case PropertyType.NAME:
                                valuesList = new ArrayList<String>();
                                for (Value v : p.getValues()) {
                                    valuesList.add(v.getString());
                                }
                                map.put(p.getName(), valuesList.toArray());
                                break;
                        }
                    } else 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) {
                    throw new UnsupportedOperationException();
                }

                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);
                    }
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.