Search in sources :

Example 81 with QValue

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);
    }
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name)

Example 82 with QValue

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);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) QValue(org.apache.jackrabbit.spi.QValue) MalformedPathException(org.apache.jackrabbit.spi.commons.conversion.MalformedPathException) ValueFormatException(javax.jcr.ValueFormatException) NamespaceException(javax.jcr.NamespaceException) RepositoryException(javax.jcr.RepositoryException) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) Name(org.apache.jackrabbit.spi.Name)

Example 83 with QValue

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;
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) Value(javax.jcr.Value) QValue(org.apache.jackrabbit.spi.QValue) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name)

Example 84 with QValue

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;
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) QValue(org.apache.jackrabbit.spi.QValue) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name)

Example 85 with QValue

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());
    }
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) Element(org.w3c.dom.Element)

Aggregations

QValue (org.apache.jackrabbit.spi.QValue)125 Name (org.apache.jackrabbit.spi.Name)40 RepositoryException (javax.jcr.RepositoryException)23 Value (javax.jcr.Value)21 NodeId (org.apache.jackrabbit.spi.NodeId)21 Batch (org.apache.jackrabbit.spi.Batch)19 PropertyInfo (org.apache.jackrabbit.spi.PropertyInfo)18 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)12 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 ValueFormatException (javax.jcr.ValueFormatException)8 Path (org.apache.jackrabbit.spi.Path)8 QValueConstraint (org.apache.jackrabbit.spi.QValueConstraint)8 HashMap (java.util.HashMap)7 ValueConstraint (org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint)7 InputStream (java.io.InputStream)5 Node (javax.jcr.Node)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 PropertyId (org.apache.jackrabbit.spi.PropertyId)5