Search in sources :

Example 56 with PropertyIterator

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

the class TreeComparator method showTree.

/**
     * Recursive display of source and target tree
     */
public void showTree(Node n, int level) throws RepositoryException {
    StringBuffer sb = new StringBuffer();
    for (int t = 0; t < level; t++) {
        sb.append("-");
    }
    sb.append(n.getName() + " ");
    sb.append(n.getPrimaryNodeType().getName() + " [ ");
    PropertyIterator pi = n.getProperties();
    while (pi.hasNext()) {
        Property p = (Property) pi.next();
        sb.append(p.getName() + " ");
    }
    sb.append("]");
    sc.log(sb.toString());
    NodeIterator ni = n.getNodes();
    while (ni.hasNext()) {
        showTree((Node) ni.next(), level + 1);
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 57 with PropertyIterator

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

the class NodeImpl method getWeakReferences.

/**
     * {@inheritDoc}
     */
public PropertyIterator getWeakReferences() throws RepositoryException {
    // check state of this instance
    sanityCheck();
    // shortcut if node isn't referenceable
    if (!isNodeType(NameConstants.MIX_REFERENCEABLE)) {
        return PropertyIteratorAdapter.EMPTY;
    }
    Value ref = getSession().getValueFactory().createValue(this, true);
    List<Property> props = new ArrayList<Property>();
    QueryManagerImpl qm = (QueryManagerImpl) getSession().getWorkspace().getQueryManager();
    for (Node n : qm.getWeaklyReferringNodes(this)) {
        for (PropertyIterator it = n.getProperties(); it.hasNext(); ) {
            Property p = it.nextProperty();
            if (p.getType() == PropertyType.WEAKREFERENCE) {
                Collection<Value> refs;
                if (p.isMultiple()) {
                    refs = Arrays.asList(p.getValues());
                } else {
                    refs = Collections.singleton(p.getValue());
                }
                if (refs.contains(ref)) {
                    props.add(p);
                }
            }
        }
    }
    return new PropertyIteratorAdapter(props);
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) PropertyIteratorAdapter(org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter) Value(javax.jcr.Value) InternalValue(org.apache.jackrabbit.core.value.InternalValue) ArrayList(java.util.ArrayList) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property) QueryManagerImpl(org.apache.jackrabbit.core.query.QueryManagerImpl)

Example 58 with PropertyIterator

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

the class BTreeManager method getProperties.

/**
     * Returns a {@link SizedIterator} of the properties of <code>node</code>
     * which excludes the <code>jcr.primaryType</code> property.
     */
@SuppressWarnings({ "deprecation", "unchecked" })
protected SizedIterator<Property> getProperties(Node node) throws RepositoryException {
    final PropertyIterator properties = node.getProperties();
    long size = properties.getSize();
    for (Iterator<String> ignored = ignoredProperties.iterator(); size > 0 && ignored.hasNext(); ) {
        if (node.hasProperty(ignored.next())) {
            size--;
        }
    }
    return getSizedIterator(filterProperties(properties), size);
}
Also used : PropertyIterator(javax.jcr.PropertyIterator)

Example 59 with PropertyIterator

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

the class AbstractNode method getProperty.

/**
     * Returns the property at the given relative path from this node.
     * <p>
     * The default implementation looks up the parent node of the given
     * relative path and iterates through the properties of that node to
     * find and return the identified property.
     *
     * @param relPath relative path of the property
     * @return property
     * @throws PathNotFoundException if the property is not found
     * @throws RepositoryException if an error occurs
     */
public Property getProperty(String relPath) throws PathNotFoundException, RepositoryException {
    // Corner case, remove any "/." self references at the end of the path
    while (relPath.endsWith("/.")) {
        relPath = relPath.substring(0, relPath.length() - 2);
    }
    // Find the parent node of the identified property
    Node node = this;
    int slash = relPath.lastIndexOf('/');
    if (slash == 0) {
        node = getSession().getRootNode();
        relPath = relPath.substring(1);
    } else if (slash > 0) {
        node = getNode(relPath.substring(0, slash));
        relPath = relPath.substring(slash + 1);
    }
    // Look for the named property. Must iterate and re-check for the name
    // since the client could have used an invalid path like "./a|b".
    PropertyIterator properties = node.getProperties(relPath);
    while (properties.hasNext()) {
        Property property = (Property) properties.next();
        if (relPath.equals(property.getName())) {
            return property;
        }
    }
    throw new PathNotFoundException("Property not found: " + relPath);
}
Also used : Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) PathNotFoundException(javax.jcr.PathNotFoundException) Property(javax.jcr.Property)

Example 60 with PropertyIterator

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

the class NodeReadMethodsTest method testGetProperties.

/**
     * Test if all returned items are of type node.
     */
public void testGetProperties() throws RepositoryException {
    PropertyIterator properties = testRootNode.getProperties();
    while (properties.hasNext()) {
        Item item = (Item) properties.next();
        assertFalse("Item is not a property", item.isNode());
    }
}
Also used : Item(javax.jcr.Item) PropertyIterator(javax.jcr.PropertyIterator)

Aggregations

PropertyIterator (javax.jcr.PropertyIterator)96 Property (javax.jcr.Property)68 Node (javax.jcr.Node)57 NodeIterator (javax.jcr.NodeIterator)28 Value (javax.jcr.Value)23 Test (org.junit.Test)16 RepositoryException (javax.jcr.RepositoryException)15 Session (javax.jcr.Session)15 ArrayList (java.util.ArrayList)14 HashSet (java.util.HashSet)10 PathNotFoundException (javax.jcr.PathNotFoundException)8 HashMap (java.util.HashMap)5 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)5 NodeImpl (org.apache.jackrabbit.core.NodeImpl)5 PropertyImpl (org.apache.jackrabbit.core.PropertyImpl)5 NoSuchElementException (java.util.NoSuchElementException)3 AccessDeniedException (javax.jcr.AccessDeniedException)3 InvalidItemStateException (javax.jcr.InvalidItemStateException)3 ValueFormatException (javax.jcr.ValueFormatException)3 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)3