Search in sources :

Example 46 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.

the class NodeTypeImpl method canSetProperty.

/**
     * {@inheritDoc}
     */
public boolean canSetProperty(String propertyName, Value value) {
    if (value == null) {
        // setting a property to null is equivalent of removing it
        return canRemoveItem(propertyName);
    }
    try {
        Name name = resolver.getQName(propertyName);
        QPropertyDefinition def;
        try {
            // try to get definition that matches the given value type
            def = ent.getApplicablePropertyDef(name, value.getType(), false);
        } catch (ConstraintViolationException cve) {
            // fallback: ignore type
            def = ent.getApplicablePropertyDef(name, PropertyType.UNDEFINED, false);
        }
        if (def.isProtected()) {
            return false;
        }
        if (def.isMultiple()) {
            return false;
        }
        int targetType;
        if (def.getRequiredType() != PropertyType.UNDEFINED && def.getRequiredType() != value.getType()) {
            // type conversion required
            targetType = def.getRequiredType();
        } else {
            // no type conversion required
            targetType = value.getType();
        }
        // perform type conversion as necessary and create InternalValue
        // from (converted) Value
        InternalValue internalValue;
        if (targetType != value.getType()) {
            // type conversion required
            Value targetVal = ValueHelper.convert(value, targetType, valueFactory);
            internalValue = InternalValue.create(targetVal, resolver, store);
        } else {
            // no type conversion required
            internalValue = InternalValue.create(value, resolver, store);
        }
        EffectiveNodeType.checkSetPropertyValueConstraints(def, new InternalValue[] { internalValue });
        return true;
    } catch (NameException be) {
    // implementation specific exception, fall through
    } catch (RepositoryException re) {
    // fall through
    }
    return false;
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Value(javax.jcr.Value) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) RepositoryException(javax.jcr.RepositoryException) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Name(org.apache.jackrabbit.spi.Name)

Example 47 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.

the class NodeTypeImpl method canAddChildNode.

/**
     * @see javax.jcr.nodetype.NodeType#canAddChildNode(String, String)
     */
public boolean canAddChildNode(String childNodeName, String nodeTypeName) {
    try {
        Name ntName = resolver().getQName(nodeTypeName);
        QNodeTypeDefinition def = ntMgr.getNodeTypeDefinition(ntName);
        ent.checkAddNodeConstraints(resolver().getQName(childNodeName), def, definitionProvider());
        return true;
    } catch (NameException be) {
    // implementation specific exception, fall through
    } catch (RepositoryException re) {
    // fall through
    }
    return false;
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name)

Example 48 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.

the class NodeTypeImpl method canSetProperty.

/**
     * @see javax.jcr.nodetype.NodeType#canSetProperty(String, Value)
     */
public boolean canSetProperty(String propertyName, Value value) {
    if (value == null) {
        // setting a property to null is equivalent of removing it
        return canRemoveItem(propertyName);
    }
    try {
        Name name = resolver().getQName(propertyName);
        QPropertyDefinition def;
        try {
            // try to get definition that matches the given value type
            def = getApplicablePropDef(name, value.getType(), false);
        } catch (ConstraintViolationException cve) {
            // fallback: ignore type
            def = getApplicablePropDef(name, PropertyType.UNDEFINED, false);
        }
        if (def.isProtected()) {
            return false;
        }
        if (def.isMultiple()) {
            return false;
        }
        Value v;
        if (def.getRequiredType() != PropertyType.UNDEFINED && def.getRequiredType() != value.getType()) {
            // type conversion required
            v = ValueHelper.convert(value, def.getRequiredType(), mgrProvider.getJcrValueFactory());
        } else {
            // no type conversion required
            v = value;
        }
        // create QValue from Value
        QValue qValue = ValueFormat.getQValue(v, resolver(), mgrProvider.getQValueFactory());
        checkSetPropertyValueConstraints(def, new QValue[] { qValue });
        return true;
    } catch (NameException re) {
    // fall through
    } catch (RepositoryException e) {
    // fall through
    }
    return false;
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name)

Example 49 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.

the class NodeTypeImpl method canSetProperty.

/**
     * @see javax.jcr.nodetype.NodeType#canSetProperty(String, Value[])
     */
public boolean canSetProperty(String propertyName, Value[] values) {
    if (values == null) {
        // setting a property to null is equivalent of removing it
        return canRemoveItem(propertyName);
    }
    try {
        Name name = resolver().getQName(propertyName);
        // determine type of values
        int type = PropertyType.UNDEFINED;
        for (int i = 0; i < values.length; i++) {
            if (values[i] == null) {
                // skip null values as those would be purged
                continue;
            }
            if (type == PropertyType.UNDEFINED) {
                type = values[i].getType();
            } else if (type != values[i].getType()) {
                // inhomogeneous types
                return false;
            }
        }
        QPropertyDefinition def;
        try {
            // try to get definition that matches the given value type
            def = getApplicablePropDef(name, type, true);
        } catch (ConstraintViolationException cve) {
            // fallback: ignore type
            def = getApplicablePropDef(name, PropertyType.UNDEFINED, true);
        }
        if (def.isProtected()) {
            return false;
        }
        if (!def.isMultiple()) {
            return false;
        }
        // determine target type
        int targetType;
        if (def.getRequiredType() != PropertyType.UNDEFINED && def.getRequiredType() != type) {
            // type conversion required
            targetType = def.getRequiredType();
        } else {
            // no type conversion required
            targetType = type;
        }
        ArrayList<QValue> list = new ArrayList<QValue>();
        // convert values and compact array (purge null entries)
        for (int i = 0; i < values.length; i++) {
            if (values[i] != null) {
                // create QValue from Value and perform
                // type conversion as necessary
                Value v = ValueHelper.convert(values[i], targetType, mgrProvider.getJcrValueFactory());
                QValue qValue = ValueFormat.getQValue(v, resolver(), mgrProvider.getQValueFactory());
                list.add(qValue);
            }
        }
        QValue[] internalValues = list.toArray(new QValue[list.size()]);
        checkSetPropertyValueConstraints(def, internalValues);
        return true;
    } catch (NameException be) {
    // implementation specific exception, fall through
    } catch (RepositoryException re) {
    // fall through
    }
    return false;
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) ArrayList(java.util.ArrayList) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) RepositoryException(javax.jcr.RepositoryException) ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint) Name(org.apache.jackrabbit.spi.Name)

