Search in sources :

Example 1 with ValueFactoryImpl

use of org.apache.jackrabbit.core.value.ValueFactoryImpl in project jackrabbit by apache.

the class LengthOperand method getValues.

/**
     * {@inheritDoc}
     */
public Value[] getValues(ScoreNode sn, EvaluationContext context) throws RepositoryException {
    PropertyState ps = property.getPropertyState(sn, context);
    if (ps == null) {
        return EMPTY;
    } else {
        ValueFactoryImpl vf = (ValueFactoryImpl) context.getSession().getValueFactory();
        QValueFactory qvf = vf.getQValueFactory();
        InternalValue[] values = ps.getValues();
        Value[] lengths = new Value[values.length];
        for (int i = 0; i < lengths.length; i++) {
            long len;
            int type = values[i].getType();
            if (type == PropertyType.NAME) {
                len = vf.createValue(qvf.create(values[i].getName())).getString().length();
            } else if (type == PropertyType.PATH) {
                len = vf.createValue(qvf.create(values[i].getPath())).getString().length();
            } else {
                len = Util.getLength(values[i]);
            }
            lengths[i] = vf.createValue(len);
        }
        return lengths;
    }
}
Also used : ValueFactoryImpl(org.apache.jackrabbit.core.value.ValueFactoryImpl) Value(javax.jcr.Value) InternalValue(org.apache.jackrabbit.core.value.InternalValue) InternalValue(org.apache.jackrabbit.core.value.InternalValue) QValueFactory(org.apache.jackrabbit.spi.QValueFactory) PropertyState(org.apache.jackrabbit.core.state.PropertyState)

Aggregations

Value (javax.jcr.Value)1 PropertyState (org.apache.jackrabbit.core.state.PropertyState)1 InternalValue (org.apache.jackrabbit.core.value.InternalValue)1 ValueFactoryImpl (org.apache.jackrabbit.core.value.ValueFactoryImpl)1 QValueFactory (org.apache.jackrabbit.spi.QValueFactory)1