Package javax.jcr

Examples of javax.jcr.Property


    private Property getProperty() {
        return getItem();
    }

    private InputStream getInputStream() {
        Property prop = getProperty();

        try {
            return prop.getBinary().getStream();
        } catch (RepositoryException re) {
            LOGGER.error("getInputStream: Problem accessing the property "
                + getPath() + " stream", re);
        }
View Full Code Here


                                    "removed in future versions. Please adjust your code.");
                    }
                    return (AdapterType) new JcrNodeResource(resourceResolverFactory.getResourceResolver(node
                            .getSession()), node.getPath(), node, resourceResolverFactory.getDynamicClassLoader());
                } else if (adaptable instanceof Property) {
                    final Property property = (Property) adaptable;
                    if ( !loggedPropertyWarning ) {
                        loggedPropertyWarning = true;
                        logger.warn("Adapting a JCR property to a resource is deprecated. This feature will be " +
                                    "removed in future versions. Please adjust your code.");
                    }
                    return (AdapterType) new JcrPropertyResource(resourceResolverFactory.getResourceResolver(property
                            .getSession()), property.getPath(), property);
                }
            } catch (final RepositoryException e) {
                logger.error("Unable to adapt JCR Item to a Resource", e);
            }
            return null;
View Full Code Here

        }

        try {
            final String key = escapeKeyName(name);
            if (node.hasProperty(key)) {
                final Property prop = node.getProperty(key);
                return cacheProperty(prop);
            }
        } catch (final RepositoryException re) {
            throw new IllegalArgumentException(re);
        }

        try {
            // for compatibility with older versions we use the (wrong) ISO9075 path
            // encoding
            final String oldKey = ISO9075.encodePath(name);
            if (node.hasProperty(oldKey)) {
                final Property prop = node.getProperty(oldKey);
                return cacheProperty(prop);
            }
        } catch (final RepositoryException re) {
            // we ignore this
        }
View Full Code Here

    void readFully() {
        if (!fullyRead) {
            try {
                final PropertyIterator pi = node.getProperties();
                while (pi.hasNext()) {
                    final Property prop = pi.nextProperty();
                    this.cacheProperty(prop);
                }
                fullyRead = true;
            } catch (final RepositoryException re) {
                throw new IllegalArgumentException(re);
View Full Code Here

        }

        try {
            final String key = escapeKeyName(name);
            if (node.hasProperty(key)) {
                final Property prop = node.getProperty(key);
                return cacheProperty(prop);
            }
        } catch (final RepositoryException re) {
            throw new IllegalArgumentException(re);
        }

        try {
            // for compatibility with older versions we use the (wrong) ISO9075 path
            // encoding
            final String oldKey = ISO9075.encodePath(name);
            if (node.hasProperty(oldKey)) {
                final Property prop = node.getProperty(oldKey);
                return cacheProperty(prop);
            }
        } catch (final RepositoryException re) {
            // we ignore this
        }
View Full Code Here

    void readFully() {
        if (!fullyRead) {
            try {
                final PropertyIterator pi = node.getProperties();
                while (pi.hasNext()) {
                    final Property prop = pi.nextProperty();
                    this.cacheProperty(prop);
                }
                fullyRead = true;
            } catch (final RepositoryException re) {
                throw new IllegalArgumentException(re);
View Full Code Here

                        ValueMap props = resource.adaptTo(ValueMap.class);
                        Object value = props.get(propertyName);
                        if (value==null) {
                            throw new PathNotFoundException();
                        }
                        Property prop = mock(Property.class);
                        when(prop.getName()).thenReturn(propertyName);
                        if (value instanceof String) {
                            when(prop.getString()).thenReturn((String)value);
                        }
                        else if (value instanceof Boolean) {
                            when(prop.getBoolean()).thenReturn((Boolean)value);
                        }
                        return prop;
                    }
                    else {
                        throw new PathNotFoundException();
View Full Code Here

            Session session = null;
            try {
                session = this.handler.getClassLoaderWriter().createSession();
                final Node node = (Node)session.getItem(this.getPath());
                // resolve the URLs item to a property
                final Property property = Util.getProperty(node);
                if (property == null) {
                    throw failure("connect",
                        "Multivalue property not supported", null);
                }

                final byte[] contents = Util.getBytes(node);

                // values to set later
                String contentType;
                String contentEncoding = null; // no defined content encoding
                long lastModified;

                Node parent = property.getParent();
                if (parent.hasProperty("jcr:lastModified")) {
                    lastModified = parent.getProperty("jcr:lastModified").getLong();
                } else {
                    lastModified = 0;
                }

                if (parent.hasProperty("jcr:mimeType")) {
                    contentType = parent.getProperty("jcr:mimeType").getString();
                } else {
                    contentType = guessContentTypeFromName(node.getName());
                    if (contentType == null) {
                        contentType = (property.getType() == PropertyType.BINARY)
                                ? APPLICATION_OCTET
                                : TEXT_PLAIN;
                    }
                }

                if (parent.hasProperty("jcr:encoding")) {
                    contentEncoding = parent.getProperty("jcr:encoding").getString();
                }

                log.debug(
                    "connect: Using property '{}' with content type '{}' for {} bytes",
                    new Object[] { property.getPath(), contentType,
                        new Integer(contentLength) });

                // set the fields
                this.contents = contents;
                this.contentType = contentType;
View Full Code Here

            long modificationTime = -1;
            final Node targetNode = promoteNode();
            try {
                if (targetNode.hasProperty(JCR_LASTMODIFIED)) {
                    // We don't check node type, so JCR_LASTMODIFIED might not be a long
                    final Property prop = targetNode.getProperty(JCR_LASTMODIFIED);
                    try {
                        modificationTime = prop.getLong();
                    } catch (final ValueFormatException vfe) {
                        LOGGER.debug("Property {} cannot be converted to a long, ignored ({})",
                            prop.getPath(), vfe);
                    }
                }
            } catch (final RepositoryException re) {
                report(re);
            }
            internalPut(MODIFICATION_TIME, modificationTime);
            return modificationTime;
        } else if (CONTENT_LENGTH.equals(key)) {
            long contentLength = -1;
            final Node targetNode = promoteNode();
            try {
                // if the node has a jcr:data property, use that property
                if (targetNode.hasProperty(JCR_DATA)) {
                    final Property prop = targetNode.getProperty(JCR_DATA);
                    contentLength = JcrItemResource.getContentLength(prop);
                } else {
                    // otherwise try to follow default item trail
                    Item item = getPrimaryItem(targetNode);
                    while (item != null && item.isNode()) {
                        item = getPrimaryItem((Node) item);
                    }
                    if ( item != null ) {
                        final Property data = (Property) item;

                        // set the content length property as a side effect
                        // for resources which are not nt:file based and whose
                        // data is not in jcr:content/jcr:data this will lazily
                        // set the correct content length
View Full Code Here

    }

    public void testProperty() throws Exception {
        this.rootNode.getSession().refresh(false);
        ValueMap map = createProperty(rootNode, "Sample Value For Prop");
        Property prop = rootNode.getProperty(PROP_NAME);

        // explicit type
        Property result = map.get(PROP_NAME, Property.class);
        assertTrue(prop.isSame(result));

        // type by default value
        Property defaultValue = rootNode.getProperty("jcr:primaryType");
        result = map.get(PROP_NAME, defaultValue);
        assertTrue(prop.isSame(result));

        // default value
        result = map.get(PROP_NAME_NIL, defaultValue);
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.