Search in sources :

Example 76 with ValueFormatException

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

the class StringPropertyTest method testGetLong.

/**
 * Tests conversion from String type to Long type.
 */
public void testGetLong() throws RepositoryException {
    Value val = PropertyUtil.getValue(prop);
    String str = val.getString();
    try {
        Long.parseLong(str);
        long l = val.getLong();
        assertEquals("Wrong conversion from String to Long.", new Long(l), Long.valueOf(str));
    } catch (NumberFormatException nfe) {
        try {
            val.getLong();
            fail("Conversion from malformed String to Long " + "should throw ValueFormatException.");
        } catch (ValueFormatException vfe) {
        // ok
        }
    }
}
Also used : Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException)

Example 77 with ValueFormatException

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

the class PropertyImpl method setValue.

/**
 * @see Property#setValue(javax.jcr.Value[])
 */
public void setValue(Value[] values) throws ValueFormatException, VersionException, LockException, RepositoryException {
    checkIsWritable(true);
    // assert equal types for all values entries
    int valueType = PropertyType.UNDEFINED;
    if (values != null) {
        for (int i = 0; i < values.length; i++) {
            if (values[i] == null) {
                // skip null values as those will be purged later
                continue;
            }
            if (valueType == PropertyType.UNDEFINED) {
                valueType = values[i].getType();
            } else if (valueType != values[i].getType()) {
                String msg = "Inhomogeneous type of values (" + safeGetJCRPath() + ")";
                log.debug(msg);
                throw new ValueFormatException(msg);
            }
        }
    }
    int targetType = getDefinition().getRequiredType();
    if (targetType == PropertyType.UNDEFINED) {
        targetType = (valueType == PropertyType.UNDEFINED) ? PropertyType.STRING : valueType;
    }
    // convert to internal values of correct type
    QValue[] qValues = null;
    if (values != null) {
        Value[] vs = ValueHelper.convert(values, targetType, session.getValueFactory());
        qValues = ValueFormat.getQValues(vs, session.getNamePathResolver(), session.getQValueFactory());
    }
    setInternalValues(qValues, targetType);
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) SetPropertyValue(org.apache.jackrabbit.jcr2spi.operation.SetPropertyValue) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException)

Example 78 with ValueFormatException

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

the class PropertyImpl method getProperty.

/**
 * @see Property#getProperty()
 */
public Property getProperty() throws RepositoryException {
    Value value = getValue();
    Value pathValue = ValueHelper.convert(value, PropertyType.PATH, session.getValueFactory());
    String path = pathValue.getString();
    boolean absolute;
    try {
        Path p = session.getPathResolver().getQPath(path);
        absolute = p.isAbsolute();
    } catch (RepositoryException e) {
        throw new ValueFormatException("Property value cannot be converted to a PATH");
    }
    try {
        return (absolute) ? session.getProperty(path) : getParent().getProperty(path);
    } catch (PathNotFoundException e) {
        throw new ItemNotFoundException(path);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) SetPropertyValue(org.apache.jackrabbit.jcr2spi.operation.SetPropertyValue) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 79 with ValueFormatException

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

the class MultiValuedPropertyTest method testGetLengthFromMultivalued.

/**
 * Tests if Property.getLength() fails for multivalued property.
 */
public void testGetLengthFromMultivalued() throws RepositoryException, NotExecutableException {
    Property prop = PropertyUtil.searchMultivalProp(testRootNode);
    if (prop == null) {
        throw new NotExecutableException("No multivalued property found.");
    }
    try {
        prop.getLength();
        fail("Property.getLength() called on a multivalue property must fail (ValueFormatException).");
    } catch (ValueFormatException vfe) {
    // ok
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) ValueFormatException(javax.jcr.ValueFormatException) Property(javax.jcr.Property)

Example 80 with ValueFormatException

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

the class MultiValuedPropertyTest method testGetDoubleFromMultivalued.

/**
 * Tests if Property.getDouble() fails for multivalued properties.
 *
 * @throws RepositoryException
 * @throws NotExecutableException
 */
public void testGetDoubleFromMultivalued() throws RepositoryException, NotExecutableException {
    Property prop = PropertyUtil.searchMultivalProp(testRootNode);
    if (prop == null) {
        throw new NotExecutableException("No multivalued property found.");
    } else {
        try {
            prop.getDouble();
            fail("Property.getDouble() must fail with ValueFormatException for any multivalued property.");
        } catch (ValueFormatException vfe) {
        // ok
        }
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) ValueFormatException(javax.jcr.ValueFormatException) Property(javax.jcr.Property)

Aggregations

ValueFormatException (javax.jcr.ValueFormatException)106 Value (javax.jcr.Value)53 Property (javax.jcr.Property)34 RepositoryException (javax.jcr.RepositoryException)16 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)12 Calendar (java.util.Calendar)10 ItemNotFoundException (javax.jcr.ItemNotFoundException)10 Node (javax.jcr.Node)10 QValue (org.apache.jackrabbit.spi.QValue)10 PathNotFoundException (javax.jcr.PathNotFoundException)6 Name (org.apache.jackrabbit.spi.Name)6 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)5 InternalValue (org.apache.jackrabbit.core.value.InternalValue)5 InputStream (java.io.InputStream)4 BigDecimal (java.math.BigDecimal)4 Date (java.util.Date)4 Path (org.apache.jackrabbit.spi.Path)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3