info.magnolia.importexport
Class DataTransporter

java.lang.Object
  extended by info.magnolia.importexport.DataTransporter
Direct Known Subclasses:
DataTransporter

public class DataTransporter
extends java.lang.Object

Utility class for manipulation of XML files (mainly JCR XML).

Author:
Nicolas Modrzyk, Oliver Lietz

Field Summary
static java.lang.String DOT
           
static java.lang.String GZ
           
static java.lang.String JCR_ROOT
           
static java.lang.String PROPERTIES
           
static java.lang.String SLASH
           
static java.lang.String UTF8
           
static java.lang.String XML
           
static java.lang.String ZIP
           
 
Constructor Summary
DataTransporter()
           
 
Method Summary
static java.lang.String decodePath(java.lang.String path, java.lang.String enc)
          decode a path (ex.
static java.lang.String encodePath(java.lang.String path, java.lang.String separator, java.lang.String enc)
           
static void executeBootstrapImport(java.io.File xmlFile, java.lang.String repositoryName)
           
static void executeExport(java.io.OutputStream baseOutputStream, boolean keepVersionHistory, boolean format, javax.jcr.Session session, java.lang.String basepath, java.lang.String repository, java.lang.String ext)
           
protected static java.io.InputStream getXslStreamForXmlFile(java.io.File file)
           
static void importDocument(Document xmlDocument, java.lang.String repositoryName, java.lang.String basepath, boolean keepVersionHistory, int importMode, boolean saveAfterImport, boolean createBasepathIfNotExist)
          Converts a xml document into a file.
static void importFile(java.io.File xmlFile, java.lang.String repositoryName, java.lang.String basepath, boolean keepVersionHistory, int importMode, boolean saveAfterImport, boolean createBasepathIfNotExist)
          Creates an InputStream backed by the specified xml file.
static void importProperties(java.util.Properties properties, java.lang.String repositoryName)
          Deprecated. since 4.0 - use the PropertiesImportExport class instead.
static void importXmlStream(java.io.InputStream xmlStream, java.lang.String repositoryName, java.lang.String basepath, java.lang.String name, boolean keepVersionHistory, int importMode, boolean saveAfterImport, boolean createBasepathIfNotExist)
          Imports XML stream into repository.
static void parseAndFormat(java.io.OutputStream stream, org.xml.sax.XMLReader reader, java.lang.String repository, java.lang.String basepath, javax.jcr.Session session, boolean noRecurse)
          Exports the content of the repository, and format it if necessary.
protected static void readFormatted(org.xml.sax.XMLReader reader, java.io.File inputFile, java.io.OutputStream outputStream)
           
protected static void readFormatted(org.xml.sax.XMLReader reader, java.io.InputStream inputStream, java.io.OutputStream outputStream)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZIP

public static final java.lang.String ZIP
See Also:
Constant Field Values

GZ

public static final java.lang.String GZ
See Also:
Constant Field Values

XML

public static final java.lang.String XML
See Also:
Constant Field Values

PROPERTIES

public static final java.lang.String PROPERTIES
See Also:
Constant Field Values

DOT

public static final java.lang.String DOT
See Also:
Constant Field Values

SLASH

public static final java.lang.String SLASH
See Also:
Constant Field Values

UTF8

public static final java.lang.String UTF8
See Also:
Constant Field Values

JCR_ROOT

public static final java.lang.String JCR_ROOT
See Also:
Constant Field Values
Constructor Detail

DataTransporter

public DataTransporter()
Method Detail

importDocument

public static void importDocument(Document xmlDocument,
                                  java.lang.String repositoryName,
                                  java.lang.String basepath,
                                  boolean keepVersionHistory,
                                  int importMode,
                                  boolean saveAfterImport,
                                  boolean createBasepathIfNotExist)
                           throws java.io.IOException
Converts a xml document into a file.

Parameters:
xmlDocument - uploaded file
repositoryName - selected repository
basepath - base path in repository
keepVersionHistory - if false version info will be stripped before importing the document
importMode - a valid value for ImportUUIDBehavior
saveAfterImport -
createBasepathIfNotExist -
Throws:
java.io.IOException
See Also:
ImportUUIDBehavior

importFile

public static void importFile(java.io.File xmlFile,
                              java.lang.String repositoryName,
                              java.lang.String basepath,
                              boolean keepVersionHistory,
                              int importMode,
                              boolean saveAfterImport,
                              boolean createBasepathIfNotExist)
                       throws java.io.IOException
Creates an InputStream backed by the specified xml file.

Parameters:
xmlFile - (zipped/gzipped) XML file to import
repositoryName - selected repository
basepath - base path in repository
keepVersionHistory - if false version info will be stripped before importing the document
importMode - a valid value for ImportUUIDBehavior
saveAfterImport -
createBasepathIfNotExist -
Throws:
java.io.IOException
See Also:
ImportUUIDBehavior

executeBootstrapImport

public static void executeBootstrapImport(java.io.File xmlFile,
                                          java.lang.String repositoryName)
                                   throws java.io.IOException
Parameters:
xmlFile -
repositoryName -
Throws:
java.io.IOException

importProperties

public static void importProperties(java.util.Properties properties,
                                    java.lang.String repositoryName)
Deprecated. since 4.0 - use the PropertiesImportExport class instead.

Deprecated.

Parameters:
properties -
repositoryName -

importXmlStream

public static void importXmlStream(java.io.InputStream xmlStream,
                                   java.lang.String repositoryName,
                                   java.lang.String basepath,
                                   java.lang.String name,
                                   boolean keepVersionHistory,
                                   int importMode,
                                   boolean saveAfterImport,
                                   boolean createBasepathIfNotExist)
                            throws java.io.IOException
Imports XML stream into repository. XML is filtered by MagnoliaV2Filter, VersionFilter and ImportXmlRootFilter if keepVersionHistory is set to false

Parameters:
xmlStream - XML stream to import
repositoryName - selected repository
basepath - base path in repository
name - (absolute path of File)
keepVersionHistory - if false version info will be stripped before importing the document
importMode - a valid value for ImportUUIDBehavior
saveAfterImport -
createBasepathIfNotExist -
Throws:
java.io.IOException
See Also:
ImportUUIDBehavior, ImportXmlRootFilter, VersionFilter, MagnoliaV2Filter

getXslStreamForXmlFile

protected static java.io.InputStream getXslStreamForXmlFile(java.io.File file)
Parameters:
file -
Returns:
XSL stream for Xml file or null

executeExport

public static void executeExport(java.io.OutputStream baseOutputStream,
                                 boolean keepVersionHistory,
                                 boolean format,
                                 javax.jcr.Session session,
                                 java.lang.String basepath,
                                 java.lang.String repository,
                                 java.lang.String ext)
                          throws java.io.IOException
Throws:
java.io.IOException

parseAndFormat

public static void parseAndFormat(java.io.OutputStream stream,
                                  org.xml.sax.XMLReader reader,
                                  java.lang.String repository,
                                  java.lang.String basepath,
                                  javax.jcr.Session session,
                                  boolean noRecurse)
                           throws java.io.IOException,
                                  org.xml.sax.SAXException,
                                  javax.jcr.PathNotFoundException,
                                  javax.jcr.RepositoryException
Exports the content of the repository, and format it if necessary.

Parameters:
stream - the stream to write the content to
reader - the reader to use to parse the xml content (so that we can perform filtering), if null instanciate a default one
repository - the repository to export
basepath - the basepath in the repository
session - the session to use to export the data from the repository
noRecurse -
Throws:
java.io.IOException
org.xml.sax.SAXException
javax.jcr.RepositoryException
javax.jcr.PathNotFoundException

readFormatted

protected static void readFormatted(org.xml.sax.XMLReader reader,
                                    java.io.File inputFile,
                                    java.io.OutputStream outputStream)
                             throws java.io.FileNotFoundException,
                                    java.io.IOException,
                                    org.xml.sax.SAXException
Parameters:
reader -
inputFile -
outputStream -
Throws:
java.io.FileNotFoundException
java.io.IOException
org.xml.sax.SAXException

readFormatted

protected static void readFormatted(org.xml.sax.XMLReader reader,
                                    java.io.InputStream inputStream,
                                    java.io.OutputStream outputStream)
                             throws java.io.FileNotFoundException,
                                    java.io.IOException,
                                    org.xml.sax.SAXException
Parameters:
reader -
inputStream -
outputStream -
Throws:
java.io.FileNotFoundException
java.io.IOException
org.xml.sax.SAXException

encodePath

public static java.lang.String encodePath(java.lang.String path,
                                          java.lang.String separator,
                                          java.lang.String enc)
Parameters:
path - path to encode
separator - "." (dot) or "/", it will be not encoded if found
enc - charset
Returns:
the path encoded

decodePath

public static java.lang.String decodePath(java.lang.String path,
                                          java.lang.String enc)
decode a path (ex. %D0%9D%D0%B0.%B2%D0%BE%D0%BB%D0%BD)

Parameters:
path - path to decode
enc - charset
Returns:
the path decoded


Copyright © 2003-2011 Magnolia International Ltd.. All Rights Reserved.