Search in sources :

Example 1 with InvalidNodeTypeDefException

use of org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException in project jackrabbit by apache.

the class ClusterNode method process.

/**
     * {@inheritDoc}
     */
public void process(NodeTypeRecord record) {
    if (nodeTypeListener == null) {
        String msg = "NodeType listener unavailable.";
        log.error(msg);
        return;
    }
    Collection coll = record.getCollection();
    try {
        switch(record.getOperation()) {
            case NodeTypeRecord.REGISTER:
                nodeTypeListener.externalRegistered(coll);
                break;
            case NodeTypeRecord.UNREGISTER:
                nodeTypeListener.externalUnregistered(coll);
                break;
            case NodeTypeRecord.REREGISTER:
                QNodeTypeDefinition ntd = (QNodeTypeDefinition) coll.iterator().next();
                nodeTypeListener.externalReregistered(ntd);
                break;
        }
    } catch (InvalidNodeTypeDefException e) {
        String msg = "Unable to deliver node type operation: " + e.getMessage();
        log.error(msg);
    } catch (RepositoryException e) {
        String msg = "Unable to deliver node type operation: " + e.getMessage();
        log.error(msg);
    }
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) InvalidNodeTypeDefException(org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException) Collection(java.util.Collection) RepositoryException(javax.jcr.RepositoryException)

Example 2 with InvalidNodeTypeDefException

use of org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException in project jackrabbit by apache.

the class NodeTypeReader method getPropDef.

/**
     * Returns the property definition specified by the current element.
     *
     * @return property definition
     * @throws InvalidNodeTypeDefException if the definition is invalid
     * @throws NameException               if the definition contains an
     *                                     illegal name
     * @throws NamespaceException if a namespace is not defined
     */
