Search in sources :

Example 41 with Property

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

the class DocumentViewImportTest method checkXmlTextNode.

/**
     * Tests if xmltext in a body of a xml element is correctly imported to a
     * node with name jcr:xmltext and that the value of the text is stored in
     * the singlevalued jcr:xmlcharacters property of String type.
     *
     * @throws RepositoryException
     */
public void checkXmlTextNode(Node node) throws RepositoryException, IOException {
    if (node.hasNode(JCR_XMLTEXT)) {
        Node xmlNode = node.getNode(JCR_XMLTEXT);
        if (xmlNode.hasProperty(JCR_XMLCHAR)) {
            Property prop = xmlNode.getProperty(JCR_XMLCHAR);
            // correct type?
            assertTrue("Property " + prop.getPath() + " is not of type String.", prop.getType() == PropertyType.STRING);
            // correct text?
            // todo remove the trim as only the white spaces of the current text should be collected
            assertEquals("Xml text is not correctly stored.", xmltext.trim(), prop.getString().trim());
            // only jcr:xmlcharacters property beneath the jcr:primaryType
            PropertyIterator iter = xmlNode.getProperties();
            assertTrue(JCR_XMLCHAR + " is not the only property beneath " + jcrPrimaryType + " in a " + JCR_XMLTEXT + " node.", getSize(iter) == 2);
        } else {
            fail("Xmltext not stored in property named " + JCR_XMLCHAR);
        }
    } else {
        fail("Xmltext not imported to Node named " + JCR_XMLTEXT);
    }
}
Also used : Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 42 with Property

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

the class ExportDocViewTest method setExportInvalidXmlNames.

/**
     * Loops through all child items of a given node to test if items with
     * invalid xml name are exported. (chapter 6.4.2.4 of the JCR
     * specification).
     *
     * @param node the root node of the tree to search
     * @param elem the parent element of the element to which the parent node of
     *             the given node is exported.
     * @throws RepositoryException
     */
private boolean setExportInvalidXmlNames(Node node, Element elem, boolean isSet) throws RepositoryException {
    if (!XMLChar.isValidName(node.getName())) {
        if (elem != null) {
            exportInvalidXmlNames = true;
            isSet = true;
        } else {
            exportInvalidXmlNames = false;
            isSet = true;
        }
    }
    // try properties
    if (!isSet) {
        PropertyIterator iter = node.getProperties();
        while (iter.hasNext()) {
            Property prop = iter.nextProperty();
            if (!exportMultivalProps && prop.getDefinition().isMultiple()) {
                continue;
            }
            if (!XMLChar.isValidName(prop.getName())) {
                // property exported?
                exportInvalidXmlNames = isExportedProp(prop, elem);
                isSet = true;
            }
        }
    }
    // try child nodes
    if (!isSet && !noRecurse) {
        // search again
        NodeIterator iter = node.getNodes();
        while (iter.hasNext()) {
            Node n = iter.nextNode();
            Element el = findElem(n, elem);
            isSet = setExportInvalidXmlNames(n, el, isSet);
        }
    }
    return isSet;
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) Element(org.w3c.dom.Element) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 43 with Property

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

the class ExportDocViewTest method setExportMultivalProps.

/**
     * Set the exportMultivalProps flag. Traverses the tree given by the node
     * and searches a multivalue property which is exported to an attribute of a
     * element of an element tree. (chapter 6.4.2.5 of the JCR specification).
     *
     * @param node
     * @param elem
     * @throws RepositoryException
     */
private boolean setExportMultivalProps(Node node, Element elem, boolean isSet) throws RepositoryException {
    Property[] props = searchMultivalProps(node);
    // multivalued property with valid xml name
    if (props[0] != null) {
        exportMultivalProps = isExportedProp(props[0], elem);
        isSet = true;
    } else {
        // invalid xml named multivalue property exported
        if (props[1] != null) {
            exportMultivalProps = isExportedProp(props[1], elem);
            if (!exportMultivalProps && exportInvalidXmlNames) {
                isSet = true;
            }
        }
    }
    if (!isSet && !noRecurse) {
        // search again
        NodeIterator iter = node.getNodes();
        while (iter.hasNext()) {
            Node n = iter.nextNode();
            Element el = findElem(n, elem);
            if (el != null) {
                isSet = setExportMultivalProps(n, el, isSet);
            } else {
                isSet = false;
            }
        }
    }
    return isSet;
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) Element(org.w3c.dom.Element) Property(javax.jcr.Property)

Example 44 with Property

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

the class ExportDocViewTest method compareNode.

/**
     * Compares the given node with the given element. Comparison is succesful
     * if the number of exported child nodes and exported properties match the
     * found child elements and attributes considering the possible exceptions
     * and if the comparison of the properties of the node with the attributes
     * of the element is successful too.
     *
     * @param node
     * @param elem
     * @throws RepositoryException
     */
private void compareNode(Node node, Element elem) throws RepositoryException, IOException {
    // count the child nodes and compare with the exported child elements
    compareChildNumber(node, elem);
    // count the properties and compare with attributes exported
    comparePropNumber(node, elem);
    PropertyIterator propIter = node.getProperties();
    while (propIter.hasNext()) {
        Property prop = propIter.nextProperty();
        Attr attr = findAttribute(prop, elem);
        checkAttribute(prop, attr);
        if (attr != null) {
            compareProperty(prop, attr);
        }
    }
}
Also used : PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property) Attr(org.w3c.dom.Attr)

Example 45 with Property

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

the class GetWeakReferencesTest method testSingleValue.

public void testSingleValue() throws RepositoryException {
    Value weakRef = vf.createValue(target, true);
    referring.setProperty(propertyName1, weakRef);
    superuser.save();
    PropertyIterator it = target.getWeakReferences();
    assertTrue("no weak references returned", it.hasNext());
    Property p = it.nextProperty();
    assertEquals("wrong weak reference property", referring.getProperty(propertyName1).getPath(), p.getPath());
    assertFalse("no more weak references expected", it.hasNext());
}
Also used : Value(javax.jcr.Value) 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