Search in sources :

Example 86 with Value

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

the class NodeLocalNameTest method testReferenceLiteral.

public void testReferenceLiteral() throws RepositoryException, NotExecutableException {
    ensureMixinType(node1, mixReferenceable);
    superuser.save();
    Value literal = superuser.getValueFactory().createValue(node1);
    QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
    checkQOM(qom, new Node[] {});
}
Also used : Value(javax.jcr.Value) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel)

Example 87 with Value

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

the class NodeLocalNameTest method checkOperatorSingleLiteral.

private void checkOperatorSingleLiteral(String literal, String operator, boolean matches) throws RepositoryException {
    Value value = superuser.getValueFactory().createValue(literal);
    QueryObjectModel qom = createQuery(operator, value);
    checkQOM(qom, matches ? new Node[] { node1 } : new Node[0]);
}
Also used : Node(javax.jcr.Node) Value(javax.jcr.Value) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel)

Example 88 with Value

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

the class NodeImpl method createProperty.

/**
     * Create a new single valued property
     *
     * @param qName
     * @param type
     * @param value
     * @return
     * @throws ConstraintViolationException if no applicable property definition
     * could be found.
     * @throws RepositoryException if another error occurs.
     */
private Property createProperty(Name qName, Value value, int type) throws ConstraintViolationException, RepositoryException {
    QPropertyDefinition def = getApplicablePropertyDefinition(qName, type, false);
    int targetType = def.getRequiredType();
    if (targetType == PropertyType.UNDEFINED) {
        targetType = type;
    }
    QValue qvs;
    if (targetType == PropertyType.UNDEFINED) {
        qvs = ValueFormat.getQValue(value, session.getNamePathResolver(), session.getQValueFactory());
        targetType = qvs.getType();
    } else {
        Value targetValue = ValueHelper.convert(value, targetType, session.getValueFactory());
        qvs = ValueFormat.getQValue(targetValue, session.getNamePathResolver(), session.getQValueFactory());
    }
    return createProperty(qName, targetType, def, new QValue[] { qvs });
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value)

Example 89 with Value

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

the class PropertyImpl method setValue.

/**
     *
     * @param value
     * @param requiredType
     * @throws RepositoryException
     */
private void setValue(Value value, int requiredType) throws RepositoryException {
    if (requiredType == PropertyType.UNDEFINED) {
        // should never get here since calling methods assert valid type
        throw new IllegalArgumentException("Property type of a value cannot be undefined (" + safeGetJCRPath() + ").");
    }
    if (value == null) {
        setInternalValues(null, requiredType);
        return;
    }
    QValue qValue;
    if (requiredType != value.getType()) {
        // type conversion required
        Value v = ValueHelper.convert(value, requiredType, session.getValueFactory());
        qValue = ValueFormat.getQValue(v, session.getNamePathResolver(), session.getQValueFactory());
    } else {
        // no type conversion required
        qValue = ValueFormat.getQValue(value, session.getNamePathResolver(), session.getQValueFactory());
    }
    setInternalValues(new QValue[] { qValue }, requiredType);
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) SetPropertyValue(org.apache.jackrabbit.jcr2spi.operation.SetPropertyValue) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value)

Example 90 with Value

use of javax.jcr.Value 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)

Aggregations

Value (javax.jcr.Value)602 Node (javax.jcr.Node)158 Test (org.junit.Test)120 Property (javax.jcr.Property)99 RepositoryException (javax.jcr.RepositoryException)82 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)82 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)70 Session (javax.jcr.Session)63 NodeType (javax.jcr.nodetype.NodeType)57 ValueFormatException (javax.jcr.ValueFormatException)53 ValueFactory (javax.jcr.ValueFactory)51 QValue (org.apache.jackrabbit.spi.QValue)51 HashMap (java.util.HashMap)46 ArrayList (java.util.ArrayList)31 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)30 Privilege (javax.jcr.security.Privilege)30 InputStream (java.io.InputStream)29 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)29 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)29 QValueValue (org.apache.jackrabbit.spi.commons.value.QValueValue)27