Search in sources :

Example 81 with ValueFormatException

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

the class MultiValuedPropertyTest method testGetBooleanFromMultivalued.

/**
 * Tests if Property.getBoolean() fails for multivalued properties.
 *
 * @throws RepositoryException
 * @throws NotExecutableException
 */
public void testGetBooleanFromMultivalued() throws RepositoryException, NotExecutableException {
    Property prop = PropertyUtil.searchMultivalProp(testRootNode);
    if (prop == null) {
        throw new NotExecutableException("No multivalued property found.");
    } else {
        try {
            prop.getBoolean();
            fail("Property.getLong() 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)

Example 82 with ValueFormatException

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

the class MultiValuedPropertyTest method testGetStringFromMultivalued.

/**
 * Tests if Property.getString() fails with ValueFormatException for
 * multivalued properties.
 *
 * @throws RepositoryException
 * @throws NotExecutableException
 */
public void testGetStringFromMultivalued() throws RepositoryException, NotExecutableException {
    Property prop = PropertyUtil.searchMultivalProp(testRootNode);
    if (prop == null) {
        throw new NotExecutableException("No multivalued property found.");
    } else {
        try {
            prop.getString();
            fail("Property.getString() 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)

Example 83 with ValueFormatException

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

the class AbstractQValue method getCalendar.

/**
 * @see QValue#getCalendar()
 */
public Calendar getCalendar() throws RepositoryException {
    if (type == PropertyType.DOUBLE) {
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+00:00"));
        cal.setTimeInMillis(((Double) val).longValue());
        return cal;
    } else if (type == PropertyType.LONG) {
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+00:00"));
        cal.setTimeInMillis((Long) val);
        return cal;
    } else if (type == PropertyType.DECIMAL) {
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+00:00"));
        cal.setTimeInMillis(((BigDecimal) val).longValue());
        return cal;
    } else {
        Calendar cal = ISO8601.parse(getString());
        if (cal == null) {
            throw new ValueFormatException("not a date string: " + getString());
        } else {
            return cal;
        }
    }
}
Also used : Calendar(java.util.Calendar) ValueFormatException(javax.jcr.ValueFormatException)

Example 84 with ValueFormatException

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

the class ValueFactoryQImpl method createValue.

/**
 * {@inheritDoc}
 */
public Value createValue(String value, int type) throws ValueFormatException {
    try {
        QValue qvalue;
        if (type == PropertyType.NAME) {
            Name name = resolver.getQName(value);
            qvalue = qfactory.create(name);
        } else if (type == PropertyType.PATH) {
            Path path = resolver.getQPath(value, false);
            qvalue = qfactory.create(path);
        } else {
            qvalue = qfactory.create(value, type);
        }
        return new QValueValue(qvalue, resolver);
    } catch (IllegalNameException ex) {
        throw new ValueFormatException(ex);
    } catch (MalformedPathException ex) {
        throw new ValueFormatException(ex);
    } catch (NamespaceException ex) {
        throw new ValueFormatException(ex);
    } catch (ValueFormatException ex) {
        throw ex;
    } catch (RepositoryException ex) {
        throw new ValueFormatException(ex);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) QValue(org.apache.jackrabbit.spi.QValue) MalformedPathException(org.apache.jackrabbit.spi.commons.conversion.MalformedPathException) ValueFormatException(javax.jcr.ValueFormatException) NamespaceException(javax.jcr.NamespaceException) RepositoryException(javax.jcr.RepositoryException) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) Name(org.apache.jackrabbit.spi.Name)

Example 85 with ValueFormatException

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

the class DoubleValue method getDate.

/**
 * Returns a <code>Calendar</code> instance interpreting the double as the
 * time in milliseconds since the epoch (1.1.1970, 0:00, UTC). If the
 * resulting value is out of range for a date,
 * a {@link ValueFormatException} is thrown.
 */
@Override
public Calendar getDate() throws ValueFormatException {
    if (Long.MIN_VALUE <= value && value <= Long.MAX_VALUE) {
        Calendar date = Calendar.getInstance();
        date.setTimeInMillis((long) value);
        return date;
    } else {
        throw new ValueFormatException("Double value is outside the date range: " + value);
    }
}
Also used : Calendar(java.util.Calendar) ValueFormatException(javax.jcr.ValueFormatException)

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