Search in sources :

Example 51 with QValue

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

Example 52 with QValue

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;
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) QValue(org.apache.jackrabbit.spi.QValue) HashMap(java.util.HashMap) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) NamespaceResolver(org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver)

Example 53 with QValue

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());
}
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 54 with QValue

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();
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) Name(org.apache.jackrabbit.spi.Name) QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition)

Example 55 with QValue

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