Search in sources :

Example 16 with PropertyIterator

use of javax.jcr.PropertyIterator in project sling by apache.

the class ConfigNodeConverter method loadProperties.

/** Load properties of n into d */
protected void loadProperties(Dictionary<String, Object> d, Node n) throws RepositoryException {
    final PropertyIterator pi = n.getProperties();
    while (pi.hasNext()) {
        final Property p = pi.nextProperty();
        final String name = p.getName();
        // ignore jcr: and similar properties
        if (name.contains(":")) {
            continue;
        }
        if (p.getDefinition().isMultiple()) {
            Object[] data = null;
            final Value[] values = p.getValues();
            int i = 0;
            for (Value v : values) {
                Object o = convertValue(v);
                if (i == 0) {
                    data = (Object[]) Array.newInstance(o.getClass(), values.length);
                }
                data[i++] = o;
            }
            // create empty array in case no value is specified
            if (data == null) {
                data = new String[0];
            }
            d.put(name, data);
        } else {
            final Object o = convertValue(p.getValue());
            if (o != null) {
                d.put(name, o);
            }
        }
    }
}
Also used : PropertyIterator(javax.jcr.PropertyIterator) Value(javax.jcr.Value) Property(javax.jcr.Property)

Example 17 with PropertyIterator

use of javax.jcr.PropertyIterator in project sling by apache.

the class JcrCommand method nodeToResource.

protected ResourceProxy nodeToResource(Node node) throws RepositoryException {
    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);
        }
    }
    return resource;
}
Also used : PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy)

Example 18 with PropertyIterator

use of javax.jcr.PropertyIterator in project acs-aem-commons by Adobe-Consulting-Services.

the class EntryNodeToCacheContentHandler method retrieveProperties.

private void retrieveProperties() throws RepositoryException {
    final PropertyIterator propertyIterator = entryNode.getProperties();
    while (propertyIterator.hasNext()) {
        final Property property = propertyIterator.nextProperty();
        final String propName = property.getName();
        final Value value = property.getValue();
        if (propName.equals(JCRHttpCacheStoreConstants.PN_CONTENT_TYPE)) {
            contentType = value.getString();
        } else if (propName.equals(JCRHttpCacheStoreConstants.PN_CHAR_ENCODING)) {
            charEncoding = value.getString();
        } else if (propName.equals(JCRHttpCacheStoreConstants.PN_STATUS)) {
            status = (int) value.getLong();
        }
    }
}
Also used : PropertyIterator(javax.jcr.PropertyIterator) Value(javax.jcr.Value) Property(javax.jcr.Property)

Example 19 with PropertyIterator

use of javax.jcr.PropertyIterator in project acs-aem-commons by Adobe-Consulting-Services.

the class EntryNodeToCacheContentHandler method retrieveHeaders.

private void retrieveHeaders() throws RepositoryException {
    if (entryNode.hasNode(JCRHttpCacheStoreConstants.PATH_HEADERS)) {
        final Node headerNode = entryNode.getNode(JCRHttpCacheStoreConstants.PATH_HEADERS);
        final PropertyIterator propertyIterator = headerNode.getProperties();
        while (propertyIterator.hasNext()) {
            final Property property = propertyIterator.nextProperty();
            final String name = property.getName();
            if (!isNativeProperty(name)) {
                Value[] values = property.getValues();
                List<String> stringValues = new ArrayList<String>(values.length);
                for (Value value : values) {
                    stringValues.add(value.getString());
                }
                headers.put(name, stringValues);
            }
        }
    }
}
Also used : Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Value(javax.jcr.Value) ArrayList(java.util.ArrayList) Property(javax.jcr.Property)

Example 20 with PropertyIterator

use of javax.jcr.PropertyIterator in project jackrabbit by apache.

the class ChildrenCollectorFilter method collectProperties.

public static PropertyIterator collectProperties(Node node, String[] nameGlobs) throws RepositoryException {
    Collection<Item> properties = Collections.emptySet();
    PropertyIterator pit = node.getProperties();
    while (pit.hasNext()) {
        Property p = pit.nextProperty();
        if (matches(p.getName(), nameGlobs)) {
            properties = addToCollection(properties, p);
        }
    }
    return new PropertyIteratorAdapter(properties);
}
Also used : Item(javax.jcr.Item) PropertyIteratorAdapter(org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Aggregations

PropertyIterator (javax.jcr.PropertyIterator)130 Property (javax.jcr.Property)97 Node (javax.jcr.Node)79 NodeIterator (javax.jcr.NodeIterator)31 RepositoryException (javax.jcr.RepositoryException)28 Value (javax.jcr.Value)28 Session (javax.jcr.Session)21 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)19 HashSet (java.util.HashSet)14 PathNotFoundException (javax.jcr.PathNotFoundException)13 HashMap (java.util.HashMap)12 AccessDeniedException (javax.jcr.AccessDeniedException)7 Item (javax.jcr.Item)5 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)5 JSONObject (org.codehaus.jettison.json.JSONObject)5 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)4 AccessControlException (java.security.AccessControlException)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 RepositoryFileDaoReferentialIntegrityException (org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException)4