This page provides an overview of all ways to define custom JCR node types and create new workspaces with Magnolia.
Even though it has always been possible to define node types and create workspaces within Magnolia Maven modules, the Content Types module brings this functionality also to the light modules. Both approaches are valid.
Whichever approach you choose, we recommend not to develop and refine these definitions in a productive environment.
Editing node type and workspace definitions can lead to new node type definitions and workspaces which are registered again, whereas the system keeps the "old" ones which become obsolete.
With content types
By utilizing the
magnolia-content-types module you can define custom JCR content types and workspaces within light modules.
Defining content types within light modules can be accomplished on a running Magnolia system without redeploying the WAR file of your Magnolia instances and without restarting the instance or a module. This makes it a perfect approach if you have a Magnolia Cloud subscription package.
A content type definition in one file
You can define all of the following in just one file:
- JCR workspace
- JCR nodetype
This node type inherits from the Magnolia node type
mgnl:content. To define more sophisticated node types, you can create a node type definition file in a light module.
- JCR namespace
Defining and using a node type definition
You can define JCR namespaces and nodetypes in a CND file.
The Compact Namespace and Node Type Definition (CND) notation provides a compact standardized syntax for defining node types and making namespace declarations. The notation is intended both for documentation and for programmatically registering node types. See http://jackrabbit.apache.org/jcr/node-type-notation.html for more details. While XML-based node type definitions are still supported, we recommend using CND.
While XML-based node type definitions are still supported, we recommend using CND.
Since this definition must be readable as a Magnolia Resource, it can be a file in a light module or in a JAR file or in the
resources JCR workspace.
Create a CND file in your light module and define a namespace and node types:
Reference the node type definition from a content type definition:Line 4: References the node type definition resource via
With a Magnolia Maven module descriptor
Magnolia registers workspaces and node types during a module's start-up phase in case they have not yet been registered.
Example of a module descriptor:
In the XML-based module descriptor you can add a
<workspace /> section in
To define and register new node types requires two things:
Creating a node type definition file (CND or XML) where you define the required node types and name spaces. Create the file in the
Referencing the node type file in the XML-based module descriptor: