Search in sources :

Example 1 with ValueFactoryQImpl

use of org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl in project jackrabbit by apache.

the class DefinitionUtil method createQPropertyDefinition.

/**
     * 
     * @param declaringNodeType
     * @param pdefElement
     * @param resolver
     * @param qValueFactory
     * @return
     * @throws RepositoryException
     */
static QPropertyDefinition createQPropertyDefinition(Name declaringNodeType, Element pdefElement, NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException {
    QPropertyDefinitionBuilder builder = new QPropertyDefinitionBuilder();
    buildQItemDefinition(declaringNodeType, pdefElement, resolver, builder);
    if (pdefElement.hasAttribute(REQUIREDTYPE_ATTRIBUTE)) {
        builder.setRequiredType(PropertyType.valueFromName(pdefElement.getAttribute(REQUIREDTYPE_ATTRIBUTE)));
    }
    if (pdefElement.hasAttribute(MULTIPLE_ATTRIBUTE)) {
        builder.setMultiple(Boolean.valueOf(pdefElement.getAttribute(MULTIPLE_ATTRIBUTE)));
    }
    if (pdefElement.hasAttribute(FULL_TEXT_SEARCHABLE_ATTRIBUTE)) {
        builder.setFullTextSearchable(Boolean.valueOf(pdefElement.getAttribute(FULL_TEXT_SEARCHABLE_ATTRIBUTE)));
    }
    if (pdefElement.hasAttribute(QUERY_ORDERABLE_ATTRIBUTE)) {
        builder.setQueryOrderable(Boolean.valueOf(pdefElement.getAttribute(QUERY_ORDERABLE_ATTRIBUTE)));
    }
    int requiredType = builder.getRequiredType();
    Element child = DomUtil.getChildElement(pdefElement, DEFAULTVALUES_ELEMENT, null);
    if (child != null) {
        ElementIterator it = DomUtil.getChildren(child, DEFAULTVALUE_ELEMENT, null);
        while (it.hasNext()) {
            String jcrVal = DomUtil.getText(it.nextElement());
            if (jcrVal == null) {
                jcrVal = "";
            }
            QValue qValue;
            if (requiredType == PropertyType.BINARY) {
                // TODO: improve
                Value v = new ValueFactoryQImpl(qValueFactory, resolver).createValue(jcrVal, requiredType);
                qValue = ValueFormat.getQValue(v, resolver, qValueFactory);
            } else {
                qValue = ValueFormat.getQValue(jcrVal, requiredType, resolver, qValueFactory);
            }
            builder.addDefaultValue(qValue);
        }
    }
    // else: no default values defined.
    child = DomUtil.getChildElement(pdefElement, VALUECONSTRAINTS_ELEMENT, null);
    if (child != null) {
        ElementIterator it = DomUtil.getChildren(child, VALUECONSTRAINT_ELEMENT, null);
        while (it.hasNext()) {
            String qValue = DomUtil.getText(it.nextElement());
            // in case of name and path constraint, the value must be
            // converted to SPI values
            // TODO: tobefixed. path-constraint may contain trailing *
            builder.addValueConstraint(ValueConstraint.create(requiredType, qValue, resolver));
        }
    }
    child = DomUtil.getChildElement(pdefElement, AVAILABLE_QUERY_OPERATORS_ELEMENT, null);
    if (child == null) {
        builder.setAvailableQueryOperators(new String[0]);
    } else {
        List<String> names = new ArrayList<String>();
        ElementIterator it = DomUtil.getChildren(child, AVAILABLE_QUERY_OPERATOR_ELEMENT, null);
        while (it.hasNext()) {
            String str = DomUtil.getText(it.nextElement());
            names.add(str);
        }
        builder.setAvailableQueryOperators(names.toArray(new String[names.size()]));
    }
    return builder.build();
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) QValue(org.apache.jackrabbit.spi.QValue) QPropertyDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QPropertyDefinitionBuilder) Element(org.w3c.dom.Element) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) ArrayList(java.util.ArrayList) ValueFactoryQImpl(org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl) ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint)

Example 2 with ValueFactoryQImpl

use of org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl in project jackrabbit by apache.

the class AccessControlEntryImpl method createJcrValue.

/**
     * Creates a jcr Value from the given qvalue using the specified
     * factory.
     * @return         the jcr value representing the qvalue.
     */
