Package javax.jcr.nodetype

Examples of javax.jcr.nodetype.NodeTypeManager


    public NodeType[] getMixinNodeTypes() throws RepositoryException {
        checkStatus();

        // TODO: check if transient changes to mixin-types are reflected here
        if (hasProperty(Property.JCR_MIXIN_TYPES)) {
            NodeTypeManager ntMgr = getSession().getWorkspace().getNodeTypeManager();
            Value[] mixinNames = getProperty(Property.JCR_MIXIN_TYPES).getValues();
            NodeType[] mixinTypes = new NodeType[mixinNames.length];
            for (int i = 0; i < mixinNames.length; i++) {
                mixinTypes[i] = ntMgr.getNodeType(mixinNames[i].getString());
            }
            return mixinTypes;
        } else {
            return new NodeType[0];
        }
View Full Code Here


    @Override
    public void setPrimaryType(String nodeTypeName) throws RepositoryException {
        checkStatus();

        // TODO: figure out the right place for this check
        NodeTypeManager ntm = sessionContext.getNodeTypeManager();
        NodeType nt = ntm.getNodeType(nodeTypeName); // throws on not found
        if (nt.isAbstract() || nt.isMixin()) {
            throw new ConstraintViolationException();
        }
        // TODO: END
View Full Code Here

    @Override
    public void addMixin(String mixinName) throws RepositoryException {
        checkStatus();
        // TODO: figure out the right place for this check
        NodeTypeManager ntm = sessionContext.getNodeTypeManager();
        ntm.getNodeType(mixinName); // throws on not found
        // TODO: END

        // todo implement addMixin
    }
View Full Code Here

    }

    @Override
    public boolean canAddMixin(String mixinName) throws RepositoryException {
        // TODO: figure out the right place for this check
        NodeTypeManager ntm = sessionContext.getNodeTypeManager();
        ntm.getNodeType(mixinName); // throws on not found
        // TODO: END

        return false;
    }
View Full Code Here

    }

    @Test
    public void testRegisterNodeType() throws Exception {
        Workspace testWsp = testSession.getWorkspace();
        NodeTypeManager ntm = testWsp.getNodeTypeManager();
        NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
        ntd.setName("testNodeType");
        ntd.setMixin(true);

        try {
            ntm.registerNodeType(ntd, true);
            fail("Node type registration should be denied.");
        } catch (AccessDeniedException e) {
            // success
        }
        try {
            ntm.registerNodeType(ntd, false);
            fail("Node type registration should be denied.");
        } catch (AccessDeniedException e) {
            // success
        }

        NodeTypeTemplate[] ntds = new NodeTypeTemplate[2];
        ntds[0] = ntd;
        ntds[1] = ntm.createNodeTypeTemplate();
        ntds[1].setName("anotherNodeType");
        ntds[1].setDeclaredSuperTypeNames(new String[] {"nt:file"});
        try {
            ntm.registerNodeTypes(ntds, true);
            fail("Node type registration should be denied.");
        } catch (AccessDeniedException e) {
            // success
        }

        try {
            ntm.registerNodeTypes(ntds, false);
            fail("Node type registration should be denied.");
        } catch (AccessDeniedException e) {
            // success
        }
    }
View Full Code Here

    @Test
    public void testRegisterNodeTypeWithPrivilege() throws Exception {
        modify(null, JCR_NODE_TYPE_DEFINITION_MANAGEMENT.toString(), true);
        try {
            Workspace testWsp = testSession.getWorkspace();
            NodeTypeManager ntm = testWsp.getNodeTypeManager();
            NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
            ntd.setName("testNodeType");
            ntd.setMixin(true);
            ntm.registerNodeType(ntd, true);

            NodeTypeTemplate[] ntds = new NodeTypeTemplate[2];
            ntds[0] = ntd;
            ntds[1] = ntm.createNodeTypeTemplate();
            ntds[1].setName("anotherNodeType");
            ntds[1].setDeclaredSuperTypeNames(new String[] {"nt:file"});
            ntm.registerNodeTypes(ntds, true);
        } finally {
            modify(null, JCR_NODE_TYPE_DEFINITION_MANAGEMENT.toString(), false);
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testUnRegisterNodeType() throws Exception {
        NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
        NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
        ntd.setName("testNodeType");
        ntd.setMixin(true);
        ntm.registerNodeType(ntd, true);

        Workspace testWsp = testSession.getWorkspace();
        try {
            try {
                NodeTypeManager testNtm = testWsp.getNodeTypeManager();
                testNtm.unregisterNodeType(ntd.getName());
                fail("Node type unregistration should be denied.");
            } catch (AccessDeniedException e) {
                // success
            }
            try {
                NodeTypeManager testNtm = testWsp.getNodeTypeManager();
                testNtm.unregisterNodeTypes(new String[] {ntd.getName()});
                fail("Node type unregistration should be denied.");
            } catch (AccessDeniedException e) {
                // success
            }
        } finally {
View Full Code Here

            @Override
            public NodeType[] perform() throws RepositoryException {
                // TODO: avoid nested calls
                // TODO: check if transient changes to mixin-types are reflected here
                if (hasProperty(Property.JCR_MIXIN_TYPES)) {
                    NodeTypeManager ntMgr = getNodeTypeManager();
                    Value[] mixinNames = getProperty(Property.JCR_MIXIN_TYPES).getValues();
                    NodeType[] mixinTypes = new NodeType[mixinNames.length];
                    for (int i = 0; i < mixinNames.length; i++) {
                        mixinTypes[i] = ntMgr.getNodeType(mixinNames[i].getString());
                    }
                    return mixinTypes;
                } else {
                    return new NodeType[0];
                }
View Full Code Here

        }
    }

    @Test
    public void nodeTypeRegistry() throws RepositoryException {
        NodeTypeManager ntMgr = getAdminSession().getWorkspace().getNodeTypeManager();
        assertFalse(ntMgr.hasNodeType("foo"));

        NodeTypeTemplate ntd = ntMgr.createNodeTypeTemplate();
        ntd.setName("foo");
        ntMgr.registerNodeType(ntd, false);
        assertTrue(ntMgr.hasNodeType("foo"));

        ntMgr.unregisterNodeType("foo");
        assertFalse(ntMgr.hasNodeType("foo"));
    }
View Full Code Here

    }

    @Test  // Regression test for OAK-299
    public void importNodeType() throws RepositoryException, IOException, ParseException {
        Session session = getAdminSession();
        NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
        if (!manager.hasNodeType("myNodeType")) {
            StringBuilder defs = new StringBuilder();
            defs.append("[\"myNodeType\"]\n");
            defs.append("  - prop1\n");
            defs.append("  + * (nt:base) = nt:unstructured \n");
            Reader cndReader = new InputStreamReader(new ByteArrayInputStream(defs.toString().getBytes()));
            CndImporter.registerNodeTypes(cndReader, session);
        }

        NodeType myNodeType = manager.getNodeType("myNodeType");
        assertTrue(myNodeType.isNodeType("nt:base"));
    }
View Full Code Here

TOP

Related Classes of javax.jcr.nodetype.NodeTypeManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.