use of org.apache.jackrabbit.spi.QValue 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();
}
use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class SessionImporter method buildQValue.
/**
*
* @param tv
* @param targetType
* @param resolver The name/path resolver used to build a <code>QValue</code>.
* @return
* @throws RepositoryException
*/
private QValue buildQValue(TextValue tv, int targetType, NamePathResolver resolver) throws RepositoryException {
QValue iv;
try {
switch(targetType) {
case PropertyType.BINARY:
// base64 encoded BINARY type
if (tv.length() < 0x10000) {
// < 65kb: deserialize BINARY type in memory
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Base64.decode(tv.retrieve(), baos);
// no need to close ByteArrayOutputStream
//baos.close();
iv = session.getQValueFactory().create(baos.toByteArray());
} else {
// >= 65kb: deserialize BINARY type
// using Reader and temporary file
TransientFileFactory fileFactory = TransientFileFactory.getInstance();
File tmpFile = fileFactory.createTransientFile("bin", null, null);
FileOutputStream out = new FileOutputStream(tmpFile);
Reader reader = tv.reader();
try {
Base64.decode(reader, out);
} finally {
reader.close();
out.close();
}
iv = session.getQValueFactory().create(tmpFile);
}
break;
default:
// build iv using namespace context of xml document
Value v = ValueHelper.convert(tv.retrieve(), targetType, session.getValueFactory());
iv = ValueFormat.getQValue(v, resolver, session.getQValueFactory());
break;
}
return iv;
} catch (IOException e) {
String msg = "failed to retrieve serialized value";
log.debug(msg, e);
throw new RepositoryException(msg, e);
}
}
use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class BinaryTest method testBinaryTwiceModifiedProperty.
public void testBinaryTwiceModifiedProperty() throws Exception {
Node test = testRootNode.addNode("test");
Property p = test.setProperty("prop", generateValue());
superuser.save();
// modify twice
test.setProperty("prop", generateValue());
QValue qv1 = getQValue(p);
test.setProperty("prop", generateValue());
QValue qv2 = getQValue(p);
assertFalse(qv1.equals(qv2));
superuser.save();
assertEquals(qv2, getQValue(p));
assertDisposed(qv1);
}
use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class BinaryTest method testBinaryTwiceIntermediateSave.
public void testBinaryTwiceIntermediateSave() throws Exception {
Node test = testRootNode.addNode("test");
Property p = test.setProperty("prop", generateValue());
QValue qv1 = getQValue(p);
superuser.save();
test.setProperty("prop", generateValue());
QValue qv2 = getQValue(p);
assertFalse(qv1.equals(qv2));
superuser.save();
assertEquals(qv2, getQValue(p));
assertDisposed(qv1);
}
use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class QValueTest method testReadBooleanAsLong.
public void testReadBooleanAsLong() throws RepositoryException {
try {
QValue v = factory.create(true);
v.getLong();
} catch (ValueFormatException e) {
// ok
return;
}
assertTrue("Cannot convert value to long", false);
}
Aggregations