use of javax.jcr.ValueFormatException in project jackrabbit by apache.
the class PropertyImpl method getNode.
/**
* @see Property#getNode()
*/
public Node getNode() throws ValueFormatException, RepositoryException {
Value value = getValue();
switch(value.getType()) {
case PropertyType.REFERENCE:
case PropertyType.WEAKREFERENCE:
return session.getNodeByIdentifier(value.getString());
case PropertyType.PATH:
case PropertyType.NAME:
String path = value.getString();
Path p = session.getPathResolver().getQPath(path);
try {
return (p.isAbsolute()) ? session.getNode(path) : getParent().getNode(path);
} catch (PathNotFoundException e) {
throw new ItemNotFoundException(path);
}
case PropertyType.STRING:
try {
Value refValue = ValueHelper.convert(value, PropertyType.REFERENCE, session.getValueFactory());
return session.getNodeByIdentifier(refValue.getString());
} catch (ItemNotFoundException e) {
throw e;
} catch (RepositoryException e) {
// try if STRING value can be interpreted as PATH value
Value pathValue = ValueHelper.convert(value, PropertyType.PATH, session.getValueFactory());
p = session.getPathResolver().getQPath(pathValue.getString());
try {
return (p.isAbsolute()) ? session.getNode(pathValue.getString()) : getParent().getNode(pathValue.getString());
} catch (PathNotFoundException e1) {
throw new ItemNotFoundException(pathValue.getString());
}
}
default:
throw new ValueFormatException("Property value cannot be converted to a PATH, REFERENCE or WEAKREFERENCE");
}
}
use of javax.jcr.ValueFormatException in project jackrabbit by apache.
the class AbstractLsProperties method getMultiplePreview.
/**
* @param property
* @return a <code>Collection</code> in which element contains the first
* 50 characters of the <code>Value</code>'s string
* representation
* @throws RepositoryException
* @throws ValueFormatException
*/
private Collection getMultiplePreview(Property p) throws ValueFormatException, RepositoryException {
Collection c = new ArrayList();
Value[] values = p.getValues();
for (int i = 0; i < values.length; i++) {
try {
String value = values[i].getString();
c.add(value.substring(0, Math.min(value.length(), 50)));
} catch (ValueFormatException e) {
c.add(bundle.getString("phrase.notavailable"));
}
}
return c;
}
use of javax.jcr.ValueFormatException in project jackrabbit by apache.
the class SetValueValueFormatExceptionTest method testDouble.
/**
* Tests if setValue(double) throws a ValueFormatException immediately (not
* on save) if a conversion fails.
*/
public void testDouble() throws NotExecutableException, RepositoryException {
Property booleanProperty = createProperty(PropertyType.BOOLEAN, false);
try {
booleanProperty.setValue(1.23);
fail("Property.setValue(double) must throw a ValueFormatException " + "immediately if a conversion fails.");
} catch (ValueFormatException e) {
// success
}
}
use of javax.jcr.ValueFormatException in project jackrabbit by apache.
the class SetValueValueFormatExceptionTest method testLong.
/**
* Tests if setValue(long) throws a ValueFormatException immediately (not
* on save) if a conversion fails.
*/
public void testLong() throws NotExecutableException, RepositoryException {
Property booleanProperty = createProperty(PropertyType.BOOLEAN, false);
try {
booleanProperty.setValue(123);
fail("Property.setValue(long) must throw a ValueFormatException " + "immediately if a conversion fails.");
} catch (ValueFormatException e) {
// success
}
}
use of javax.jcr.ValueFormatException in project jackrabbit by apache.
the class SetValueValueFormatExceptionTest method testCalendar.
/**
* Tests if setValue(Calendar) throws a ValueFormatException immediately (not
* on save) if a conversion fails.
*/
public void testCalendar() throws NotExecutableException, RepositoryException {
Property booleanProperty = createProperty(PropertyType.BOOLEAN, false);
try {
booleanProperty.setValue(Calendar.getInstance());
fail("Property.setValue(Calendar) must throw a ValueFormatException " + "immediately if a conversion fails.");
} catch (ValueFormatException e) {
// success
}
}
Aggregations