Igor's Blog

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

, , ,
About — I'm an enthusiastic software engineer and consultant interested in many fields including J2EE, programming, electronics, 3D printing, video games, wood working and gardening.
See my Resume for more information.
The views expressed in this blog are my own and not those of my employer.
comments powered by Disqus
My other posts you may like...
Programming, DIY, Games, Hacks, Tech and more.
Follow me on...
Current and Past Projects
See my Resume

Subscribe


RSS Feed

My Other Web Sites

Igor and Elise's Travels
Riverside Expressway Cam
StrFunc() Online
300 George St Blogumentary
Guru JSON-RPC Tester
Extrudifier Object Designer

Recent Blog Posts

Binding extra variables with PHP PDO returns no results

New Nintendo 3DS XL, R4i SDHC RTS Lite and DSDoom

Older versions of JD-GUI crashing on macOS Sierra

How does Seeed Fusion stack up as a low budget PCB fab

Where to find the last item (Robbie's lost lyrics) in GravityFalls Lake level

Detecting print requests to print contents of a DIV with JavaScript

Using Google DFP with AdSense on responsive pages

How to change the email subject line in Gmail

Force PHP GD library to load JPEG images that have invalid data

How to uninstall Samsung Smart Switch from your Mac

Recent Galleries

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

DIY spare parts computer build with a RAIDMAX Anura case

Fake 'Lepin' brand Lego packaging

Hardwood garden bench with clear resin void filler

Fixing a 3D printer extruder that stopped heating up

Easily increase disk space in a Lenovo Ideapad 100S 14" laptop with an M.2 SSD

Making a multi-piece 3D printed solder spool holder stand

DIY indoor apartment grow light wiring

Good Friday Electronics fun Easter Bunny LED PCB Kit IBEABU-01.0

Top Categories

Blogs I follow

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth

Friends

RAWS Parts Online
Alpha Dimensions Hosting
Kristensen Photography
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Follow me on... 
     
...or subscribe for updates!

Don't show this again