public static Property getProperty()

in src/main/java/org/apache/sling/jcr/classloader/internal/Util.java [84:137]


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