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();
}
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);
}
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());
}
}
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);
}
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);
}
Aggregations