@Override public NodeTypeIterator registerNodeTypes( URL url, boolean allowUpdate ) throws IOException, RepositoryException { String content = IoUtil.read(url.openStream()); if (content.startsWith("<?xml")) { // This is Jackrabbit XML format ... return registerNodeTypes(importFromXml(new InputSource(new StringReader(content))), allowUpdate); } // Assume this is CND format ... CndImporter importer = new CndImporter(context()); Problems problems = new SimpleProblems(); importer.importFrom(content, problems, url.toExternalForm()); // Check for (and report) any problems ... if (problems.hasProblems()) { // There are errors and/or warnings, so report them ... String summary = messageFrom(problems); if (problems.hasErrors()) { String msg = JcrI18n.errorsParsingNodeTypeDefinitions.text(url.toExternalForm(), summary); throw new RepositoryException(msg); } // Otherwise, there are warnings, so log them ... I18n msg = JcrI18n.warningsParsingNodeTypeDefinitions; Logger.getLogger(getClass()).warn(msg, url.toExternalForm(), summary); } // Register the node types ... return registerNodeTypes(importer.getNodeTypeDefinitions(), allowUpdate); } }
protected final JcrNodeType nodeTypeFor( String name ) { return nodeTypes.getNodeType(nameFor(name)); }
/** * Unregisters the named node type if it is not referenced by other node types as a supertype, a default primary type of a * child node (or nodes), or a required primary type of a child node (or nodes). * * @param nodeTypeName * @throws NoSuchNodeTypeException if node type name does not correspond to a registered node type * @throws InvalidNodeTypeDefinitionException if the node type with the given name cannot be unregistered because it is the * supertype, one of the required primary types, or a default primary type of another node type * @throws AccessDeniedException if the current session does not have the {@link ModeShapePermissions#REGISTER_TYPE register * type permission}. * @throws RepositoryException if any other error occurs */ @Override public void unregisterNodeType( String nodeTypeName ) throws NoSuchNodeTypeException, InvalidNodeTypeDefinitionException, RepositoryException { unregisterNodeTypes(Collections.singleton(nodeTypeName)); }
/** * Returns the node type with the given name (if one exists) * * @param nodeTypeName the name of the node type to be returned * @return the node type with the given name (if one exists) * @see NodeTypes#getNodeType(Name) */ JcrNodeType getNodeType( Name nodeTypeName ) { JcrNodeType nodeType = nodeTypes().getNodeType(nodeTypeName); if (nodeType != null) { nodeType = nodeType.with(context(), session); } return nodeType; }
/** * {@inheritDoc} */ @Override protected void initNodeTypes(NodeTypeManager ntm) throws RepositoryException { JcrNodeTypeManager ntmi = (JcrNodeTypeManager) ntm; try { InputStream is = null; try { is = this.getClass().getResourceAsStream(DEFAULT_NODETYPE_FILE); ntmi.registerNodeTypes(is, true); } finally { if (is != null) { is.close(); } } } catch (IOException e) { throw new RepositoryException("Failed to init NodeTypes: " + e.getMessage(), e); } }
/** * Get the node definition given the supplied identifier. * * @param definitionId the identifier of the node definition * @return the node definition, or null if there is no such definition (or if the ID was null) */ JcrNodeDefinition getNodeDefinition( NodeDefinitionId definitionId ) { if (definitionId == null) return null; return nodeTypes().getChildNodeDefinition(definitionId); }
private boolean canAddNode( String primaryNodeTypeName ) throws RepositoryException { if (isLockedByAnotherSession()) { return false; } // Determine the name for the primary node type if (primaryNodeTypeName != null) { if (!session().nodeTypeManager().hasNodeType(primaryNodeTypeName)) return false; JcrNodeType nodeType = session().nodeTypeManager().getNodeType(primaryNodeTypeName); if (nodeType.isAbstract()) return false; if (nodeType.isMixin()) return false; if (INTERNAL_NODE_TYPE_NAMES.contains(nodeType.getInternalName())) return false; } return true; }
@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); }
CheckArg.isNotEmpty(primaryTypeName, "primaryTypeName"); NameFactory nameFactory = context().getValueFactories().getNameFactory(); Name[] typeNames = nameFactory.create(testTypeNames); JcrNodeType nodeType = getNodeType(typeName); for (String mixin : mixinNames) { for (Name typeName : typeNames) { JcrNodeType nodeType = getNodeType(typeName);
private void testRegisterType( Session session ) throws Exception { JcrNodeTypeManager nodeTypes = (JcrNodeTypeManager)session.getWorkspace().getNodeTypeManager(); NodeTypeTemplate newType = nodeTypes.createNodeTypeTemplate(); String nodeTypeName = session.getUserID() + "Type"; newType.setName(nodeTypeName); nodeTypes.registerNodeType(newType, false); nodeTypes.unregisterNodeTypes(Collections.singleton(nodeTypeName)); }
/** * Returns an empty {@code PropertyDefinitionTemplate} which can then be used to create a property definition and attached to * a {@code NodeTypeTemplate}. * * @return an empty {@code PropertyDefinitionTemplate} which can then be used to create a property definition and attached to * a {@code NodeTypeTemplate}. * @throws RepositoryException if another error occurs */ @Override public NodeDefinitionTemplate createNodeDefinitionTemplate() throws RepositoryException { return new JcrNodeDefinitionTemplate(context()); }
@Test public void shouldReturnTrueForHasNodeTypeWithExistingNodeTypeName() throws Exception { assertTrue(nodeTypeMgr.hasNodeType("nt:base")); assertTrue(nodeTypeMgr.hasNodeType(HIERARCHY_NODE_TYPE)); assertTrue(nodeTypeMgr.hasNodeType(MIXIN1)); }
@Override public JcrNodeDefinition getDefinition() throws RepositoryException { return session.workspace().nodeTypeManager().getRootNodeDefinition(); }
final JcrNodeTypeManager nodeTypeManager() { if (nodeTypeManager == null) { try { lock.lock(); if (nodeTypeManager == null) { nodeTypeManager = new JcrNodeTypeManager(session, repository().nodeTypeManager()); } } finally { lock.unlock(); } } return nodeTypeManager; }
@Test @FixFor( "MODE-1807" ) public void shouldAllowOverridingChildDefinitionWithSubtypeOfOriginalDefinition() throws Exception { InputStream cndStream = getClass().getResourceAsStream("/cnd/orc.cnd"); assertThat(cndStream, is(notNullValue())); nodeTypeManager().registerNodeTypes(cndStream, true); }
/** * Returns the node type with the given name (if one exists) * * @param nodeTypeName the name of the node type to be returned * @return the node type with the given name (if one exists) * @see NodeTypes#getNodeType(Name) */ JcrNodeType getNodeType( Name nodeTypeName ) { JcrNodeType nodeType = nodeTypes().getNodeType(nodeTypeName); if (nodeType != null) { nodeType = nodeType.with(context(), session); } return nodeType; }
/** * Get the property definition given the supplied identifier. * * @param definitionId the identifier of the node definition * @return the property definition, or null if there is no such definition (or if the ID was null) */ JcrPropertyDefinition getPropertyDefinition( PropertyDefinitionId definitionId ) { if (definitionId == null) return null; return nodeTypes().getPropertyDefinition(definitionId); }
private boolean canAddNode( String primaryNodeTypeName ) throws RepositoryException { if (isLockedByAnotherSession()) { return false; } // Determine the name for the primary node type if (primaryNodeTypeName != null) { if (!session().nodeTypeManager().hasNodeType(primaryNodeTypeName)) return false; JcrNodeType nodeType = session().nodeTypeManager().getNodeType(primaryNodeTypeName); if (nodeType.isAbstract()) return false; if (nodeType.isMixin()) return false; if (INTERNAL_NODE_TYPE_NAMES.contains(nodeType.getInternalName())) return false; } return true; }
CheckArg.isNotEmpty(primaryTypeName, "primaryTypeName"); NameFactory nameFactory = context().getValueFactories().getNameFactory(); Name[] typeNames = nameFactory.create(testTypeNames); JcrNodeType nodeType = getNodeType(typeName); for (String mixin : mixinNames) { for (Name typeName : typeNames) { JcrNodeType nodeType = getNodeType(typeName);
/** * Returns an empty {@code NodeTypeTemplate} which can then be used to define a node type and passed to * {@link JcrNodeTypeManager#registerNodeType(NodeTypeDefinition, boolean)} * * @return an empty {@code NodeTypeTemplate} which can then be used to define a node type and passed to * {@link JcrNodeTypeManager#registerNodeType(NodeTypeDefinition, boolean)}. * @throws RepositoryException if another error occurs */ @Override public NodeTypeTemplate createNodeTypeTemplate() throws RepositoryException { return new JcrNodeTypeTemplate(context()); }