private QPropertyDefinitionBuilder getPropDef() throws InvalidNodeTypeDefException, NameException, NamespaceException {
    QPropertyDefinitionBuilder def = new QPropertyDefinitionBuilder();
    String name = walker.getAttribute(Constants.NAME_ATTRIBUTE);
    if (name.equals("*")) {
        def.setName(NameConstants.ANY_NAME);
    } else {
        def.setName(resolver.getQName(name));
    }
    // simple attributes
    def.setAutoCreated(Boolean.valueOf(walker.getAttribute(Constants.AUTOCREATED_ATTRIBUTE)));
    def.setMandatory(Boolean.valueOf(walker.getAttribute(Constants.MANDATORY_ATTRIBUTE)));
    def.setProtected(Boolean.valueOf(walker.getAttribute(Constants.PROTECTED_ATTRIBUTE)));
    def.setOnParentVersion(OnParentVersionAction.valueFromName(walker.getAttribute(Constants.ONPARENTVERSION_ATTRIBUTE)));
    def.setMultiple(Boolean.valueOf(walker.getAttribute(Constants.MULTIPLE_ATTRIBUTE)));
    def.setFullTextSearchable(Boolean.valueOf(walker.getAttribute(Constants.ISFULLTEXTSEARCHABLE_ATTRIBUTE)));
    def.setQueryOrderable(Boolean.valueOf(walker.getAttribute(Constants.ISQUERYORDERABLE_ATTRIBUTE)));
    String s = walker.getAttribute(Constants.AVAILABLEQUERYOPERATORS_ATTRIBUTE);
    if (s != null && s.length() > 0) {
        String[] ops = s.split(" ");
        List<String> queryOps = new ArrayList<String>();
        for (String op1 : ops) {
            String op = op1.trim();
            if (op.equals(Constants.EQ_ENTITY)) {
                queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO);
            } else if (op.equals(Constants.NE_ENTITY)) {
                queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_NOT_EQUAL_TO);
            } else if (op.equals(Constants.LT_ENTITY)) {
                queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN);
            } else if (op.equals(Constants.LE_ENTITY)) {
                queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO);
            } else if (op.equals(Constants.GT_ENTITY)) {
                queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN);
            } else if (op.equals(Constants.GE_ENTITY)) {
                queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO);
            } else if (op.equals(Constants.LIKE_ENTITY)) {
                queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_LIKE);
            } else {
                throw new InvalidNodeTypeDefException("'" + op + "' is not a valid query operator");
            }
        }
        def.setAvailableQueryOperators(queryOps.toArray(new String[queryOps.size()]));
    }
    def.setRequiredType(PropertyType.valueFromName(walker.getAttribute(Constants.REQUIREDTYPE_ATTRIBUTE)));
    // value constraints
    if (walker.enterElement(Constants.VALUECONSTRAINTS_ELEMENT)) {
        List<QValueConstraint> constraints = new ArrayList<QValueConstraint>();
        int type = def.getRequiredType();
        while (walker.iterateElements(Constants.VALUECONSTRAINT_ELEMENT)) {
            String constraint = walker.getContent();
            try {
                constraints.add(ValueConstraint.create(type, constraint.trim(), resolver));
            } catch (InvalidConstraintException e) {
                throw new InvalidNodeTypeDefException("Invalid value constraint " + constraint, e);
            }
        }
        def.setValueConstraints(constraints.toArray(new QValueConstraint[constraints.size()]));
        walker.leaveElement();
    }
    // default values
    if (walker.enterElement(Constants.DEFAULTVALUES_ELEMENT)) {
        List<InternalValue> values = new ArrayList<InternalValue>();
        int type = def.getRequiredType();
        if (type == PropertyType.UNDEFINED) {
            type = PropertyType.STRING;
        }
        while (walker.iterateElements(Constants.DEFAULTVALUE_ELEMENT)) {
            String value = walker.getContent();
            try {
                Value v = ValueHelper.convert(value, type, valueFactory);
                values.add((InternalValue) ValueFormat.getQValue(v, resolver, qValueFactory));
            } catch (RepositoryException e) {
                throw new InvalidNodeTypeDefException("Unable to create default value: " + value, e);
            }
        }
        def.setDefaultValues(values.toArray(new InternalValue[values.size()]));
        walker.leaveElement();
    }
    return def;
}
Also used : InvalidConstraintException(org.apache.jackrabbit.spi.commons.nodetype.InvalidConstraintException) QPropertyDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QPropertyDefinitionBuilder) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) InternalValue(org.apache.jackrabbit.core.value.InternalValue) ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) InvalidNodeTypeDefException(org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Value(javax.jcr.Value)

Example 3 with InvalidNodeTypeDefException

use of org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException in project jackrabbit by apache.

the class LostFromCacheIssueTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    Workspace workspace = superuser.getWorkspace();
    NamespaceRegistry namespaceRegistry = workspace.getNamespaceRegistry();
    NodeTypeManager ntmgr = workspace.getNodeTypeManager();
    NodeTypeRegistry nodetypeRegistry = ((NodeTypeManagerImpl) ntmgr).getNodeTypeRegistry();
    try {
        namespaceRegistry.registerNamespace(NAMESPACE_PREFIX, NAMESPACE_URI);
    } catch (NamespaceException ignore) {
    //already exists
    }
    QNodeTypeDefinition nodeTypeDefinition = new QNodeTypeDefinitionImpl(((SessionImpl) superuser).getQName(NODETYPE_1), Name.EMPTY_ARRAY, Name.EMPTY_ARRAY, true, false, true, false, null, QPropertyDefinition.EMPTY_ARRAY, QNodeDefinition.EMPTY_ARRAY);
    try {
        nodetypeRegistry.registerNodeType(nodeTypeDefinition);
    } catch (InvalidNodeTypeDefException ignore) {
    //already exists
    }
    nodeTypeDefinition = new QNodeTypeDefinitionImpl(((SessionImpl) superuser).getQName(NODETYPE_2), Name.EMPTY_ARRAY, Name.EMPTY_ARRAY, true, false, true, false, null, QPropertyDefinition.EMPTY_ARRAY, QNodeDefinition.EMPTY_ARRAY);
    try {
        nodetypeRegistry.registerNodeType(nodeTypeDefinition);
    } catch (InvalidNodeTypeDefException ignore) {
    //already exists
    }
    getOrCreate(superuser.getRootNode(), TESTNODE_PATH);
    superuser.save();
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) InvalidNodeTypeDefException(org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NamespaceRegistry(javax.jcr.NamespaceRegistry) NamespaceException(javax.jcr.NamespaceException) NodeTypeRegistry(org.apache.jackrabbit.core.nodetype.NodeTypeRegistry) NodeTypeManagerImpl(org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl) Workspace(javax.jcr.Workspace) QNodeTypeDefinitionImpl(org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)

Example 4 with InvalidNodeTypeDefException

use of org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException in project jackrabbit by apache.

the class TestAll method testInvalidXMLNodeTypes.

/** Test for same node type name on node type import. */
public void testInvalidXMLNodeTypes() throws Exception {
    JackrabbitNodeTypeManager ntm = (JackrabbitNodeTypeManager) superuser.getWorkspace().getNodeTypeManager();
    try {
        ntm.registerNodeTypes(TestAll.class.getResourceAsStream(TEST_SAME_NT_NAME_XML_NODETYPES), JackrabbitNodeTypeManager.TEXT_XML);
        fail("Importing multiple node types with the same name must fail");
    } catch (RepositoryException e) {
        if (e.getCause() instanceof InvalidNodeTypeDefException) {
        // Expected
        } else {
            throw e;
        }
    }
}
Also used : InvalidNodeTypeDefException(org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException) JackrabbitNodeTypeManager(org.apache.jackrabbit.api.JackrabbitNodeTypeManager) RepositoryException(javax.jcr.RepositoryException)

Example 5 with InvalidNodeTypeDefException

use of org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException in project jackrabbit by apache.

the class TestAll method testInvalidCNDNodeTypes.

/** Test for same node type name on node type import. */
public void testInvalidCNDNodeTypes() throws Exception {
    JackrabbitNodeTypeManager ntm = (JackrabbitNodeTypeManager) superuser.getWorkspace().getNodeTypeManager();
    try {
        ntm.registerNodeTypes(TestAll.class.getResourceAsStream(TEST_SAME_NT_NAME_CND_NODETYPES), JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
        fail("Importing multiple node types with the same name must fail");
    } catch (RepositoryException e) {
        if (e.getCause() instanceof InvalidNodeTypeDefException) {
        // Expected
        } else {
            throw e;
        }
    }
}
Also used : InvalidNodeTypeDefException(org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException) JackrabbitNodeTypeManager(org.apache.jackrabbit.api.JackrabbitNodeTypeManager) RepositoryException(javax.jcr.RepositoryException)

Aggregations

InvalidNodeTypeDefException (org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException)7 RepositoryException (javax.jcr.RepositoryException)5 QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)4 ArrayList (java.util.ArrayList)2 JackrabbitNodeTypeManager (org.apache.jackrabbit.api.JackrabbitNodeTypeManager)2 NodeTypeRegistry (org.apache.jackrabbit.core.nodetype.NodeTypeRegistry)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Collection (java.util.Collection)1 NamespaceException (javax.jcr.NamespaceException)1 NamespaceRegistry (javax.jcr.NamespaceRegistry)1 Value (javax.jcr.Value)1 Workspace (javax.jcr.Workspace)1 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)1 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)1 InternalValue (org.apache.jackrabbit.core.value.InternalValue)1 Name (org.apache.jackrabbit.spi.Name)1 QValueConstraint (org.apache.jackrabbit.spi.QValueConstraint)1 QNodeTypeDefinitionImpl (org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)1 InvalidConstraintException (org.apache.jackrabbit.spi.commons.nodetype.InvalidConstraintException)1