Search in sources :

Example 16 with Property

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

the class PropertyItemIsModifiedTest method testPersistentPropertyItemIsModified.

/**
     * Test if Item.isModified() returns false for an already exixting and modified
     * PropertyItem after the current node is saved (persistent).
     *
     * @see javax.jcr.Item#isModified()
     */
public void testPersistentPropertyItemIsModified() throws RepositoryException {
    Property testProperty = testNode.setProperty(propertyName1, "test1");
    testNode.save();
    testProperty.setValue("test2");
    testNode.save();
    Item testPropertyItem = superuser.getItem(testProperty.getPath());
    // check testPropertyItem.isModified() after save
    assertFalse("Item.isModified() must return false after an existing Property is modified and the current Node is saved", testPropertyItem.isModified());
}
Also used : Item(javax.jcr.Item) Property(javax.jcr.Property)

Example 17 with Property

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

the class PropertyUtil method searchMultivalProp.

/**
     * Helper method to find a multivalue property.
     *
     * @param node the node to start the search from.
     * @return a multivalue property or null if not found any.
     */
public static Property searchMultivalProp(Node node) throws RepositoryException {
    Property multiVal = null;
    for (PropertyIterator props = node.getProperties(); props.hasNext(); ) {
        Property property = props.nextProperty();
        if (property.getDefinition().isMultiple()) {
            multiVal = property;
            break;
        }
    }
    if (multiVal == null) {
        for (NodeIterator nodes = node.getNodes(); nodes.hasNext(); ) {
            Node n = nodes.nextNode();
            multiVal = searchMultivalProp(n);
            if (multiVal != null) {
                break;
            }
        }
    }
    return multiVal;
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 18 with Property

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

the class PropertyUtil method searchMultivalProp.

/**
     * Helper method to find a multivalue property of a given type.
     *
     * @param node the node to start the search from.
     * @param type the property type.
     * @return a multivalue property or null if not found any.
     */
public static Property searchMultivalProp(Node node, int type) throws RepositoryException {
    Property multiVal = null;
    for (PropertyIterator props = node.getProperties(); props.hasNext(); ) {
        Property property = props.nextProperty();
        if (property.getDefinition().isMultiple() && property.getType() == type) {
            multiVal = property;
            break;
        }
    }
    if (multiVal == null) {
        for (NodeIterator nodes = node.getNodes(); nodes.hasNext(); ) {
            Node n = nodes.nextNode();
            multiVal = searchMultivalProp(n, type);
            if (multiVal != null) {
                break;
            }
        }
    }
    return multiVal;
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 19 with Property

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

the class ReferencePropertyTest method testEquals.

/**
     * Tests equals method of Reference value.
     */
public void testEquals() throws RepositoryException {
    Property prop2 = referencedNode.getProperty(jcrUUID);
    assertTrue("Incorrect equals method of Reference value.", PropertyUtil.equalValues(prop2.getValue(), prop.getValue()));
}
Also used : Property(javax.jcr.Property)

Example 20 with Property

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

the class ReferencePropertyTest method testPropValue.

/**
     * Tests if the referenced node has this property in its referers list in
     * case the property is not transient. Also tests in theis case that the
     * node retrieved by property.getNode() is the same as the one retrieved by
     * session.getNodeByUUID() .
     */
public void testPropValue() throws RepositoryException {
    Node referenced = session.getNodeByUUID(prop.getString());
    PropertyIterator referers = referenced.getReferences();
    if (!prop.isNew()) {
        boolean found = false;
        while (referers.hasNext()) {
            Property propp = referers.nextProperty();
            if (propp.isSame(prop)) {
                found = true;
            }
        }
        assertTrue("Referencing property of node " + referenced.getName() + " not found.", found);
        assertTrue("Referenced node retrieved with getNode is different " + "from the node retrieved with getNodeByUUID", referenced.isSame(referencedNode));
    } else {
        log.println("Reference property " + prop.getName() + " is in transient state.");
    }
}
Also used : Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Aggregations

Property (javax.jcr.Property)445 Node (javax.jcr.Node)252 Value (javax.jcr.Value)99 Test (org.junit.Test)87 Session (javax.jcr.Session)78 PropertyIterator (javax.jcr.PropertyIterator)68 RepositoryException (javax.jcr.RepositoryException)64 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)47 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)37 ValueFormatException (javax.jcr.ValueFormatException)34 QValue (org.apache.jackrabbit.spi.QValue)29 ArrayList (java.util.ArrayList)24 NodeIterator (javax.jcr.NodeIterator)24 QValueValue (org.apache.jackrabbit.spi.commons.value.QValueValue)23 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)20 Item (javax.jcr.Item)19 PathNotFoundException (javax.jcr.PathNotFoundException)17 InvalidItemStateException (javax.jcr.InvalidItemStateException)16 Version (javax.jcr.version.Version)16 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)15