Search in sources :

Example 36 with Value

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

the class DatePropertyTest method testGetString.

/**
     * Tests if a calendar is returned and if the conversion to a string has
     * correct format.
     */
public void testGetString() throws RepositoryException {
    Value val = PropertyUtil.getValue(prop);
    // correct format:  YYYY-MM-DDThh:mm:ss.sssTZD
    // month(01-12), day(01-31), hours(00-23), minutes(00-59), seconds(00-59),
    // TZD(Z or +hh:mm or -hh:mm)
    // String aDay="2005-01-19T15:34:15.917+01:00";
    String date = val.getString();
    log.println("date str = " + date);
    boolean match = PropertyUtil.isDateFormat(prop.getString());
    assertTrue("Date not in correct String format.", match);
}
Also used : Value(javax.jcr.Value)

Example 37 with Value

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

the class DatePropertyTest method testGetStream.

/**
     * Tests conversion from Date type to Binary type.
     */
public void testGetStream() throws RepositoryException, IOException {
    Value val = PropertyUtil.getValue(prop);
    BufferedInputStream in = new BufferedInputStream(val.getStream());
    Value otherVal = PropertyUtil.getValue(prop);
    InputStream ins = null;
    byte[] utf8bytes = otherVal.getString().getBytes(UTF8);
    // if yet utf-8 encoded these bytes should be equal
    // to the ones received from the stream
    int i = 0;
    byte[] b = new byte[1];
    while (in.read(b) != -1) {
        assertTrue("Date as a Stream is not utf-8 encoded.", b[0] == utf8bytes[i]);
        i++;
    }
    try {
        val.getDate();
    } catch (IllegalStateException ise) {
        fail("Non stream method call after stream method call " + "should not throw an IllegalStateException.");
    }
    try {
        ins = otherVal.getStream();
    } catch (IllegalStateException ise) {
        fail("Stream method call after a non stream method call " + "should not throw an IllegalStateException.");
    } finally {
        if (in != null) {
            in.close();
        }
        if (ins != null) {
            ins.close();
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) Value(javax.jcr.Value)

Example 38 with Value

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

the class DatePropertyTest method testGetBoolean.

/**
     * Tests failure of conversion from Date type to Boolean type.
     */
public void testGetBoolean() throws RepositoryException {
    try {
        Value val = PropertyUtil.getValue(prop);
        val.getBoolean();
        fail("Conversion from a Date value to a Boolean value " + "should throw a ValueFormatException.");
    } catch (ValueFormatException vfe) {
    //ok
    }
}
Also used : Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException)

Example 39 with Value

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

the class ExportDocViewTest method exportValues.

/**
     * Exports values of a multivalue property and concatenate the values
     * separated by a space. (chapter 6.4.4 of the JCR specification).
     *
     * @param prop
     * @param isBinary
     * @return
     * @throws RepositoryException
     */
private static String exportValues(Property prop, boolean isBinary) throws RepositoryException, IOException {
    Value[] vals = prop.getValues();
    // order of multi values is preserved.
    // multival with empty array is exported as empty string
    StringBuffer exportedVal = new StringBuffer();
    String space = "";
    if (isBinary) {
        for (int i = 0; i < vals.length; i++) {
            exportedVal.append(space);
            InputStream in = vals[i].getStream();
            try {
                exportedVal.append(encodeBase64(in));
            } finally {
                in.close();
            }
            space = " ";
        }
    } else {
        for (int i = 0; i < vals.length; i++) {
            exportedVal.append(space);
            exportedVal.append(escapeValues(vals[i].getString()));
            space = " ";
        }
    }
    return exportedVal.toString();
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Value(javax.jcr.Value)

Example 40 with Value

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

the class BinaryPropertyTest method testSameStream.

/**
     * Tests that when Value.getStream() is called a second time the same Stream
     * object is returned. Also tests that when a new Value object is requested
     * also a new Stream object is returned by calling getStream() on the new
     * Value object.
     */
public void testSameStream() throws RepositoryException, IOException {
    Value val = PropertyUtil.getValue(prop);
    InputStream in = val.getStream();
    InputStream in2 = val.getStream();
    Value otherVal = PropertyUtil.getValue(prop);
    InputStream in3 = otherVal.getStream();
    try {
        assertSame("Same InputStream object expected when " + "Value.getStream is called twice.", in, in2);
        assertNotSame("Value.getStream() called on a new value " + "object should return a different Stream object.", in, in3);
    } finally {
        // cleaning up
        try {
            in.close();
        } catch (IOException ignore) {
        }
        if (in2 != in) {
            try {
                in2.close();
            } catch (IOException ignore) {
            }
        }
        if (in3 != in) {
            try {
                in3.close();
            } catch (IOException ignore) {
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) Value(javax.jcr.Value) IOException(java.io.IOException)

Aggregations

Value (javax.jcr.Value)600 Node (javax.jcr.Node)158 Test (org.junit.Test)118 Property (javax.jcr.Property)99 RepositoryException (javax.jcr.RepositoryException)82 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)82 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)70 Session (javax.jcr.Session)63 NodeType (javax.jcr.nodetype.NodeType)57 ValueFormatException (javax.jcr.ValueFormatException)53 ValueFactory (javax.jcr.ValueFactory)51 QValue (org.apache.jackrabbit.spi.QValue)51 HashMap (java.util.HashMap)46 ArrayList (java.util.ArrayList)31 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)30 Privilege (javax.jcr.security.Privilege)30 InputStream (java.io.InputStream)29 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)29 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)29 QValueValue (org.apache.jackrabbit.spi.commons.value.QValueValue)27