Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

This is a bit of code from my latest personal project that's using PHPCR / Jackalope 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.
 location.cnd
<tb = 'http://travelblog.ws/ns'>
[tb:Location]
- tb:name (string) primary mandatory
- tb:arrivalDate (date) mandatory
+ tb:posts (nt:unstructured) mandatory autocreated


To register this definition, the NodeTypeManager is used. This object is fetched from the workspace and a workspace comes from a session...
 PHP
$workspace = $session->getWorkspace();
$nodeTypeManager = $workspace->getNodeTypeManager();
$nodeTypeManager->registerNodeTypesCnd(file_get_contents('location.cnd'), true);


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 files.

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.



-i

Please leave your comments or feedback below!
comments powered by Disqus
Other posts you may like...
Hi! You can search my blog here ⤵
Or browse the recent top tags...

Recent Blog Posts

Tiny Arcade revision 6 kit assembly and decal application

Jersey JAX-RS filters and interceptors execution order for a simple GET request

How to stop macOS adding shadows to window screenshots

How to run Atari Lynx games on the SNES Classic Mini

Maven dependency scopes with relation to WAR file packaging and the WEB-INF/lib directory

Hacking the Sonoff B1 WiFi LED bulb to run custom firmware

What does an idle WebLogic server run on the hour to cause a CPU spike

How to open the Sonoff B1 wifi LED bulb to access its internal circuitry

Australian release SNES mini classic unboxing and a quick play through

Troubleshooting high CPU usage for JVM threads

Recent Galleries

Atari Lynx repair - Part 5 - McWill LED screen mod installation

Atari Lynx repair - Part 4 - screen cover replacement

Atari Lynx repair - Part 2 - re-capping the motherboard

Atari Lynx repair - Part 3 - broken speaker replacement

Atari Lynx repair - Part 1 - introduction and case disassembly

Building a custom Atari Lynx game box storage shelf unit in a day

Protecting old Atari Lynx game boxes with snug fit plastic sleeves

Monument Valley 2 is released and does not disappoint

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

Blogs and Friends

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity