use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class AbstractQValueFactory method computeAutoValues.
//------------------------------------------------------< QValueFactory >---
/**
* @see QValueFactory#computeAutoValues(org.apache.jackrabbit.spi.QPropertyDefinition)
*/
public QValue[] computeAutoValues(QPropertyDefinition propertyDefinition) throws RepositoryException {
Name declaringNT = propertyDefinition.getDeclaringNodeType();
Name name = propertyDefinition.getName();
if (NameConstants.JCR_UUID.equals(name) && NameConstants.MIX_REFERENCEABLE.equals(declaringNT)) {
// jcr:uuid property of a mix:referenceable
return new QValue[] { create(UUID.randomUUID().toString(), PropertyType.STRING) };
} else {
throw new RepositoryException("createFromDefinition not implemented for: " + name);
}
}
use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class ValueFactoryQImpl method createValue.
/**
* {@inheritDoc}
*/
public Value createValue(String value, int type) throws ValueFormatException {
try {
QValue qvalue;
if (type == PropertyType.NAME) {
Name name = resolver.getQName(value);
qvalue = qfactory.create(name);
} else if (type == PropertyType.PATH) {
Path path = resolver.getQPath(value, false);
qvalue = qfactory.create(path);
} else {
qvalue = qfactory.create(value, type);
}
return new QValueValue(qvalue, resolver);
} catch (IllegalNameException ex) {
throw new ValueFormatException(ex);
} catch (MalformedPathException ex) {
throw new ValueFormatException(ex);
} catch (NamespaceException ex) {
throw new ValueFormatException(ex);
} catch (ValueFormatException ex) {
throw ex;
} catch (RepositoryException ex) {
throw new ValueFormatException(ex);
}
}
use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class ValueFormat method getJCRValue.
/**
* @param value
* @param resolver
* @param factory
* @return the JCR value created from the given <code>QValue</code>.
* @throws RepositoryException
*/
public static Value getJCRValue(QValue value, NamePathResolver resolver, ValueFactory factory) throws RepositoryException {
if (factory instanceof ValueFactoryQImpl) {
return ((ValueFactoryQImpl) factory).createValue(value);
} else {
Value jcrValue;
int propertyType = value.getType();
switch(propertyType) {
case PropertyType.STRING:
case PropertyType.REFERENCE:
case PropertyType.WEAKREFERENCE:
case PropertyType.URI:
jcrValue = factory.createValue(value.getString(), propertyType);
break;
case PropertyType.PATH:
Path qPath = value.getPath();
jcrValue = factory.createValue(resolver.getJCRPath(qPath), propertyType);
break;
case PropertyType.NAME:
Name qName = value.getName();
jcrValue = factory.createValue(resolver.getJCRName(qName), propertyType);
break;
case PropertyType.BOOLEAN:
jcrValue = factory.createValue(value.getBoolean());
break;
case PropertyType.BINARY:
jcrValue = factory.createValue(value.getBinary());
break;
case PropertyType.DATE:
jcrValue = factory.createValue(value.getCalendar());
break;
case PropertyType.DOUBLE:
jcrValue = factory.createValue(value.getDouble());
break;
case PropertyType.LONG:
jcrValue = factory.createValue(value.getLong());
break;
case PropertyType.DECIMAL:
jcrValue = factory.createValue(value.getDecimal());
break;
default:
throw new RepositoryException("illegal internal value type");
}
return jcrValue;
}
}
use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class EventImpl method getEventInfo.
private static Map<Name, QValue> getEventInfo(Element infoElement, NamePathResolver resolver, QValueFactory qvFactory) {
if (infoElement == null) {
return Collections.emptyMap();
}
Map<Name, QValue> info = new HashMap<Name, QValue>();
ElementIterator it = DomUtil.getChildren(infoElement);
while (it.hasNext()) {
Element el = it.nextElement();
String uri = el.getNamespaceURI();
if (uri == null) {
uri = Namespace.EMPTY_NAMESPACE.getURI();
}
String localName = el.getLocalName();
String value = DomUtil.getTextTrim(el);
try {
Name n = N_FACTORY.create(uri, localName);
QValue qv = null;
if (value != null) {
qv = ValueFormat.getQValue(value, PropertyType.PATH, resolver, qvFactory);
}
info.put(n, qv);
} catch (RepositoryException e) {
log.error("Internal Error: {}", e.getMessage());
}
}
return info;
}
use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class BatchUtils method importProperty.
static void importProperty(Element nodeElement, Name propertyName, int type, QValue[] values, NamePathResolver resolver) throws RepositoryException {
Element propElement = DomUtil.addChildElement(nodeElement, PROPERTY_ELEMENT, SV_NAMESPACE);
DomUtil.setAttribute(propElement, NAME_ATTRIBUTE, SV_NAMESPACE, resolver.getJCRName(propertyName));
DomUtil.setAttribute(propElement, TYPE_ATTRIBUTE, SV_NAMESPACE, PropertyType.nameFromValue(type));
// build all the values.
for (QValue value : values) {
DomUtil.addChildElement(propElement, VALUE_ELEMENT, SV_NAMESPACE, value.getString());
}
}
Aggregations