Search in sources :

Example 16 with QValue

use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.

the class DefinitionUtil method createQPropertyDefinition.

/**
     * 
     * @param declaringNodeType
     * @param pdefElement
     * @param resolver
     * @param qValueFactory
     * @return
     * @throws RepositoryException
     */
static QPropertyDefinition createQPropertyDefinition(Name declaringNodeType, Element pdefElement, NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException {
    QPropertyDefinitionBuilder builder = new QPropertyDefinitionBuilder();
    buildQItemDefinition(declaringNodeType, pdefElement, resolver, builder);
    if (pdefElement.hasAttribute(REQUIREDTYPE_ATTRIBUTE)) {
        builder.setRequiredType(PropertyType.valueFromName(pdefElement.getAttribute(REQUIREDTYPE_ATTRIBUTE)));
    }
    if (pdefElement.hasAttribute(MULTIPLE_ATTRIBUTE)) {
        builder.setMultiple(Boolean.valueOf(pdefElement.getAttribute(MULTIPLE_ATTRIBUTE)));
    }
    if (pdefElement.hasAttribute(FULL_TEXT_SEARCHABLE_ATTRIBUTE)) {
        builder.setFullTextSearchable(Boolean.valueOf(pdefElement.getAttribute(FULL_TEXT_SEARCHABLE_ATTRIBUTE)));
    }
    if (pdefElement.hasAttribute(QUERY_ORDERABLE_ATTRIBUTE)) {
        builder.setQueryOrderable(Boolean.valueOf(pdefElement.getAttribute(QUERY_ORDERABLE_ATTRIBUTE)));
    }
    int requiredType = builder.getRequiredType();
    Element child = DomUtil.getChildElement(pdefElement, DEFAULTVALUES_ELEMENT, null);
    if (child != null) {
        ElementIterator it = DomUtil.getChildren(child, DEFAULTVALUE_ELEMENT, null);
        while (it.hasNext()) {
            String jcrVal = DomUtil.getText(it.nextElement());
            if (jcrVal == null) {
                jcrVal = "";
            }
            QValue qValue;
            if (requiredType == PropertyType.BINARY) {
                // TODO: improve
                Value v = new ValueFactoryQImpl(qValueFactory, resolver).createValue(jcrVal, requiredType);
                qValue = ValueFormat.getQValue(v, resolver, qValueFactory);
            } else {
                qValue = ValueFormat.getQValue(jcrVal, requiredType, resolver, qValueFactory);
            }
            builder.addDefaultValue(qValue);
        }
    }
    // else: no default values defined.
    child = DomUtil.getChildElement(pdefElement, VALUECONSTRAINTS_ELEMENT, null);
    if (child != null) {
        ElementIterator it = DomUtil.getChildren(child, VALUECONSTRAINT_ELEMENT, null);
        while (it.hasNext()) {
            String qValue = DomUtil.getText(it.nextElement());
            // in case of name and path constraint, the value must be
            // converted to SPI values
            // TODO: tobefixed. path-constraint may contain trailing *
            builder.addValueConstraint(ValueConstraint.create(requiredType, qValue, resolver));
        }
    }
    child = DomUtil.getChildElement(pdefElement, AVAILABLE_QUERY_OPERATORS_ELEMENT, null);
    if (child == null) {
        builder.setAvailableQueryOperators(new String[0]);
    } else {
        List<String> names = new ArrayList<String>();
        ElementIterator it = DomUtil.getChildren(child, AVAILABLE_QUERY_OPERATOR_ELEMENT, null);
        while (it.hasNext()) {
            String str = DomUtil.getText(it.nextElement());
            names.add(str);
        }
        builder.setAvailableQueryOperators(names.toArray(new String[names.size()]));
    }
    return builder.build();
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) QValue(org.apache.jackrabbit.spi.QValue) QPropertyDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QPropertyDefinitionBuilder) Element(org.w3c.dom.Element) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) ArrayList(java.util.ArrayList) ValueFactoryQImpl(org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl) ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint)

Example 17 with QValue

use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.

the class QValueTest method testPathValueGetPath.

public void testPathValueGetPath() throws RepositoryException {
    QValue v = factory.create(ROOT_PATH);
    assertTrue(v.getPath().equals(ROOT_PATH));
}
Also used : QValue(org.apache.jackrabbit.spi.QValue)

Example 18 with QValue

use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.

the class QValueTest method testWeakReferenceValueEquality.

public void testWeakReferenceValueEquality() throws RepositoryException {
    QValue v = factory.create(REFERENCE, PropertyType.WEAKREFERENCE);
    QValue otherV = factory.create(REFERENCE, PropertyType.WEAKREFERENCE);
    assertEquals("Weak reference values created from the same string must be equal.", v, otherV);
}
Also used : QValue(org.apache.jackrabbit.spi.QValue)

Example 19 with QValue

use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.

the class QValueTest method runBinarySerializableTest.

/**
     * Runs binary serializable test using a stream with a size of kBytes.
     * @param size in kBytes.
     */
private void runBinarySerializableTest(int size) throws Exception {
    File tmp = File.createTempFile("test", "bin");
    OutputStream out = new FileOutputStream(tmp);
    byte[] stuff = new byte[1024];
    Arrays.fill(stuff, (byte) 7);
    for (int i = 0; i < size; i++) {
        out.write(stuff);
    }
    out.close();
    InputStream in = new FileInputStream(tmp);
    QValue v = factory.create(in);
    in.close();
    tmp.delete();
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ObjectOutputStream oout = new ObjectOutputStream(bout);
    oout.writeObject(v);
    oout.close();
    ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
    ObjectInputStream oin = new ObjectInputStream(bin);
    QValue serValue = (QValue) oin.readObject();
    try {
        InputStream in1 = new BufferedInputStream(v.getStream());
        InputStream in2 = new BufferedInputStream(serValue.getStream());
        int i;
        while ((i = in1.read()) > -1) {
            assertEquals(i, in2.read());
        }
        assertEquals(in2.read(), -1);
        in1.close();
        in2.close();
    } finally {
        v.discard();
        serValue.discard();
    }
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) BufferedInputStream(java.io.BufferedInputStream) ObjectInputStream(java.io.ObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ObjectInputStream(java.io.ObjectInputStream)

Example 20 with QValue

use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.

the class QValueTest method testEmptyBinaryFromFile.

public void testEmptyBinaryFromFile() throws RepositoryException, IOException {
    File f = File.createTempFile("QValueFactoryImplTest", ".txt");
    f.deleteOnExit();
    QValue v = factory.create(f);
    assertEquals(PropertyType.BINARY, v.getType());
    assertEquals(0, v.getLength());
    assertEquals("", v.getString());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    spool(out, v.getStream());
    assertEquals("", new String(out.toByteArray()));
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File)

Aggregations

QValue (org.apache.jackrabbit.spi.QValue)125 Name (org.apache.jackrabbit.spi.Name)40 RepositoryException (javax.jcr.RepositoryException)23 Value (javax.jcr.Value)21 NodeId (org.apache.jackrabbit.spi.NodeId)21 Batch (org.apache.jackrabbit.spi.Batch)19 PropertyInfo (org.apache.jackrabbit.spi.PropertyInfo)18 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)12 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 ValueFormatException (javax.jcr.ValueFormatException)8 Path (org.apache.jackrabbit.spi.Path)8 QValueConstraint (org.apache.jackrabbit.spi.QValueConstraint)8 HashMap (java.util.HashMap)7 ValueConstraint (org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint)7 InputStream (java.io.InputStream)5 Node (javax.jcr.Node)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 PropertyId (org.apache.jackrabbit.spi.PropertyId)5