NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ
for more details.
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.
A quick disclaimer...
Although I put in a great effort into researching all the topics I cover, mistakes can happen.
If you spot something out of place, please do let me know.
All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle).
Use of any information contained in this blog post/article is subject to this disclaimer
Other posts you may like...