Search in sources :

Example 1 with QValue

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

the class EventImpl method getInfo.

/**
     * @see javax.jcr.observation.Event#getInfo()
     */
public Map<String, String> getInfo() throws RepositoryException {
    Map<String, String> jcrInfo = new HashMap<String, String>();
    for (Map.Entry<Name, QValue> entry : event.getInfo().entrySet()) {
        Name key = entry.getKey();
        QValue value = entry.getValue();
        String strValue = null;
        if (value != null) {
            strValue = ValueFormat.getJCRString(value, resolver);
        }
        jcrInfo.put(resolver.getJCRName(key), strValue);
    }
    return jcrInfo;
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Name(org.apache.jackrabbit.spi.Name)

Example 2 with QValue

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

the class RepositoryServiceImpl method getPropertyInfo.

/**
     * @see RepositoryService#getPropertyInfo(SessionInfo, PropertyId)
     */
@Override
public PropertyInfo getPropertyInfo(SessionInfo sessionInfo, PropertyId propertyId) throws RepositoryException {
    Path p = getPath(propertyId, sessionInfo);
    String uri = getURI(p, sessionInfo);
    HttpPropfind request = null;
    try {
        request = new HttpPropfind(uri, LAZY_PROPERTY_NAME_SET, DavConstants.DEPTH_0);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (mresponses.length != 1) {
            throw new ItemNotFoundException("Unable to retrieve the PropertyInfo. No such property " + uri);
        }
        MultiStatusResponse mresponse = mresponses[0];
        DavPropertySet props = mresponse.getProperties(DavServletResponse.SC_OK);
        int propertyType = PropertyType.valueFromName(props.get(JCR_TYPE).getValue().toString());
        if (propertyType == PropertyType.BINARY) {
            DavProperty<?> lengthsProp = props.get(JCR_LENGTHS);
            if (lengthsProp != null) {
                // multivalued binary property
                long[] lengths = ValueUtil.lengthsFromXml(lengthsProp.getValue());
                QValue[] qValues = new QValue[lengths.length];
                for (int i = 0; i < lengths.length; i++) {
                    qValues[i] = getQValueFactory(sessionInfo).create(lengths[i], uri, i);
                }
                return new PropertyInfoImpl(propertyId, p, propertyType, qValues);
            } else {
                // single valued binary property
                long length = Long.parseLong(props.get(JCR_LENGTH).getValue().toString());
                QValue qValue = getQValueFactory(sessionInfo).create(length, uri, QValueFactoryImpl.NO_INDEX);
                return new PropertyInfoImpl(propertyId, p, propertyType, qValue);
            }
        } else if (props.contains(JCR_GET_STRING)) {
            // single valued non-binary property
            Object v = props.get(JCR_GET_STRING).getValue();
            String str = (v == null) ? "" : v.toString();
            QValue qValue = ValueFormat.getQValue(str, propertyType, getNamePathResolver(sessionInfo), getQValueFactory(sessionInfo));
            return new PropertyInfoImpl(propertyId, p, propertyType, qValue);
        } else {
            // didn't expose the JCR_GET_STRING dav property.
            return super.getPropertyInfo(sessionInfo, propertyId);
        }
    } catch (IOException e) {
        log.error("Internal error while retrieving ItemInfo.", e);
        throw new RepositoryException(e.getMessage());
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) QValue(org.apache.jackrabbit.spi.QValue) DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 3 with QValue

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

the class BatchTest method testSetDateValue.

public void testSetDateValue() throws RepositoryException {
    NodeId nid = getNodeId(testPath);
    Name propName = resolver.getQName("dateProp");
    QValue v = rs.getQValueFactory().create(Calendar.getInstance());
    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(v.getString(), pi.getValues()[0].getString());
    assertEquals(PropertyType.DATE, pi.getType());
    pi = getPropertyInfo(nid, propName);
    assertEquals(v, pi.getValues()[0]);
    assertEquals(v.getString(), pi.getValues()[0].getString());
    assertEquals(PropertyType.DATE, 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 4 with QValue

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

the class BatchTest method testSetLongValue.

public void testSetLongValue() throws RepositoryException {
    NodeId nid = getNodeId(testPath);
    Name propName = resolver.getQName("doubleProp");
    QValue v = rs.getQValueFactory().create(234567);
    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(v.getString(), pi.getValues()[0].getString());
    assertEquals(PropertyType.LONG, pi.getType());
    pi = getPropertyInfo(nid, propName);
    assertEquals(v, pi.getValues()[0]);
    assertEquals(v.getString(), pi.getValues()[0].getString());
    assertEquals(PropertyType.LONG, 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 5 with QValue

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

the class BatchTest method testEmptyValueArray.

public void testEmptyValueArray() throws RepositoryException {
    NodeId nid = getNodeId(testPath);
    Name propName = resolver.getQName("mvProperty");
    Batch b = rs.createBatch(si, nid);
    b.addProperty(nid, propName, new QValue[0]);
    rs.submit(b);
    PropertyId pid = getPropertyId(nid, propName);
    PropertyInfo pi = rs.getPropertyInfo(si, pid);
    assertTrue(pi.isMultiValued());
    assertEquals(Arrays.asList(new QValue[0]), Arrays.asList(pi.getValues()));
    assertFalse(pi.getType() == PropertyType.UNDEFINED);
    Iterator<? extends ItemInfo> it = rs.getItemInfos(si, nid);
    while (it.hasNext()) {
        ItemInfo info = it.next();
        if (!info.denotesNode()) {
            PropertyInfo pInfo = (PropertyInfo) info;
            if (propName.equals((pInfo.getId().getName()))) {
                assertTrue(pi.isMultiValued());
                assertEquals(Arrays.asList(new QValue[0]), Arrays.asList(pi.getValues()));
                assertFalse(pi.getType() == PropertyType.UNDEFINED);
                break;
            }
        }
    }
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) Batch(org.apache.jackrabbit.spi.Batch) ItemInfo(org.apache.jackrabbit.spi.ItemInfo) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.spi.PropertyId)

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