/** * Create a new node type factory that reads the node types from Jackrabbit XML files. * * @param session the session that will be used to register the node types; may not be null * @throws RepositoryException if there is a problem */ XmlNodeTypeReader( JcrSession session ) throws RepositoryException { this.session = session; this.nodeTypeManager = session.getWorkspace().getNodeTypeManager(); this.namespaces = this.session.getWorkspace().getNamespaceRegistry(); CharHandler supertypeHandler = new SupertypeNameHandler(); CharHandler requiredPrimaryTypeHandler = new RequiredPrimaryTypeHandler(); CharHandler defaultHandler = new DefaultValueHandler(); CharHandler constraintHandler = new ConstraintHandler(); this.charHandlers.put(SUPERTYPES, supertypeHandler); this.charHandlers.put(REQUIRED_PRIMARY_TYPES, requiredPrimaryTypeHandler); this.charHandlers.put(DEFAULT_VALUES, defaultHandler); this.charHandlers.put(VALUE_CONSTRAINTS, constraintHandler); this.charHandlers.put(SUPERTYPE, supertypeHandler); this.charHandlers.put(REQUIRED_PRIMARY_TYPE, requiredPrimaryTypeHandler); this.charHandlers.put(DEFAULT_VALUE, defaultHandler); this.charHandlers.put(VALUE_CONSTRAINT, constraintHandler); }
/** * Create a new node type factory that reads the node types from Jackrabbit XML files. * * @param session the session that will be used to register the node types; may not be null * @throws RepositoryException if there is a problem */ XmlNodeTypeReader( JcrSession session ) throws RepositoryException { this.session = session; this.nodeTypeManager = session.getWorkspace().getNodeTypeManager(); this.namespaces = this.session.getWorkspace().getNamespaceRegistry(); CharHandler supertypeHandler = new SupertypeNameHandler(); CharHandler requiredPrimaryTypeHandler = new RequiredPrimaryTypeHandler(); CharHandler defaultHandler = new DefaultValueHandler(); CharHandler constraintHandler = new ConstraintHandler(); this.charHandlers.put(SUPERTYPES, supertypeHandler); this.charHandlers.put(REQUIRED_PRIMARY_TYPES, requiredPrimaryTypeHandler); this.charHandlers.put(DEFAULT_VALUES, defaultHandler); this.charHandlers.put(VALUE_CONSTRAINTS, constraintHandler); this.charHandlers.put(SUPERTYPE, supertypeHandler); this.charHandlers.put(REQUIRED_PRIMARY_TYPE, requiredPrimaryTypeHandler); this.charHandlers.put(DEFAULT_VALUE, defaultHandler); this.charHandlers.put(VALUE_CONSTRAINT, constraintHandler); }
protected void assertNoRepositoryNamespace( String uri, String prefix ) throws RepositoryException { NamespaceRegistry registry = session.getWorkspace().getNamespaceRegistry(); for (String existingPrefix : registry.getPrefixes()) { assertThat(existingPrefix.equals(prefix), is(false)); } for (String existingUri : registry.getURIs()) { assertThat(existingUri.equals(uri), is(false)); } }
@Test public void shouldProvideNamespaceRegistry() throws Exception { NamespaceRegistry registry = workspace.getNamespaceRegistry(); assertThat(registry, is(notNullValue())); assertThat(registry.getURI(JcrLexicon.Namespace.PREFIX), is(JcrLexicon.Namespace.URI)); }
@Override @Before public void beforeEach() throws Exception { super.beforeEach(); registry = session.getWorkspace().getNamespaceRegistry(); }
@Override @Before public void beforeEach() throws Exception { super.beforeEach(); session.getWorkspace().getNamespaceRegistry().registerNamespace(TestLexicon.Namespace.PREFIX, TestLexicon.Namespace.URI); }
@Test @FixFor("MODE-1965") public void shouldNotAllowRegistrationOfMixinThatInheritsNonMixin() throws Exception { session.getWorkspace().getNamespaceRegistry().registerNamespace("test", "http://myexample.com/test"); String mixinName = "test:mixin"; try { registerMixin(mixinName, "nt:unstructured"); fail("Should not allow registration of mixin that inherits non-mixin"); } catch (RepositoryException e) { // expected } }
@BeforeClass public static final void beforeAll() throws Exception { MultiUseAbstractTest.beforeAll(); // Import the node types ... session.getWorkspace().getNamespaceRegistry().registerNamespace(TestLexicon.Namespace.PREFIX, TestLexicon.Namespace.URI); registerNodeTypes(getTestTypes()); // Create some initial content ... Node nodeA = session.getRootNode().addNode("a"); Node nodeB = nodeA.addNode("b"); Node nodeC = nodeB.addNode("c"); assertThat(nodeC, is(notNullValue())); nodeA.addMixin("mix:referenceable"); session.save(); }
@Test @FixFor("MODE-1965") public void shouldNotAllowRegistrationOfMixinThatInheritsBothNonMixinAndMixin() throws Exception { session.getWorkspace().getNamespaceRegistry().registerNamespace("test", "http://myexample.com/test"); registerMixin("test:mixinParent"); try { registerMixin("test:mixinChild", "test:mixinParent", "nt:base"); fail("Should not allow registration of mixin that inherits non-mixin"); } catch (RepositoryException e) { // expected } }
@FixFor("MODE-1795") @Test public void shouldBeAbleToImportXmlFileThatUsesDefaultNamespaceWithNonBlankUri() throws Exception { session.importXML("/", resourceStream("io/simple-document-view-with-default-namespace.xml"), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); // Get the prefix for the namespace used in the imported file ... String prefix = session.getWorkspace().getNamespaceRegistry().getPrefix("http://www.ns.com"); assertNode("/" + prefix + ":childNode", "nt:unstructured"); }
@Test @FixFor("MODE-1963") public void shouldAllowReRegistrationOfMixinViaTemplate() throws Exception { session.getWorkspace().getNamespaceRegistry().registerNamespace("dmsmix", "http://myexample.com/dms"); String mixinName = "dmsmix:test"; registerMixin(mixinName); nodeTypeMgr.unregisterNodeType(mixinName); registerMixin(mixinName); }
@FixFor( "MODE-1408" ) @Test public void shouldReceiveEventsForChangesToRepositoryNamespacesInSystemContent() throws Exception { String uri = "http://acme.com/example/foobar/"; String prefix = "foobar"; assertNoRepositoryNamespace(uri, prefix); Session session2 = login(WORKSPACE2); SimpleListener listener = addListener(session, 4, ALL_EVENTS, "/jcr:system", true, null, null, false); SimpleListener listener2 = addListener(session2, 4, ALL_EVENTS, "/jcr:system", true, null, null, false); session.getWorkspace().getNamespaceRegistry().registerNamespace(prefix, uri); // Wait for the events on the session's listeners (that should get the events) ... listener.waitForEvents(); listener2.waitForEvents(); removeListener(listener); removeListener(listener2); assertThat(session.getWorkspace().getNamespaceRegistry().getPrefix(uri), is(prefix)); assertThat(session.getWorkspace().getNamespaceRegistry().getURI(prefix), is(uri)); // Verify the expected events were received ... checkResults(listener); checkResults(listener2); }
@SuppressWarnings("unchecked") @Test @FixFor("MODE-1954") public void shouldRemovePropertyDefinitionViaTemplate() throws Exception { session.getWorkspace().getNamespaceRegistry().registerNamespace("dmsmix", "http://myexample.com/dms"); NodeTypeTemplate fileContent = nodeTypeMgr.createNodeTypeTemplate(); fileContent.setName("dmsmix:filecontent"); nodeTypeMgr.registerNodeType(fileContent, true); NodeType nodeType = nodeTypeMgr.getNodeType("dmsmix:filecontent"); NodeTypeTemplate nodeTypeTemplate = nodeTypeMgr.createNodeTypeTemplate(nodeType); PropertyDefinitionTemplate tp = nodeTypeMgr.createPropertyDefinitionTemplate(); tp.setName("dmsmix:owner"); nodeTypeTemplate.getPropertyDefinitionTemplates().add(tp); nodeTypeMgr.registerNodeType(nodeTypeTemplate, true); nodeType = nodeTypeMgr.getNodeType("dmsmix:filecontent"); nodeTypeTemplate = nodeTypeMgr.createNodeTypeTemplate(nodeType); List<PropertyDefinitionTemplate> pts = nodeTypeTemplate.getPropertyDefinitionTemplates(); Iterator<PropertyDefinitionTemplate> pit = pts.iterator(); while (pit.hasNext()) { PropertyDefinitionTemplate pi = pit.next(); if (pi.getName().equals("dmsmix:owner")) { pit.remove(); } } nodeTypeMgr.registerNodeType(nodeTypeTemplate, true); }
@SuppressWarnings( "deprecation" ) @Test public void shouldBeAbleToExecuteXPathQueryWithNewlyRegisteredNamespace() throws RepositoryException { NamespaceRegistry namespaceRegistry = session.getWorkspace().getNamespaceRegistry(); namespaceRegistry.registerNamespace("newPrefix", "newUri"); try { // We don't have any elements that use this yet, but let's at least verify that it can execute. Query query = session.getWorkspace().getQueryManager() .createQuery("//*[@newPrefix:someColumn = 'someValue']", Query.XPATH); query.execute(); } finally { namespaceRegistry.unregisterNamespace("newPrefix"); } }
@Test @FixFor( "MODE-2149" ) @SuppressWarnings("unchecked") public void shouldValidateConstraintValue() throws Exception { String namespaceName = "admb"; String namespaceUri = "http://www.admb.be/modeshape/admb/1.0"; String nodeTypeName = "test"; session.getWorkspace().getNamespaceRegistry().registerNamespace(namespaceName, namespaceUri); NodeTypeTemplate nodeTypeTemplate = nodeTypeMgr.createNodeTypeTemplate(); nodeTypeTemplate.setPrimaryItemName("test"); String primaryType = namespaceName.concat(":").concat(nodeTypeName); nodeTypeTemplate.setName(primaryType); PropertyDefinitionTemplate propertyDefinition = nodeTypeMgr.createPropertyDefinitionTemplate(); propertyDefinition.setName("test"); propertyDefinition.setRequiredType(PropertyType.LONG); propertyDefinition.setMandatory(true); propertyDefinition.setValueConstraints(new String[] { "test" }); nodeTypeTemplate.getPropertyDefinitionTemplates().add(propertyDefinition); try { nodeTypeMgr.registerNodeType(nodeTypeTemplate, false); fail("Should not allow the registration of a node type with invalid constraint"); } catch (ValueFormatException e) { //expected } }
String nodeTypeName = "test"; session.getWorkspace().getNamespaceRegistry().registerNamespace(namespaceName, namespaceUri);
@Test @FixFor( "MODE-1687" ) public void shouldRegisterBothUsedAndUnusedNamespacesFromCNDFile() throws Exception { startRepositoryWithConfigurationFrom("config/repo-config-node-types.json"); NamespaceRegistry namespaceRegistry = session.getWorkspace().getNamespaceRegistry(); assertEquals("http://www.modeshape.org/examples/cars/1.0", namespaceRegistry.getURI("car")); assertEquals("http://www.modeshape.org/examples/aircraft/1.0", namespaceRegistry.getURI("air")); assertEquals("http://www.test1.com", namespaceRegistry.getURI("test1")); assertEquals("http://www.test2.com", namespaceRegistry.getURI("test2")); }
this.jcrNamespaceRegistry = (org.modeshape.jcr.api.NamespaceRegistry)session.workspace().getNamespaceRegistry();
this.jcrNamespaceRegistry = (org.modeshape.jcr.api.NamespaceRegistry)session.workspace().getNamespaceRegistry();
public void beforeEach() throws Exception { super.beforeEach(); session.getWorkspace().getNamespaceRegistry().registerNamespace("acme", "http://example.com"); dateFactory = session.dateFactory();