Search in sources :

Example 61 with QValue

use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.

the class NodeImpl method createProperty.

/**
     * Create a new multi valued property
     *
     * @param qName
     * @param type
     * @param values
     * @return
     * @throws ConstraintViolationException
     * @throws RepositoryException
     */
private Property createProperty(Name qName, Value[] values, int type) throws ConstraintViolationException, RepositoryException {
    QPropertyDefinition def = getApplicablePropertyDefinition(qName, type, true);
    int targetType = def.getRequiredType();
    // make sure, the final type is not set to undefined
    if (targetType == PropertyType.UNDEFINED) {
        if (type == PropertyType.UNDEFINED) {
            // try to retrieve type from the values array
            if (values.length > 0) {
                for (Value value : values) {
                    if (value != null) {
                        targetType = value.getType();
                        break;
                    }
                }
            }
            if (targetType == PropertyType.UNDEFINED) {
                // fallback
                targetType = PropertyType.STRING;
            }
        } else {
            targetType = type;
        }
    }
    Value[] targetValues = ValueHelper.convert(values, targetType, session.getValueFactory());
    QValue[] qvs = ValueFormat.getQValues(targetValues, session.getNamePathResolver(), session.getQValueFactory());
    return createProperty(qName, targetType, def, 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 62 with QValue

use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.

the class AccessControlManagerImpl method createAceNode.

private void createAceNode(SetTree operation, NodeState parentState, AccessControlEntry entry) throws RepositoryException {
    AccessControlEntryImpl ace = (AccessControlEntryImpl) entry;
    String uuid = null;
    boolean isAllow = ace.isAllow();
    Name nodeName = getUniqueNodeName(parentState, (isAllow) ? "allow" : "deny");
    Name nodeTypeName = (isAllow) ? NT_REP_GRANT_ACE : NT_REP_DENY_ACE;
    NodeState aceNode = addNode(operation, parentState, nodeName, uuid, nodeTypeName);
    // add rep:principalName property
    String valueStr = ace.getPrincipal().getName();
    QValue value = qvf.create(valueStr, PropertyType.STRING);
    addProperty(operation, aceNode, N_REP_PRINCIPAL_NAME, PropertyType.STRING, new QValue[] { value });
    // add rep:privileges MvProperty
    Privilege[] privs = ace.getPrivileges();
    QValue[] vls = new QValue[privs.length];
    Name privilegeName = null;
    try {
        for (int i = 0; i < privs.length; i++) {
            privilegeName = npResolver.getQName(privs[i].getName());
            vls[i] = qvf.create(privilegeName.toString(), PropertyType.NAME);
        }
    } catch (ValueFormatException e) {
        throw new RepositoryException(e.getMessage());
    }
    addProperty(operation, aceNode, N_REP_PRIVILEGES, PropertyType.NAME, vls);
// TODO: add single and mv restrictions
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) ValueFormatException(javax.jcr.ValueFormatException) RepositoryException(javax.jcr.RepositoryException) Privilege(javax.jcr.security.Privilege) Name(org.apache.jackrabbit.spi.Name)

Example 63 with QValue

use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.

the class PropertyState method diff.

/**
     * Returns true, if type and/or values of the given property states differ.
     *
     * @param p1
     * @param p2
     * @return if the 2 <code>PropertyState</code>s are different in terms of
     * type and/or values.
     */
private static boolean diff(PropertyData p1, PropertyData p2) {
    // compare type
    if (p1.type != p2.type) {
        return true;
    }
    QValue[] vs1 = p1.values;
    QValue[] vs2 = p2.values;
    if (vs1.length != vs2.length) {
        return true;
    } else {
        for (int i = 0; i < vs1.length; i++) {
            boolean eq = (vs1[i] == null) ? vs2[i] == null : vs1[i].equals(vs2[i]);
            if (!eq) {
                return true;
            }
        }
    }
    // no difference
    return false;
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint)

Example 64 with QValue

use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.

the class ValueConstraint method checkValueConstraints.

/**
     * Tests if the value constraints defined in the property definition
     * <code>pd</code> are satisfied by the the specified <code>values</code>.
     * <p>
     * Note that the <i>protected</i> flag is not checked. Also note that no
     * type conversions are attempted if the type of the given values does not
     * match the required type as specified in the given definition.
     *
     * @param pd property definition
     * @param values values to check
     * @throws ConstraintViolationException if the constraints are violated
     */
public static void checkValueConstraints(QPropertyDefinition pd, QValue[] values) throws ConstraintViolationException, RepositoryException {
    // check multi-value flag
    if (!pd.isMultiple() && values != null && values.length > 1) {
        throw new ConstraintViolationException("the property is not multi-valued");
    }
    QValueConstraint[] constraints = pd.getValueConstraints();
    if (constraints == null || constraints.length == 0) {
        // no constraints to check
        return;
    }
    if (values != null && values.length > 0) {
        // check value constraints on every value
        for (QValue value : values) {
            // constraints are OR-ed together
            boolean satisfied = false;
            ConstraintViolationException cve = null;
            for (int j = 0; j < constraints.length && !satisfied; j++) {
                try {
                    constraints[j].check(value);
                    satisfied = true;
                } catch (ConstraintViolationException e) {
                    cve = e;
                } catch (InvalidConstraintException e) {
                    cve = new ConstraintViolationException(e.getMessage(), e);
                }
            }
            if (!satisfied) {
                // re-throw last exception we encountered
                throw cve;
            }
        }
    }
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) InvalidConstraintException(org.apache.jackrabbit.spi.commons.nodetype.InvalidConstraintException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint)

Example 65 with QValue

use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.

the class PropertyDefinitionImpl method getDefaultValues.

//-------------------------------------------------< PropertyDefinition >---
/**
     * {@inheritDoc}
     */
public Value[] getDefaultValues() {
    QPropertyDefinition pDef = ((QPropertyDefinition) itemDef);
    QValue[] defVals = pDef.getDefaultValues();
    if (defVals == null) {
        return null;
    }
    Value[] values = new Value[defVals.length];
    for (int i = 0; i < defVals.length; i++) {
        try {
            values[i] = ValueFormat.getJCRValue(defVals[i], resolver, valueFactory);
        } catch (RepositoryException e) {
            // should never get here
            String propName = (getName() == null) ? "[null]" : getName();
            log.error("illegal default value specified for property " + propName + " in node type " + getDeclaringNodeType(), e);
            return null;
        }
    }
    return values;
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) Value(javax.jcr.Value) QValue(org.apache.jackrabbit.spi.QValue) RepositoryException(javax.jcr.RepositoryException) ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint)

Aggregations

QValue (org.apache.jackrabbit.spi.QValue)125 Name (org.apache.jackrabbit.spi.Name)40 RepositoryException (javax.jcr.RepositoryException)23 Value (javax.jcr.Value)21 NodeId (org.apache.jackrabbit.spi.NodeId)21 Batch (org.apache.jackrabbit.spi.Batch)19 PropertyInfo (org.apache.jackrabbit.spi.PropertyInfo)18 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)12 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 ValueFormatException (javax.jcr.ValueFormatException)8 Path (org.apache.jackrabbit.spi.Path)8 QValueConstraint (org.apache.jackrabbit.spi.QValueConstraint)8 HashMap (java.util.HashMap)7 ValueConstraint (org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint)7 InputStream (java.io.InputStream)5 Node (javax.jcr.Node)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 PropertyId (org.apache.jackrabbit.spi.PropertyId)5