Search in sources :

Example 1 with ValueConstraint

use of org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint in project jackrabbit by apache.

the class NodeTypeWriter method addPropDef.

/**
 * Builds a property definition element under the current element.
 *
 * @param def property definition
 * @throws RepositoryException       if the default values cannot
 *                                   be serialized
 * @throws NamespaceException if the property definition contains
 *                                   invalid namespace references
 */
private void addPropDef(QPropertyDefinition def) throws NamespaceException, RepositoryException {
    builder.startElement(Constants.PROPERTYDEFINITION_ELEMENT);
    // simple attributes
    builder.setAttribute(Constants.NAME_ATTRIBUTE, resolver.getJCRName(def.getName()));
    builder.setAttribute(Constants.AUTOCREATED_ATTRIBUTE, def.isAutoCreated());
    builder.setAttribute(Constants.MANDATORY_ATTRIBUTE, def.isMandatory());
    builder.setAttribute(Constants.PROTECTED_ATTRIBUTE, def.isProtected());
    builder.setAttribute(Constants.ONPARENTVERSION_ATTRIBUTE, OnParentVersionAction.nameFromValue(def.getOnParentVersion()));
    builder.setAttribute(Constants.MULTIPLE_ATTRIBUTE, def.isMultiple());
    builder.setAttribute(Constants.ISFULLTEXTSEARCHABLE_ATTRIBUTE, def.isFullTextSearchable());
    builder.setAttribute(Constants.ISQUERYORDERABLE_ATTRIBUTE, def.isQueryOrderable());
    // TODO do properly...
    String[] qops = def.getAvailableQueryOperators();
    if (qops != null && qops.length > 0) {
        List<String> ops = Arrays.asList(qops);
        List<String> defaultOps = Arrays.asList(Operator.getAllQueryOperators());
        if (!ops.containsAll(defaultOps)) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < qops.length; i++) {
                if (i > 0) {
                    sb.append(' ');
                }
                if (qops[i].equals(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO)) {
                    sb.append(Constants.EQ_ENTITY);
                } else if (qops[i].equals(QueryObjectModelConstants.JCR_OPERATOR_NOT_EQUAL_TO)) {
                    sb.append(Constants.NE_ENTITY);
                } else if (qops[i].equals(QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN)) {
                    sb.append(Constants.GT_ENTITY);
                } else if (qops[i].equals(QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO)) {
                    sb.append(Constants.GE_ENTITY);
                } else if (qops[i].equals(QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN)) {
                    sb.append(Constants.LT_ENTITY);
                } else if (qops[i].equals(QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO)) {
                    sb.append(Constants.LE_ENTITY);
                } else if (qops[i].equals(QueryObjectModelConstants.JCR_OPERATOR_LIKE)) {
                    sb.append(Constants.LIKE_ENTITY);
                }
            }
            builder.setAttribute(Constants.AVAILABLEQUERYOPERATORS_ATTRIBUTE, sb.toString());
        }
    }
    builder.setAttribute(Constants.REQUIREDTYPE_ATTRIBUTE, PropertyType.nameFromValue(def.getRequiredType()));
    // value constraints
    QValueConstraint[] constraints = def.getValueConstraints();
    if (constraints != null && constraints.length > 0) {
        builder.startElement(Constants.VALUECONSTRAINTS_ELEMENT);
        for (QValueConstraint constraint : constraints) {
            ValueConstraint vc = ValueConstraint.create(def.getRequiredType(), constraint.getString());
            builder.addContentElement(Constants.VALUECONSTRAINT_ELEMENT, vc.getDefinition(resolver));
        }
        builder.endElement();
    }
    // default values
    QValue[] defaults = def.getDefaultValues();
    if (defaults != null && defaults.length > 0) {
        builder.startElement(Constants.DEFAULTVALUES_ELEMENT);
        for (QValue v : defaults) {
            builder.addContentElement(Constants.DEFAULTVALUE_ELEMENT, factory.createValue(v).getString());
        }
        builder.endElement();
    }
    builder.endElement();
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint)

Example 2 with ValueConstraint

use of org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint in project jackrabbit by apache.

the class NodeTypeDefinitionFactory method createValueConstraints.

private String[] createValueConstraints(int type, QValueConstraint[] qv) throws RepositoryException {
    String[] ret = new String[qv.length];
    for (int i = 0; i < ret.length; i++) {
        try {
            ValueConstraint c = ValueConstraint.create(type, qv[i].getString());
            ret[i] = c.getDefinition(resolver);
        } catch (InvalidConstraintException e) {
            throw new RepositoryException("Internal error while converting value constraints.", e);
        }
    }
    return ret;
}
Also used : ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) RepositoryException(javax.jcr.RepositoryException) ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint)

Example 3 with ValueConstraint

use of org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint in project jackrabbit by apache.

the class PropertyDefinitionImpl method getValueConstraints.

/**
 * {@inheritDoc}
 */
public String[] getValueConstraints() {
    QPropertyDefinition pd = (QPropertyDefinition) itemDef;
    QValueConstraint[] constraints = pd.getValueConstraints();
    if (constraints == null || constraints.length == 0) {
        return new String[0];
    }
    String[] vca = new String[constraints.length];
    for (int i = 0; i < constraints.length; i++) {
        try {
            ValueConstraint vc = ValueConstraint.create(pd.getRequiredType(), constraints[i].getString());
            vca[i] = vc.getDefinition(resolver);
        } catch (InvalidConstraintException e) {
            log.warn("Internal error during conversion of constraint.", e);
            vca[i] = constraints[i].getString();
        }
    }
    return vca;
}
Also used : QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint)

Aggregations

QValueConstraint (org.apache.jackrabbit.spi.QValueConstraint)3 ValueConstraint (org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint)3 RepositoryException (javax.jcr.RepositoryException)1 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)1 QValue (org.apache.jackrabbit.spi.QValue)1