Search code examples
jcrjackrabbit

How to import system view XML directly under root in Jackrabbit?


I have a system view XML dump from a ModeShape (4.1) repository, that I try to import into Jackrabbit (2.8).

The root node of my XML contains a node with the name "jcr:root" (but I have commented out the "jcr:uuid" and "jcr:primaryType" ("mode:root") as Jackrabbit didn't seem to like these).

I import the XML using:

session.importXML("/", stream, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);

XML looks like (I've handtyped this, because I'm on a closed network, so disregard name spaces, they are ok :-):

<?xml version="1.0" encoding="UTF-8" ?>
<sv:node xmlns:jcr=".../jcr/1.0" xmlns:sv=".../sv/1.0" ... sv:name="jcr:root">
   <!-- jcr:uuid and jcr:primaryType properties commented out... -->
   <sv:node sv:name="Messages">
      ...
   </sv:node>
</sv:node>

Importing this into Jackrabbit works without any errors, however, the import creates a new node named "jcr:root" (containing "Messages") under the real repository root node, rather than placing the "Messages" node directly under the repository root node (as ModeShape does).

I.e., I get:

/jcr:root/Messages

Rather than what I expected:

/Messages

(I also tried setting with "jcr:uuid" matching that of the Jackrabbit repository, and IMPORT_UUID_COLLISION_REPLACE_EXISTING, but got an exception that the root node could not be replaced).

How can I correctly import this into Jackrabbit, directly under the root node?

UPDATE:

While reading up on the JCR spec, section 11.9, "Importing jcr:root", it seems neither Jackrabbit nor ModeShape does the right thing. Although I kind of like ModeShape's behaviour.

Jackrabbit seems to behave like the spec says for IMPORT_UUID_CREATE_NEW (and doesn't treat jcr:root specially). If I add the jcr:uuid property with the value of the current repository root node, it works as specified.

ModeShape just merges the root, and doesn't seem to care about the collision at all (which is actually reasonable, but not according to any of the behaviours defined in the spec).

...or am I wrong? :-)


Solution

  • An obvious solution that I should try, is to just move the "Messages" node to the root of the XML document.

    <?xml version="1.0" encoding="UTF-8" ?>
    <sv:node sv:name="Messages" xmlns...>
       ...
    </sv:node>
    

    (Unfortunately, I have multiple nodes under the root, so I'll need to create multiple XML exports. Not elegant, but probably doable).