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
}
}
}
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
}
}
}
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;
}
}
}
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);
}
}
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);
}
}
Aggregations