Search in sources :

Example 41 with ValueFormatException

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");
    }
}
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 42 with ValueFormatException

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;
}
Also used : ArrayList(java.util.ArrayList) Value(javax.jcr.Value) Collection(java.util.Collection) ValueFormatException(javax.jcr.ValueFormatException)

Example 43 with ValueFormatException

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
    }
}
Also used : ValueFormatException(javax.jcr.ValueFormatException) Property(javax.jcr.Property)

Example 44 with ValueFormatException

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
    }
}
Also used : ValueFormatException(javax.jcr.ValueFormatException) Property(javax.jcr.Property)

Example 45 with ValueFormatException

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
    }
}
Also used : 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