jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jukka Zitting" <jukka.zitt...@gmail.com>
Subject Re: Beginner cnd question
Date Sun, 20 May 2007 07:59:39 GMT

On 5/20/07, Phillip Rhodes <spamsucks@rhoderunner.com> wrote:
> At this point, whenever I do try to add a node, it errors out with a
> "no matching child node definition found for {}Tag 0"
> I figured out that I can add the node successfully if I specify a node
> name that matches what I specify in the cnd (by using "stitches:tags"
> instead of "Tag 0" as the node name), but is there a way to specify
> the node name dynamically?  I want to specify that I am adding a
> node with this name, and with this type to this node.

You can use a residual child node definition. Like this:

    <nt = 'http://www.jcp.org/jcr/nt/1.0'>
    <stitches = 'http://stitches.authsum.com/stitches'>

    /* This is a simple tag */
    [stitches:tag] > nt:resource

    /* the stitch folder extends the nt:folder */
    [stitches:folder] > nt:folder
    - stitches:contentType (string)
    + * (stitches:tag)

Another alternative, since you're already using the standard nt:folder
and nt:resource types, would be to use a subfolder and normal nt:files
for the tags. The code is a bit more complicated, but gives you a
perfect mapping for things like the WebDAV interface, which would
allow you to modify tags with a normal WebDAV-enabled file explorer.

Adding a new folder with a tag:

    Node root = session.getRootNode();
    Node folder = root.addNode("a folder", "stitches:folder");
    Node tags = folder.addNode("stiches:tags", "nt:folder");
    Node file = tags.addNode("Tag 0", "nt:file");
    Node tag = file.addNode("jcr:content", "stiches:tag");

Adding a tag to an existing folder:

    Node root = session.getRootNode();
    Node file = root.addNode("a folder/stiches:tags/Tag 1", "nt:file");
    Node tag = file.addNode("jcr:content", "stiches:tag");


Jukka Zitting

View raw message