Search in sources :

Example 1 with JackrabbitNodeTypeManager

use of org.apache.jackrabbit.api.JackrabbitNodeTypeManager in project jackrabbit by apache.

the class DocumentViewTest method setUp.

/**
 * Sets up the test fixture.
 *
 * @throws Exception if an unexpected error occurs
 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    JackrabbitNodeTypeManager manager = (JackrabbitNodeTypeManager) superuser.getWorkspace().getNodeTypeManager();
    try {
        manager.getNodeType("DocViewMultiValueTest");
    } catch (NoSuchNodeTypeException e) {
        String cnd = "[DocViewMultiValueTest] - test (boolean) multiple";
        Reader cndReader = new InputStreamReader(new ByteArrayInputStream(cnd.getBytes("UTF-8")));
        CndImporter.registerNodeTypes(cndReader, superuser);
    }
}
Also used : JackrabbitNodeTypeManager(org.apache.jackrabbit.api.JackrabbitNodeTypeManager) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 2 with JackrabbitNodeTypeManager

use of org.apache.jackrabbit.api.JackrabbitNodeTypeManager in project jackrabbit by apache.

the class AbstractRepositoryTest method createTestData.

protected void createTestData(Session session) throws Exception {
    JackrabbitNodeTypeManager manager = (JackrabbitNodeTypeManager) session.getWorkspace().getNodeTypeManager();
    String cnd = "<nt='http://www.jcp.org/jcr/nt/1.0'>\n" + "<mix='http://www.jcp.org/jcr/mix/1.0'>\n" + "[nt:myversionable] > nt:unstructured, mix:versionable\n";
    manager.registerNodeTypes(new ByteArrayInputStream(cnd.getBytes("UTF-8")), JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
    Node root = session.getRootNode();
    Node test = root.addNode("test", "nt:unstructured");
    root.save();
    Node versionable = createVersionable(test);
    createProperties(test, versionable);
    createLock(test);
    createUsers(session);
}
Also used : JackrabbitNodeTypeManager(org.apache.jackrabbit.api.JackrabbitNodeTypeManager) ByteArrayInputStream(java.io.ByteArrayInputStream) Node(javax.jcr.Node)

Example 3 with JackrabbitNodeTypeManager

use of org.apache.jackrabbit.api.JackrabbitNodeTypeManager 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)

Example 4 with JackrabbitNodeTypeManager

use of org.apache.jackrabbit.api.JackrabbitNodeTypeManager 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 JackrabbitNodeTypeManager

use of org.apache.jackrabbit.api.JackrabbitNodeTypeManager in project jackrabbit by apache.

the class TestContentLoader method loadTestContent.

public void loadTestContent(Session session) throws RepositoryException, IOException {
    JackrabbitWorkspace workspace = (JackrabbitWorkspace) session.getWorkspace();
    Collection<String> workspaces = Arrays.asList(workspace.getAccessibleWorkspaceNames());
    if (!workspaces.contains("test")) {
        workspace.createWorkspace("test");
    }
    JackrabbitNodeTypeManager manager = (JackrabbitNodeTypeManager) workspace.getNodeTypeManager();
    if (!manager.hasNodeType("test:versionable")) {
        InputStream xml = TestContentLoader.class.getResourceAsStream("test-nodetypes.xml");
        try {
            manager.registerNodeTypes(xml, JackrabbitNodeTypeManager.TEXT_XML);
        } finally {
            xml.close();
        }
    }
    Node data = getOrAddNode(session.getRootNode(), "testdata");
    addPropertyTestData(getOrAddNode(data, "property"));
    addQueryTestData(getOrAddNode(data, "query"));
    addNodeTestData(getOrAddNode(data, "node"));
    addLifecycleTestData(getOrAddNode(data, "lifecycle"));
    addExportTestData(getOrAddNode(data, "docViewTest"));
    Node conf = getOrAddNode(session.getRootNode(), "testconf");
    addRetentionTestData(getOrAddNode(conf, "retentionTest"));
    session.save();
}
Also used : JackrabbitNodeTypeManager(org.apache.jackrabbit.api.JackrabbitNodeTypeManager) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Node(javax.jcr.Node) JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace)

Aggregations

JackrabbitNodeTypeManager (org.apache.jackrabbit.api.JackrabbitNodeTypeManager)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Node (javax.jcr.Node)2 RepositoryException (javax.jcr.RepositoryException)2 InvalidNodeTypeDefException (org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 NoSuchNodeTypeException (javax.jcr.nodetype.NoSuchNodeTypeException)1 JackrabbitWorkspace (org.apache.jackrabbit.api.JackrabbitWorkspace)1