use of org.apache.jackrabbit.spi.QValue 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.QValue in project jackrabbit by apache.
the class QValueTest method testPathValueGetPath.
public void testPathValueGetPath() throws RepositoryException {
QValue v = factory.create(ROOT_PATH);
assertTrue(v.getPath().equals(ROOT_PATH));
}
use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class QValueTest method testWeakReferenceValueEquality.
public void testWeakReferenceValueEquality() throws RepositoryException {
QValue v = factory.create(REFERENCE, PropertyType.WEAKREFERENCE);
QValue otherV = factory.create(REFERENCE, PropertyType.WEAKREFERENCE);
assertEquals("Weak reference values created from the same string must be equal.", v, otherV);
}
use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class QValueTest method runBinarySerializableTest.
/**
* Runs binary serializable test using a stream with a size of kBytes.
* @param size in kBytes.
*/
private void runBinarySerializableTest(int size) throws Exception {
File tmp = File.createTempFile("test", "bin");
OutputStream out = new FileOutputStream(tmp);
byte[] stuff = new byte[1024];
Arrays.fill(stuff, (byte) 7);
for (int i = 0; i < size; i++) {
out.write(stuff);
}
out.close();
InputStream in = new FileInputStream(tmp);
QValue v = factory.create(in);
in.close();
tmp.delete();
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream oout = new ObjectOutputStream(bout);
oout.writeObject(v);
oout.close();
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
ObjectInputStream oin = new ObjectInputStream(bin);
QValue serValue = (QValue) oin.readObject();
try {
InputStream in1 = new BufferedInputStream(v.getStream());
InputStream in2 = new BufferedInputStream(serValue.getStream());
int i;
while ((i = in1.read()) > -1) {
assertEquals(i, in2.read());
}
assertEquals(in2.read(), -1);
in1.close();
in2.close();
} finally {
v.discard();
serValue.discard();
}
}
use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class QValueTest method testEmptyBinaryFromFile.
public void testEmptyBinaryFromFile() throws RepositoryException, IOException {
File f = File.createTempFile("QValueFactoryImplTest", ".txt");
f.deleteOnExit();
QValue v = factory.create(f);
assertEquals(PropertyType.BINARY, v.getType());
assertEquals(0, v.getLength());
assertEquals("", v.getString());
ByteArrayOutputStream out = new ByteArrayOutputStream();
spool(out, v.getStream());
assertEquals("", new String(out.toByteArray()));
}
Aggregations