This is a bit of code from my latest personal project that's using PHPCR
for it's storage backend. With Jackalope
you can keep using nt:unstructured
as your node type, but it makes a lot of sense to create custom node types when you are certain of what your data will look like. With a custom node type you are guaranteed that the structure of the node you're trying to store will be as defined and you don't have to worry about writing additional validation code yourself since the storage backend will take care of it for you.
This is where CND
files come in. A good way of thinking of a CND
file node definition is as if it is a table in a traditional relational database.
There is a node type notation
defined that provides the grammar for a CND
file. This format is very compact and easy to understand.
Here's an example node definition that has two properties and specifies that the parent node will have an unstructured child node. Notice that I define my own custom namespace here.
To register this definition, the NodeTypeManager
is used. This object is fetched from the workspace and a workspace comes from a session...
The above code assumes that a session has already been created. The CND
file is read into a string and passed to the NodeTypeManager
. That's all there is to it. Of course you would probably want to have multiple CND
The loading of registration of CND
files is a one time operation, once it's in your repository you can keep reusing the defined node types.
Hope you found this post useful...
...so please read on! I love writing articles that provide beneficial information,
tips and examples to my readers. All information on my blog is provided free of
charge and I encourage you to share it as you wish. There is a small favour I ask in return however -
engage in comments below, provide feedback, and if you see mistakes let me know.
If you want to show additional support and help me pay for web hosting and
domain name registration,
donations, no matter how small, are always welcome!
Use of any information contained in this blog post/article is subject to this disclaimer
Other posts you may like...