use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class XmlTree method addProperty.
@Override
public void addProperty(NodeId parentId, Name propertyName, int propertyType, QValue[] values) throws RepositoryException {
properties.append("<sv:property sv:name=\"").append(getResolver().getJCRName(propertyName)).append("\"");
properties.append(" sv:type=\"").append(PropertyType.nameFromValue(propertyType) + "\">");
for (QValue value : values) {
properties.append("<sv:value>").append(value.getString()).append("</sv:value>");
}
properties.append("</sv:property>");
}
use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class RepositoryServiceImpl method getRepositoryDescriptors.
/**
* {@inheritDoc}
*/
public Map<String, QValue[]> getRepositoryDescriptors() throws RepositoryException {
Map<String, QValue[]> descriptors = new HashMap<String, QValue[]>();
for (String key : repository.getDescriptorKeys()) {
if (key.equals(Repository.OPTION_TRANSACTIONS_SUPPORTED)) {
descriptors.put(key, new QValue[] { qValueFactory.create(false) });
} else {
Value[] vs = repository.getDescriptorValues(key);
QValue[] qvs = new QValue[vs.length];
for (int i = 0; i < vs.length; i++) {
// Name and path resolver that uses a dummy namespace resolver
// as Name/Path values are not expected to occur in the
// descriptors. TODO: check again.
NamePathResolver resolver = new DefaultNamePathResolver(new NamespaceResolver() {
public String getURI(String prefix) {
return prefix;
}
public String getPrefix(String uri) {
return uri;
}
});
qvs[i] = ValueFormat.getQValue(vs[i], resolver, qValueFactory);
}
descriptors.put(key, qvs);
}
}
return descriptors;
}
use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class BatchTest method testSetMixedBinaryValues.
public void testSetMixedBinaryValues() throws RepositoryException, IOException {
NodeId nid = getNodeId(testPath);
Name propName = resolver.getQName("binPropMV");
Batch b = rs.createBatch(si, nid);
QValue[] vs = new QValue[] { rs.getQValueFactory().create(new byte[] { 'a', 'b', 'c' }), rs.getQValueFactory().create(new byte[0]), rs.getQValueFactory().create(new byte[] { 'g', 'h', 'i' }) };
b.addProperty(nid, propName, vs);
rs.submit(b);
PropertyInfo pi = rs.getPropertyInfo(si, getPropertyId(nid, propName));
assertTrue(pi.isMultiValued());
vs = pi.getValues();
assertEquals("abc", vs[0].getString());
assertEquals("", vs[1].getString());
assertEquals("ghi", vs[2].getString());
assertEquals(PropertyType.BINARY, pi.getType());
pi = getPropertyInfo(nid, propName);
vs = pi.getValues();
assertEquals("abc", vs[0].getString());
assertEquals("", vs[1].getString());
assertEquals("ghi", vs[2].getString());
assertEquals(PropertyType.BINARY, pi.getType());
}
use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class NodeTypeRegistry method toString.
//--------------------------------------------------------------< Object >
/**
* {@inheritDoc}
*/
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("NodeTypeRegistry (" + super.toString() + ")\n");
builder.append("Registered NodeTypes:\n");
for (QNodeTypeDefinition ntd : registeredNTDefs.values()) {
builder.append(ntd.getName());
builder.append("\n");
builder.append("\tSupertypes: " + Arrays.toString(ntd.getSupertypes()) + "\n");
builder.append("\tMixin\t" + ntd.isMixin() + "\n");
builder.append("\tOrderableChildNodes\t" + ntd.hasOrderableChildNodes() + "\n");
builder.append("\tPrimaryItemName\t" + (ntd.getPrimaryItemName() == null ? "<null>" : ntd.getPrimaryItemName().toString()) + "\n");
QPropertyDefinition[] pd = ntd.getPropertyDefs();
for (QPropertyDefinition aPd : pd) {
builder.append("\tPropertyDefinition\n");
builder.append(" (declared in " + aPd.getDeclaringNodeType() + ")\n");
builder.append("\t\tName\t\t" + (aPd.definesResidual() ? "*" : aPd.getName().toString()) + "\n");
String type = aPd.getRequiredType() == 0 ? "null" : PropertyType.nameFromValue(aPd.getRequiredType());
builder.append("\t\tRequiredType\t" + type + "\n");
QValueConstraint[] vca = aPd.getValueConstraints();
StringBuilder constraints = new StringBuilder();
if (vca == null) {
constraints.append("<null>");
} else {
for (QValueConstraint aVca : vca) {
if (constraints.length() > 0) {
constraints.append(", ");
}
constraints.append(aVca.getString());
}
}
builder.append("\t\tValueConstraints\t" + constraints + "\n");
QValue[] defVals = aPd.getDefaultValues();
StringBuilder defaultValues = new StringBuilder();
if (defVals == null) {
defaultValues.append("<null>");
} else {
for (QValue defVal : defVals) {
if (defaultValues.length() > 0) {
defaultValues.append(", ");
}
defaultValues.append(defVal.toString());
}
}
builder.append("\t\tDefaultValue\t" + defaultValues + "\n");
builder.append("\t\tAutoCreated\t" + aPd.isAutoCreated() + "\n");
builder.append("\t\tMandatory\t" + aPd.isMandatory() + "\n");
builder.append("\t\tOnVersion\t" + OnParentVersionAction.nameFromValue(aPd.getOnParentVersion()) + "\n");
builder.append("\t\tProtected\t" + aPd.isProtected() + "\n");
builder.append("\t\tMultiple\t" + aPd.isMultiple() + "\n");
}
QNodeDefinition[] nd = ntd.getChildNodeDefs();
for (QNodeDefinition aNd : nd) {
builder.append("\tNodeDefinition\\n");
builder.append(" (declared in " + aNd.getDeclaringNodeType() + ")\\n");
builder.append("\t\tName\t\t" + (aNd.definesResidual() ? "*" : aNd.getName().toString()) + "\n");
Name[] reqPrimaryTypes = aNd.getRequiredPrimaryTypes();
if (reqPrimaryTypes != null && reqPrimaryTypes.length > 0) {
for (Name reqPrimaryType : reqPrimaryTypes) {
builder.append("\t\tRequiredPrimaryType\t" + reqPrimaryType + "\n");
}
}
Name defPrimaryType = aNd.getDefaultPrimaryType();
if (defPrimaryType != null) {
builder.append("\n\t\tDefaultPrimaryType\t" + defPrimaryType + "\n");
}
builder.append("\n\t\tAutoCreated\t" + aNd.isAutoCreated() + "\n");
builder.append("\t\tMandatory\t" + aNd.isMandatory() + "\n");
builder.append("\t\tOnVersion\t" + OnParentVersionAction.nameFromValue(aNd.getOnParentVersion()) + "\n");
builder.append("\t\tProtected\t" + aNd.isProtected() + "\n");
builder.append("\t\tAllowsSameNameSiblings\t" + aNd.allowsSameNameSiblings() + "\n");
}
}
builder.append(entCache);
return builder.toString();
}
use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class ValueFormat method getQValue.
/**
*
* @param jcrValue
* @param propertyType
* @param resolver
* @param factory
* @return
* @throws RepositoryException
*/
public static QValue getQValue(String jcrValue, int propertyType, NamePathResolver resolver, QValueFactory factory) throws RepositoryException {
QValue qValue;
switch(propertyType) {
case PropertyType.STRING:
case PropertyType.BOOLEAN:
case PropertyType.DOUBLE:
case PropertyType.LONG:
case PropertyType.DECIMAL:
case PropertyType.DATE:
case PropertyType.REFERENCE:
case PropertyType.WEAKREFERENCE:
case PropertyType.URI:
qValue = factory.create(jcrValue, propertyType);
break;
case PropertyType.BINARY:
qValue = factory.create(jcrValue.getBytes());
break;
case PropertyType.NAME:
Name qName = resolver.getQName(jcrValue);
qValue = factory.create(qName);
break;
case PropertyType.PATH:
Path qPath = resolver.getQPath(jcrValue, false);
qValue = factory.create(qPath);
break;
default:
throw new IllegalArgumentException("Invalid property type.");
}
return qValue;
}
Aggregations