1
votes

I’m working with a CMS and using the Jackrabbit implementation of the JCR Session interface to import content. The CMS itself is Hippo (now Bloomreach). Using the Hippo console I am able to export a node and its children to an XML file. The file itself is well-formed XML and when I use the console to re-import the nodes specified in the XML it works fine.

For proof of concept I used the following code to ensure that my use of the Session interface was working, and this successfully imported the XML I had exported

Node node = cmsSession.getNode(path);
node.addNode("test", "nt:unstructured");
return cmsSession.importContent(image, path + "/test");

As you can see, I’ve simply created an unstructured node named “test” at a given location in the CMS (specified by the contents of the “path” variable). This code successfully imports the XML file to the “test” node.

The issue I’m having is when I specify a different location to import. The exported XML was exported from a Hippo handle node containing image nodes and image data. I’m using the following code to create the handle node

public Node createHandle(Node basedir, String handleName) throws CMSException {
    try {
        Node handleNode = basedir.addNode(handleName,”hippo:handle”);
        handleNode = addMixins(handleNode,”hippo:named, mix:referenceable”);
        return handleNode;
    } catch (RepositoryException e) {
        //handling
    }
}

Then this is my code that calls the importXML method. By this stage I’ve converted the contents of the XML file I want to import into a byte array

@Override
public boolean importContent(byte[] content, String cmsPathToImportInto) throws JCRSessionException {
    validateSession();

    try {
        ByteArrayInputStream inputStream = new ByteArrayInputStream(content);
        session.importXML(cmsPathToImportInto, inputStream, IMPORT_UUID_COLLISION_REMOVE_EXISTING);
        inputStream.close();
        session.save();
        return true;
    } catch (RepositoryException e) {
        e.printStackTrace();
//handling
    } catch (IOException e) {
        log.error("Unable to read from byte array");
        return false;
    }
}

The resulting error is

javax.jcr.nodetype.ConstraintViolationException: No child node definition for <my node name> found in node <the path and node that I want to import to> at org.apache.jackrabbit.rmi.server.ServerObject.getRepositoryException(ServerObject.java:109) at org.apache.jackrabbit.rmi.server.ServerSession.importXML(ServerSession.java:295)

It seems to be that no child nodes are set for the handle node when I create it but I’m unsure what properties govern the creation of child nodes.

Any help is appreciated

1

1 Answers

0
votes

In the end, I was unable to find a way to resolve the immediate problem. I was able to find a workaround by creating a temporary, unstructured node to initially import the XML, then moving the contents of that node to the desired location using the session.move() method