Search in sources :

Example 6 with QValue

use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.

the class ItemInfoJsonHandler method endArray.

public void endArray() throws IOException {
    try {
        if (propertyType == PropertyType.UNDEFINED) {
            if (propValues.isEmpty()) {
                // make sure that type is set for mv-properties with empty value array.
                propertyType = vFactory.retrieveType(getValueURI());
            } else {
                propertyType = propValues.get(0).getType();
            }
        }
        // create multi-valued property info
        NodeInfoImpl parent = getCurrentNodeInfo();
        Path p = pFactory.create(parent.getPath(), name, true);
        PropertyId id = idFactory.createPropertyId(parent.getId(), name);
        PropertyInfoImpl propInfo = new PropertyInfoImpl(id, p, propertyType, propValues.toArray(new QValue[propValues.size()]));
        propInfo.checkCompleted();
        getCurrentPropInfos().add(propInfo);
    } catch (RepositoryException e) {
        throw new IOException(e.getMessage());
    } finally {
        // reset property-related handler state
        propertyType = PropertyType.UNDEFINED;
        multiValuedProperty = false;
        propValues.clear();
        name = null;
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) QValue(org.apache.jackrabbit.spi.QValue) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) PropertyId(org.apache.jackrabbit.spi.PropertyId)

Example 7 with QValue

use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.

the class NodeInfoImpl method setPropertyInfos.

//--------------------------------------------------------------------------
void setPropertyInfos(PropertyInfoImpl[] propInfos, IdFactory idFactory) throws RepositoryException {
    boolean resolveUUID = false;
    for (PropertyInfoImpl propInfo : propInfos) {
        Name pn = propInfo.getId().getName();
        if (NameConstants.JCR_UUID.equals(pn)) {
            id = idFactory.createNodeId(propInfo.getValues()[0].getString());
            resolveUUID = true;
        } else if (NameConstants.JCR_PRIMARYTYPE.equals(pn)) {
            primaryNodeTypeName = propInfo.getValues()[0].getName();
        } else if (NameConstants.JCR_MIXINTYPES.equals(pn)) {
            QValue[] vs = propInfo.getValues();
            Name[] mixins = new Name[vs.length];
            for (int i = 0; i < vs.length; i++) {
                mixins[i] = vs[i].getName();
            }
            mixinNodeTypeNames = mixins;
        }
    }
    propertyIds.clear();
    for (PropertyInfoImpl propInfo : propInfos) {
        if (resolveUUID) {
            propInfo.setId(idFactory.createPropertyId(id, propInfo.getName()));
        }
        propertyIds.add(propInfo.getId());
    }
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) Name(org.apache.jackrabbit.spi.Name)

Example 8 with QValue

use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.

the class BatchTest method testSetEmptyBinaryValues.

public void testSetEmptyBinaryValues() 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[0]), rs.getQValueFactory().create(new byte[0]), rs.getQValueFactory().create(new byte[0]) };
    b.addProperty(nid, propName, vs);
    rs.submit(b);
    PropertyInfo pi = rs.getPropertyInfo(si, getPropertyId(nid, propName));
    assertTrue(pi.isMultiValued());
    vs = pi.getValues();
    assertEquals("", vs[0].getString());
    assertEquals("", vs[1].getString());
    assertEquals("", vs[2].getString());
    assertEquals(PropertyType.BINARY, pi.getType());
    pi = getPropertyInfo(nid, propName);
    vs = pi.getValues();
    assertEquals("", vs[0].getString());
    assertEquals("", vs[1].getString());
    assertEquals("", vs[2].getString());
    assertEquals(PropertyType.BINARY, pi.getType());
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) Batch(org.apache.jackrabbit.spi.Batch) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) Name(org.apache.jackrabbit.spi.Name)

Example 9 with QValue

use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.

the class BatchTest method testSetPathValue.

public void testSetPathValue() throws RepositoryException {
    NodeId nid = getNodeId(testPath);
    Name propName = resolver.getQName("pathProp");
    QValue v = rs.getQValueFactory().create(resolver.getQPath(testPath));
    Batch b = rs.createBatch(si, nid);
    b.addProperty(nid, propName, v);
    rs.submit(b);
    PropertyInfo pi = rs.getPropertyInfo(si, getPropertyId(nid, propName));
    assertFalse(pi.isMultiValued());
    assertEquals(v, pi.getValues()[0]);
    assertEquals(PropertyType.PATH, pi.getType());
    pi = getPropertyInfo(nid, propName);
    assertEquals(v.getPath(), pi.getValues()[0].getPath());
    assertEquals(v, pi.getValues()[0]);
    assertEquals(PropertyType.PATH, pi.getType());
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) Batch(org.apache.jackrabbit.spi.Batch) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) Name(org.apache.jackrabbit.spi.Name)

Example 10 with QValue

use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.

the class BatchTest method testSetBooleanValue.

public void testSetBooleanValue() throws RepositoryException {
    NodeId nid = getNodeId(testPath);
    Name propName = resolver.getQName("booleanProp");
    QValue v = rs.getQValueFactory().create(false);
    Batch b = rs.createBatch(si, nid);
    b.addProperty(nid, propName, v);
    rs.submit(b);
    PropertyInfo pi = rs.getPropertyInfo(si, getPropertyId(nid, propName));
    assertFalse(pi.isMultiValued());
    assertFalse(pi.getValues()[0].getBoolean());
    assertEquals(PropertyType.BOOLEAN, pi.getType());
    pi = getPropertyInfo(nid, propName);
    assertFalse(pi.getValues()[0].getBoolean());
    assertEquals(PropertyType.BOOLEAN, pi.getType());
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) Batch(org.apache.jackrabbit.spi.Batch) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) Name(org.apache.jackrabbit.spi.Name)

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