Example 50 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.

the class SysViewImportHandler method endElement.

/**
     * {@inheritDoc}
     */
@Override
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
    // check element name
    ImportState state = stack.peek();
    if (NODE.equals(localName)) {
        // sv:node element
        if (!state.started) {
            // need to start & end current node
            processNode(state, true, true);
            state.started = true;
        } else {
            // need to end current node
            processNode(state, false, true);
        }
        // pop current state from stack
        stack.pop();
    } else if (PROPERTY.equals(localName)) {
        // have been collected and create node as necessary
        if (currentPropName.equals(NameConstants.JCR_PRIMARYTYPE)) {
            AppendableValue val = (AppendableValue) currentPropValues.get(0);
            String s = null;
            try {
                s = val.retrieve();
                state.nodeTypeName = resolver.getQName(s);
            } catch (IOException ioe) {
                throw new SAXException("error while retrieving value", ioe);
            } catch (NameException e) {
                throw new SAXException(new InvalidSerializedDataException("illegal node type name: " + s, e));
            } catch (NamespaceException e) {
                throw new SAXException(new InvalidSerializedDataException("illegal node type name: " + s, e));
            }
        } else if (currentPropName.equals(NameConstants.JCR_MIXINTYPES)) {
            if (state.mixinNames == null) {
                state.mixinNames = new ArrayList<Name>(currentPropValues.size());
            }
            for (int i = 0; i < currentPropValues.size(); i++) {
                AppendableValue val = (AppendableValue) currentPropValues.get(i);
                String s = null;
                try {
                    s = val.retrieve();
                    Name mixin = resolver.getQName(s);
                    state.mixinNames.add(mixin);
                } catch (IOException ioe) {
                    throw new SAXException("error while retrieving value", ioe);
                } catch (NameException e) {
                    throw new SAXException(new InvalidSerializedDataException("illegal mixin type name: " + s, e));
                } catch (NamespaceException e) {
                    throw new SAXException(new InvalidSerializedDataException("illegal mixin type name: " + s, e));
                }
            }
        } else if (currentPropName.equals(NameConstants.JCR_UUID)) {
            AppendableValue val = (AppendableValue) currentPropValues.get(0);
            try {
                state.uuid = val.retrieve();
            } catch (IOException ioe) {
                throw new SAXException("error while retrieving value", ioe);
            }
        } else {
            Importer.TextValue[] values = currentPropValues.toArray(new Importer.TextValue[currentPropValues.size()]);
            Importer.PropInfo prop = new Importer.PropInfo(currentPropName, currentPropType, values);
            state.props.add(prop);
        }
        // reset temp fields
        currentPropValues.clear();
    } else if (VALUE.equals(localName)) {
        // sv:value element
        currentPropValues.add(currentPropValue);
        // reset temp fields
        currentPropValue = null;
    } else {
        throw new SAXException(new InvalidSerializedDataException("invalid element in system view xml document: " + localName));
    }
}
Also used : InvalidSerializedDataException(javax.jcr.InvalidSerializedDataException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) Name(org.apache.jackrabbit.spi.Name) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) NamespaceException(javax.jcr.NamespaceException)

Aggregations

NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)65 RepositoryException (javax.jcr.RepositoryException)44 Name (org.apache.jackrabbit.spi.Name)38 Path (org.apache.jackrabbit.spi.Path)20 NamespaceException (javax.jcr.NamespaceException)17 ArrayList (java.util.ArrayList)16 IllegalNameException (org.apache.jackrabbit.spi.commons.conversion.IllegalNameException)9 SAXException (org.xml.sax.SAXException)8 Node (javax.jcr.Node)6 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)6 InvalidQueryException (javax.jcr.query.InvalidQueryException)6 NodeId (org.apache.jackrabbit.core.id.NodeId)6 IOException (java.io.IOException)5 ItemNotFoundException (javax.jcr.ItemNotFoundException)5 PathNotFoundException (javax.jcr.PathNotFoundException)5 Value (javax.jcr.Value)5 LocationStepQueryNode (org.apache.jackrabbit.spi.commons.query.LocationStepQueryNode)5 AccessDeniedException (javax.jcr.AccessDeniedException)4 NodeType (javax.jcr.nodetype.NodeType)4 VersionException (javax.jcr.version.VersionException)4