How to configure custom node definitions in Apache Jackrabbit?

Is there a way to configure custom node types for Apache Jackrabbit to register when creating a new repository?

I will automate my build using Apache Maven and run some unit tests with JUnit and integration tests to work with Jetty and you want to be able to easily install and reset the test repository.

+4
source share
5 answers

If you can upgrade to the recently released Jackrabbit 2.0.0, you can programmatically create and register nodetypes. The main hook is the JSR-283 NodeTypeManager , which doubles as a factory for new NodeTypes and a place to register them. Just register them in the setup method of your JUnit tests, and you should be good to go.

+7
source

I suggest that you define your nodetypes using a CND file and configure your JUnit test cases to register them for you, as in this example . I would say that the most appropriate way to do this is to define an abstract test case that performs this configuration.

Also note that node types are associated with the workspace, and not with the entire repository.

+5
source

According to NodeTypeManager , this is sample code for creating a node type:

import javax.jcr.PropertyType; import javax.jcr.Session; import javax.jcr.nodetype.NodeType; import javax.jcr.nodetype.NodeTypeManager; import javax.jcr.nodetype.NodeTypeTemplate; import javax.jcr.nodetype.PropertyDefinitionTemplate; /** * * @author Aroniaina */ public class FileType { public static void RegisterFileType(Session session) throws Exception { NodeTypeManager nodeTypeManager = session.getWorkspace().getNodeTypeManager(); NodeTypeTemplate nodeType = nodeTypeManager.createNodeTypeTemplate(); nodeType.setName("FileType"); String[] str = {"nt:resource"}; nodeType.setDeclaredSuperTypeNames(str); nodeType.setMixin(false); nodeType.setQueryable(true); PropertyDefinitionTemplate path = nodeTypeManager.createPropertyDefinitionTemplate(); path.setName("jcr:path"); path.setRequiredType(PropertyType.PATH); path.setQueryOrderable(false); path.setFullTextSearchable(false); nodeType.getPropertyDefinitionTemplates().add(path); PropertyDefinitionTemplate nom = nodeTypeManager.createPropertyDefinitionTemplate(); nom.setName("jcr:nom"); nom.setRequiredType(PropertyType.STRING); nom.setQueryOrderable(true); nom.setFullTextSearchable(true); nodeType.getPropertyDefinitionTemplates().add(nom); PropertyDefinitionTemplate description = nodeTypeManager.createPropertyDefinitionTemplate(); description.setName("jcr:description"); description.setRequiredType(PropertyType.STRING); description.setQueryOrderable(true); description.setFullTextSearchable(true); nodeType.getPropertyDefinitionTemplates().add(description); PropertyDefinitionTemplate motsCles = nodeTypeManager.createPropertyDefinitionTemplate(); motsCles.setName("jcr:motsCles"); motsCles.setRequiredType(PropertyType.STRING); motsCles.setQueryOrderable(true); motsCles.setFullTextSearchable(true); nodeType.getPropertyDefinitionTemplates().add(motsCles); PropertyDefinitionTemplate size = nodeTypeManager.createPropertyDefinitionTemplate(); size.setName("jcr:size"); size.setRequiredType(PropertyType.STRING); size.setQueryOrderable(true); size.setFullTextSearchable(false); nodeType.getPropertyDefinitionTemplates().add(size); PropertyDefinitionTemplate users = nodeTypeManager.createPropertyDefinitionTemplate(); users.setName("jcr:users"); users.setRequiredType(PropertyType.STRING); users.setQueryOrderable(true); users.setFullTextSearchable(false); nodeType.getPropertyDefinitionTemplates().add(users); PropertyDefinitionTemplate groupe = nodeTypeManager.createPropertyDefinitionTemplate(); groupe.setName("jcr:groupe"); groupe.setRequiredType(PropertyType.STRING); groupe.setQueryOrderable(true); groupe.setFullTextSearchable(false); nodeType.getPropertyDefinitionTemplates().add(groupe); NodeType newnodetype = nodeTypeManager.registerNodeType(nodeType, true); session.save(); } } 
+2
source

You can see our code in Silverpeas . We use Apache Jackrabbit with some unit tests. This is currently a work in progress in my dev branch: https://github.com/ehsavoie/Silverpeas-Core/tree/feature_82 , which uses memory repository loading of CND files and testing with spring. Take a look at DocumentRepositoryTest for example

0
source

I'm not sure about nodetypes, but I read that apache sling has a way to specify the initial content when the package is installed (osgi package). Looks like what you mean.

-1
source

All Articles