JCR Import Export

1 Introduction

There are a number of use cases that XML Import/Export can satisfy.

Content Exchange

Allows the exchange of JCR content with other content consumers.

Archival Purposes

Many business and governmental organizations have strict legal requirements regarding the availability of content and information. XML Import/Export facilitates this with the help of the ability to periodically export a JCR or a subset of workspaces to a secure storage.

Application Import/Export

Applications often need to exchange data between systems in an application specific fashion, the JCR XML Import/Export specification allows the architecture to define adapters for content import and export as well as shipping default adapters for content. This is to facilitate integrators and developers utilizing the framework when developing their own application specific import/export adapters.

2 Export

Specification describes four methods for exporting. Two methods use “Document” and another two “System” view as interchange format (see JSR-170 for details).

  • Session.exportSystemView(String absPath, ContentHandler contentHandler, boolean skipBinary, boolean noRecurse)
  • Session.exportSystemView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse)
  • Session.exportDocumentView(String absPath, ContentHandler contentHandler, boolean skipBinary, boolean noRecurse)
  • Session.exportDocumentView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse)
In both cases the content can be exported using either SAX ContentHandler or OutputStream to the XML file.

The easiest way to export data looks like:

BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
session.exportSystemView(node.getPath(), bufferedOutputStream, false, false);
bufferedOutputStream.close();

The result of this operations is the XML file containing serialized node with all subnodes and properties.

3 Import

JSR-170 specifies four methods for content importing (two provided by Workspace interface and other two by Session):

  • Workspace.getImportContentHandler
  • Workspace.importXML
  • Session.getImportContentHandler
  • Session.importXML
The following sample shows how Session.importXML() method performs importing of the XML file content into Java Content Repository. Note: the JCR recognizes the format of the file and uses appropriate (Document or System) view import handler automatically:
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
    session.importXML(root.getPath(),
        bufferedInputStream,
        ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING);

The result of this call is the content of an xml file imported into the root node.

NOTE: Due to XML parser limitation, current implementation of Document view importer/exporter can not be applied to big streams to be imported to the repository or big values to be exported from, otherwise OutOfMemoryException occurs. For instance the maximum size of Document view which contains XML is ~30Mb for –XmX512 (JVM heap size of 512Mb).


Creator: Sergey Kabashnyuk on 06/15/2007
Copyright (c) 2000-2009. Allright reserved - eXo platform SAS
1.6.13286