Search in sources :

Example 6 with InvalidNodeTypeDefException

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

the class TestAll method testWrite.

/**
     * Test for writing a node type definition file. Writing is tested
     * by writing and re-reading the test node types using an internal
     * byte array. The resulting node type map is then compared to the
     * original test node types.
     *
     * @throws IOException on IO errors
     * @throws RepositoryException on repository errors
     */
public void testWrite() throws IOException, RepositoryException {
    try {
        ByteArrayOutputStream xml = new ByteArrayOutputStream();
        NodeTypeWriter.write(xml, types, registry);
        byte[] bytes = xml.toByteArray();
        QNodeTypeDefinition[] output = NodeTypeReader.read(new ByteArrayInputStream(bytes));
        assertTrue("write output", Arrays.equals(types, output));
    } catch (InvalidNodeTypeDefException e) {
        fail(e.getMessage());
    }
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) InvalidNodeTypeDefException(org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 7 with InvalidNodeTypeDefException

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

the class RepositoryCopier method copyNodeTypes.

private void copyNodeTypes() throws RepositoryException {
    NodeTypeRegistry sourceRegistry = source.getNodeTypeRegistry();
    NodeTypeRegistry targetRegistry = target.getNodeTypeRegistry();
    logger.info("Copying registered node types");
    Collection<Name> existing = Arrays.asList(targetRegistry.getRegisteredNodeTypes());
    Collection<QNodeTypeDefinition> register = new ArrayList<QNodeTypeDefinition>();
    for (Name name : sourceRegistry.getRegisteredNodeTypes()) {
        // TODO: what about modified node types?
        if (!existing.contains(name)) {
            register.add(sourceRegistry.getNodeTypeDef(name));
        }
    }
    try {
        targetRegistry.registerNodeTypes(register);
    } catch (InvalidNodeTypeDefException e) {
        throw new RepositoryException("Unable to copy node types", e);
    }
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) InvalidNodeTypeDefException(org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException) ArrayList(java.util.ArrayList) NodeTypeRegistry(org.apache.jackrabbit.core.nodetype.NodeTypeRegistry) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name)

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