Package javax.jcr

Examples of javax.jcr.Property


    @Test
    public void testValueArray() throws RepositoryException {
        Value[] value1 = new Value[] { this.session.getValueFactory().createValue("aaa"),
                this.session.getValueFactory().createValue("bbb") };
        this.node1.setProperty("prop1", value1);
        Property prop1 = this.node1.getProperty("prop1");

        Value[] values = prop1.getValues();
        for (int i = 0; i < values.length; i++) {
            assertEquals("value #" + i, value1[i].getString(), values[i].getString());
        }

        Value[] value2 = new Value[] { this.session.getValueFactory().createValue("cc") };
        prop1.setValue(value2);
        values = prop1.getValues();
        for (int i = 0; i < values.length; i++) {
            assertEquals("value #" + i, value2[i].getString(), values[i].getString());
        }

        assertTrue(prop1.isMultiple());
        assertTrue(prop1.getDefinition().isMultiple());
        assertArrayEquals(new long[] { 2 }, prop1.getLengths());
    }
View Full Code Here


    @Override
    protected byte[] execute0(Session session) throws RepositoryException, IOException {

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

        Property property;
        if (node.hasProperty("jcr:data")) {
          property = node.getProperty("jcr:data");
        } else {
          if (!node.hasNode("jcr:content")) {
              return null;
          }
 
          Node contentNode = node.getNode("jcr:content");
 
          if (!contentNode.hasProperty("jcr:data")) {
              return null;
          }
 
          property = contentNode.getProperty("jcr:data");
        }

        if (property.getType() == PropertyType.BINARY) {
            Binary binary = property.getBinary();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            try {
                byte[] buffer = new byte[2048];
                InputStream stream = binary.getStream();
                int read;
View Full Code Here

    }

    @Test
    public void testGetPrimaryItem() throws RepositoryException {
        Node dataParent = this.node1.addNode("dataParent");
        Property dataProperty = dataParent.setProperty(JcrConstants.JCR_DATA, "data");
        assertEquals(dataProperty, dataParent.getPrimaryItem());

        Node contentParent = this.node1.addNode("contentParent");
        Node contentNode = contentParent.addNode(JcrConstants.JCR_CONTENT);
        assertEquals(contentNode, contentParent.getPrimaryItem());
View Full Code Here

        final String path = cleanPath(name) + "/jcr:content/jcr:data";
        Session session = null;
        try {
            session = this.createSession();
            if ( session.itemExists(path) ) {
                final Property prop = (Property)session.getItem(path);
                final InputStream is = prop.getStream();
                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                int l = 0;
                final byte[] buf = new byte[2048];
                while ( (l = is.read(buf)) > -1 ) {
                    if ( l > 0 ) {
View Full Code Here

        final String path = cleanPath(name) + "/jcr:content/jcr:lastModified";
        Session session = null;
        try {
            session = this.createSession();
            if ( session.itemExists(path) ) {
                final Property prop = (Property)session.getItem(path);
                return prop.getLong();
            }
        } catch (final RepositoryException se) {
            logger.error("Cannot get last modification time for " + name, se);
        } finally {
            if ( session != null ) {
View Full Code Here

     *             repository.
     */
    public static Property getProperty(Item item) throws ValueFormatException,
            RepositoryException {

        Property prop;
        if (item.isNode()) {

            // check whether the node has a jcr:content node (e.g. nt:file)
            Node node = (Node) item;
            if (node.hasNode("jcr:content")) {
                node = node.getNode("jcr:content");
            }

            // if the node has a jcr:data property, use that property
            if (node.hasProperty("jcr:data")) {

                prop = node.getProperty("jcr:data");

            } else {

                // otherwise try to follow default item trail
                try {
                    item = node.getPrimaryItem();
                    while (item.isNode()) {
                        item = ((Node) item).getPrimaryItem();
                    }
                    prop = (Property) item;
                } catch (ItemNotFoundException infe) {
                    // we don't actually care, but log for completeness
                    log.debug("getProperty: No primary items for "
                        + node.getPath(), infe);
                    return null;
                }
            }

        } else {

            prop = (Property) item;

        }

        // we get here with a property - otherwise an exception has already
        // been thrown
        if (prop.getDefinition().isMultiple()) {
            log.error("{} is a multivalue property", prop.getPath());
            return null;
        } else if (prop.getType() == PropertyType.REFERENCE) {
            Node node = prop.getNode();
            log.info("Property {} refers to node {}; finding primary item",
                prop.getPath(), node.getPath());
            return getProperty(node);
        }

        return prop;
    }
View Full Code Here

        // Add all matching properties to result
        boolean isMulti = false;
        try {
            PropertyIterator it = node.getProperties(name);
            while (it.hasNext()) {
                Property prop = it.nextProperty();
                if (prop.getDefinition().isMultiple()) {
                    isMulti = true;
                    Value[] values = prop.getValues();
                    for (int i = 0; i < values.length; i++) {
                        items.add(wrap(values[i]));
                    }
                } else {
                    items.add(wrap(prop.getValue()));
                }
            }
        } catch (RepositoryException e) {
            log.debug("RepositoryException while collecting Node properties", e);
        }
View Full Code Here

        final ResourceResolver resolver = this.context.mock(ResourceResolver.class);
        for (final Entry<Object, Integer> data : testData.entrySet()) {
            final String stringValue = data.getKey().toString();
            final long stringByteLength =  stringValue.getBytes("UTF-8").length;
            final Property property = this.context.mock(Property.class, stringValue);
            this.context.checking(new Expectations() {{
                ignoring(resolver);
                allowing(property).getParent();
                allowing(property).getName();
                allowing(property).isMultiple(); will(returnValue(false));
View Full Code Here

    public PropertyIterator getProperties(String namePattern) throws RepositoryException {
        PropertyIterator iterator = getProperties();
        List<Property> properties = new ArrayList<Property>();

        while (iterator.hasNext()) {
            Property p = iterator.nextProperty();
            String name = p.getName();
            if (ChildrenCollectorFilter.matches(name, namePattern)) {
                properties.add(p);
            }
        }
View Full Code Here

                // otherwise it is the node of this resource
                Node content = node.isNodeType(NT_FILE)
                        ? node.getNode(JCR_CONTENT)
                        : node;

                Property data;

                // if the node has a jcr:data property, use that property
                if (content.hasProperty(JCR_DATA)) {
                    data = content.getProperty(JCR_DATA);
                } else {
                    // otherwise try to follow default item trail
                    try {
                        Item item = content.getPrimaryItem();
                        while (item.isNode()) {
                            item = ((Node) item).getPrimaryItem();
                        }
                        data = (Property) item;

                    } catch (ItemNotFoundException infe) {
                        // we don't actually care, but log for completeness
                        LOGGER.debug("getInputStream: No primary items for {}", toString(), infe);
                        data = null;
                    }
                }

                if (data != null) {
                    return data.getBinary().getStream();
                }

            } catch (RepositoryException re) {
                LOGGER.error("getInputStream: Cannot get InputStream for " + this,
                    re);
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.