private Value createJcrValue(QValue qValue) throws RepositoryException {
    // build ValueFactory
    ValueFactoryQImpl valueFactory = new ValueFactoryQImpl(qvf, resolver);
    // build jcr value
    QValueValue jcrValue = new QValueValue(qValue, resolver);
    return ValueHelper.copy(jcrValue, valueFactory);
}
Also used : QValueValue(org.apache.jackrabbit.spi.commons.value.QValueValue) ValueFactoryQImpl(org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl)

Example 3 with ValueFactoryQImpl

use of org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl in project jackrabbit by apache.

the class TestAll method getDefaultValue.

/**
     * Returns the string value of the identified property default value.
     *
     * @param def property definition
     * @param index default value index
     * @return default value
     */
private String getDefaultValue(QPropertyDefinition def, int index) {
    try {
        QValue[] values = def.getDefaultValues();
        NamespaceResolver nsResolver = new AdditionalNamespaceResolver(registry);
        NamePathResolver resolver = new DefaultNamePathResolver(nsResolver);
        ValueFactoryQImpl factory = new ValueFactoryQImpl(InternalValueFactory.getInstance(), resolver);
        return factory.createValue(values[index]).getString();
    } catch (RepositoryException e) {
        throw new AssertionFailedError(e.getMessage());
    }
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) QValue(org.apache.jackrabbit.spi.QValue) NamespaceResolver(org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) RepositoryException(javax.jcr.RepositoryException) ValueFactoryQImpl(org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl) AssertionFailedError(junit.framework.AssertionFailedError)

Example 4 with ValueFactoryQImpl

use of org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl in project jackrabbit by apache.

the class CompactNodeTypeDefWriter method write.

/**
     * Write one QNodeTypeDefinition to this writer
     *
     * @param ntd node type definition
     * @throws IOException if an I/O error occurs
     */
public void write(QNodeTypeDefinition ntd) throws IOException {
    NodeTypeDefinition def = new NodeTypeDefinitionImpl(ntd, npResolver, new ValueFactoryQImpl(QValueFactoryImpl.getInstance(), npResolver));
    super.write(def);
}
Also used : NodeTypeDefinitionImpl(org.apache.jackrabbit.spi.commons.nodetype.NodeTypeDefinitionImpl) QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NodeTypeDefinition(javax.jcr.nodetype.NodeTypeDefinition) ValueFactoryQImpl(org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl)

Example 5 with ValueFactoryQImpl

use of org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl in project jackrabbit by apache.

the class ParserTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    NamePathResolver resolver = new DefaultNamePathResolver(new DummyNamespaceResolver());
    QueryObjectModelFactoryImpl factory = new QOMF(resolver);
    ValueFactory vf = new ValueFactoryQImpl(QValueFactoryImpl.getInstance(), resolver);
    parser = new Parser(factory, vf);
}
Also used : QueryObjectModelFactoryImpl(org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelFactoryImpl) NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) DummyNamespaceResolver(org.apache.jackrabbit.spi.commons.conversion.DummyNamespaceResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) ValueFactory(javax.jcr.ValueFactory) ValueFactoryQImpl(org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl) Parser(org.apache.jackrabbit.commons.query.sql2.Parser)

Aggregations

ValueFactoryQImpl (org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl)5 QValue (org.apache.jackrabbit.spi.QValue)2 DefaultNamePathResolver (org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver)2 NamePathResolver (org.apache.jackrabbit.spi.commons.conversion.NamePathResolver)2 ArrayList (java.util.ArrayList)1 RepositoryException (javax.jcr.RepositoryException)1 Value (javax.jcr.Value)1 ValueFactory (javax.jcr.ValueFactory)1 NodeTypeDefinition (javax.jcr.nodetype.NodeTypeDefinition)1 AssertionFailedError (junit.framework.AssertionFailedError)1 Parser (org.apache.jackrabbit.commons.query.sql2.Parser)1 QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)1 DummyNamespaceResolver (org.apache.jackrabbit.spi.commons.conversion.DummyNamespaceResolver)1 NamespaceResolver (org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver)1 NodeTypeDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.NodeTypeDefinitionImpl)1 QPropertyDefinitionBuilder (org.apache.jackrabbit.spi.commons.nodetype.QPropertyDefinitionBuilder)1 ValueConstraint (org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint)1 QueryObjectModelFactoryImpl (org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelFactoryImpl)1 QValueValue (org.apache.jackrabbit.spi.commons.value.QValueValue)1 ElementIterator (org.apache.jackrabbit.webdav.xml.ElementIterator)1