info.magnolia.importexport
Class DataTransporter

java.lang.Object
  extended by info.magnolia.importexport.DataTransporter

public class DataTransporter
extends Object

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


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

Field Detail

ZIP

public static final String ZIP
See Also:
Constant Field Values

GZ

public static final String GZ
See Also:
Constant Field Values

XML

public static final String XML
See Also:
Constant Field Values

PROPERTIES

public static final String PROPERTIES
See Also:
Constant Field Values

DOT

public static final String DOT
See Also:
Constant Field Values

SLASH

public static final String SLASH
See Also:
Constant Field Values

UTF8

public static final String UTF8
See Also:
Constant Field Values

JCR_ROOT

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

DataTransporter

public DataTransporter()
Method Detail

importDocument

public static void importDocument(Document xmlDocument,
                                  String repositoryName,
                                  String basepath,
                                  boolean keepVersionHistory,
                                  int importMode,
                                  boolean saveAfterImport,
                                  boolean createBasepathIfNotExist)
                           throws 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
Throws:
IOException
See Also:
ImportUUIDBehavior

importFile

public static void importFile(File xmlFile,
                              String repositoryName,
                              String basepath,
                              boolean keepVersionHistory,
                              int importMode,
                              boolean saveAfterImport,
                              boolean createBasepathIfNotExist)
                       throws 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
Throws:
IOException
See Also:
ImportUUIDBehavior

executeBootstrapImport

public static void executeBootstrapImport(File xmlFile,
                                          String repositoryName)
                                   throws IOException
Throws:
IOException

importProperties

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


importXmlStream

public static void importXmlStream(InputStream xmlStream,
                                   String repositoryName,
                                   String basepath,
                                   String name,
                                   boolean keepVersionHistory,
                                   int importMode,
                                   boolean saveAfterImport,
                                   boolean createBasepathIfNotExist)
                            throws 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
Throws:
IOException
See Also:
ImportUUIDBehavior, ImportXmlRootFilter, VersionFilter, MagnoliaV2Filter

importXmlStream

public static void importXmlStream(InputStream xmlStream,
                                   String repositoryName,
                                   String basepath,
                                   String name,
                                   boolean keepVersionHistory,
                                   boolean forceUnpublishState,
                                   int importMode,
                                   boolean saveAfterImport,
                                   boolean createBasepathIfNotExist)
                            throws 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
forceUnpublishState - if true then activation state of node will be change to unpublished.
importMode - a valid value for ImportUUIDBehavior
Throws:
IOException
See Also:
ImportUUIDBehavior, ImportXmlRootFilter, VersionFilter, MagnoliaV2Filter

getXslStreamForXmlFile

protected static InputStream getXslStreamForXmlFile(File file)
Returns:
XSL stream for Xml file or null

executeExport

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

parseAndFormat

public static void parseAndFormat(OutputStream stream,
                                  XMLReader reader,
                                  String repository,
                                  String basepath,
                                  javax.jcr.Session session,
                                  boolean noRecurse)
                           throws IOException,
                                  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
Throws:
IOException
SAXException
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException

readFormatted

protected static void readFormatted(XMLReader reader,
                                    File inputFile,
                                    OutputStream outputStream)
                             throws FileNotFoundException,
                                    IOException,
                                    SAXException
Throws:
FileNotFoundException
IOException
SAXException

readFormatted

protected static void readFormatted(XMLReader reader,
                                    InputStream inputStream,
                                    OutputStream outputStream)
                             throws FileNotFoundException,
                                    IOException,
                                    SAXException
Throws:
FileNotFoundException
IOException
SAXException

encodePath

public static String encodePath(String path,
                                String separator,
                                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 String decodePath(String path,
                                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

createExportPath

public static String createExportPath(String path)
Prior to 4.5 Magnolia used to produce export xml filenames where the / (slash) separating sub nodes was replaced by a dot. Since 4.5, Magnolia enables dots in path names, therefore dots which are part of the node name have to be escaped by doubling them. I.e. given a path like this /foo/bar.baz/test../dir/baz..bar, this method will produce .foo.bar..baz.test.....dir.baz....bar.


revertExportPath

public static String revertExportPath(String exportPath)
The opposite of createExportPath(String). I.e. given a path like this .foo.bar..baz.test.....dir.baz....bar, this method will produce /foo/bar.baz/test../dir/baz..bar.



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