Importing new nodes into Hippo CMS using Java and XML

Hi folks,

I’m working with Hippo CMS and am using Jackrabbit to manage the import and export of content. My CMS stores images under the following tree structure

/content/gallery/mycmsname/stuff/

I have two instances of this CMS - one in development hosted on a server and one local version. The structures of the two CMS’s are identical (i.e. that path is the same in both). In my development instance I have image content under a handle node at this location:

/content/gallery/mycmsname/stuff/thisismycontent.jpg

That “thisismycontent.jpg” is a node of type hippo:handle and it contains a node of the same name and of type “hippogallery:imageset”, which itself contains the image content. All in all, the nodes containing this content are as follows

/content/gallery/mycmsname/stuff/thisismycontent.jpg
/content/gallery/mycmsname/stuff/thisismycontent.jpg/thisismycontent.jpg
/content/gallery/mycmsname/stuff/thisismycontent.jpg/thisismycontent.jpg/hippogallery:thumbnail
/content/gallery/mycmsname/stuff/thisismycontent.jpg/thisismycontent.jpg/hippogallery:original

Using the Hippo CMS console, I right-click on the “thisismycontent.jpg” handle node and export it to an XML file from the development instance with the “Export XML” feature. I can then go to my local instance, right click on the “stuff” node and select “Import XML” where I then paste the XML of “thisismycontent.jpg”. It imports fine - a handle node “thisismycontent.jpg” and its children appear in the local instance.

The problem is that I’m unable to import to the “stuff” node using Java. I convert the XML content to a byte array and then feed it into a ByteArrayInputStream. I also make sure that the path that it’s being imported to is “/content/gallery/mycmsname/stuff/” but I get a PathNotFoundException error saying that no node called “thisismycontent.jpg” is found. If I do create than node manually and then change the import path to “/content/gallery/mycmsname/stuff/thisismycontent.jpg” I get a ConstraingViolationException saying that “No child node definition for thisismycontent.jpg is found in /content/gallery/mycmsname/stuff/thisismycontent.jpg”. I’m unsure a) why the import isn’t creating a node in the first case and b) how to define child nodes in the second case. Below is the Java code I’m using for import. Any help is appreciated

    public boolean importContent(byte[] content, String cmsPathToImportInto) {	

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

It is very difficult to export/import through pure JCR API for XM binaries (gallery imageset and file assets) and documents.
It’s probably easier to install/use Content-EXIM forge module instead. For references:

Regards,

Woonsan