org.opencms.importexport
Class CmsExportHelper

java.lang.Object
  extended by org.opencms.importexport.CmsExportHelper

public class CmsExportHelper
extends java.lang.Object

Wrapper to write exported OpenCms resources either to a .ZIP file or to the file system.

Since:
7.5.1
Version:
$Revision: 1.4 $
Author:
Alexander Kandzior

Constructor Summary
CmsExportHelper(java.lang.String exportPath, boolean exportAsFiles, boolean validateXml)
          Creates a new export helper.
 
Method Summary
protected  java.lang.String getRfsFileName(java.lang.String name)
          Returns the RFS file name for the given OpenCms VFS file name.
 org.dom4j.io.SAXWriter getSaxWriter()
          Returns the SAX writer for the Manifest file.
protected  void removeOldExport(java.lang.String exportPath)
          Removes the old export output, which may be an existing file or directory.
 void writeFile(CmsFile file, java.lang.String name)
          Writes a single OpenCms VFS file to the export.
protected  void writeFile2Rfs(CmsFile file, java.lang.String name)
          Writes a single OpenCms VFS file to the RFS export.
protected  void writeFile2Zip(CmsFile file, java.lang.String name)
          Writes a single OpenCms VFS file to the ZIP export.
 void writeManifest(CmsXmlSaxWriter xmlSaxWriter)
          Writes the OpenCms manifest.xml file to the export.
protected  void writeManifest2Rfs(CmsXmlSaxWriter xmlSaxWriter)
          Writes the OpenCms manifest.xml file to the RFS export.
protected  void writeManifest2Zip(CmsXmlSaxWriter xmlSaxWriter)
          Writes the OpenCms manifest.xml file to the ZIP export.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmsExportHelper

public CmsExportHelper(java.lang.String exportPath,
                       boolean exportAsFiles,
                       boolean validateXml)
                throws org.xml.sax.SAXException,
                       java.io.IOException
Creates a new export helper.

Parameters:
exportPath - the export path
exportAsFiles - indicates if the resources should be exported as individual files or in one big ZIP file
validateXml - indicates of the manifest.xml should be validated
Throws:
org.xml.sax.SAXException - in case of issues creating the manifest.xml
java.io.IOException - in case of file access issues
Method Detail

getSaxWriter

public org.dom4j.io.SAXWriter getSaxWriter()
Returns the SAX writer for the Manifest file.

Returns:
the SAX writer for the Manifest file

writeFile

public void writeFile(CmsFile file,
                      java.lang.String name)
               throws java.io.IOException
Writes a single OpenCms VFS file to the export.

Parameters:
file - the OpenCms VFS file to write
name - the name of the file in the export
Throws:
java.io.IOException - in case of file access issues

writeManifest

public void writeManifest(CmsXmlSaxWriter xmlSaxWriter)
                   throws java.io.IOException,
                          org.xml.sax.SAXException
Writes the OpenCms manifest.xml file to the export.

Parameters:
xmlSaxWriter - the SAX writer to use
Throws:
org.xml.sax.SAXException - in case of issues creating the manifest.xml
java.io.IOException - in case of file access issues

getRfsFileName

protected java.lang.String getRfsFileName(java.lang.String name)
Returns the RFS file name for the given OpenCms VFS file name.

Parameters:
name - the OpenCms VFS file name
Returns:
the RFS file name for the given OpenCms VFS file name

removeOldExport

protected void removeOldExport(java.lang.String exportPath)
Removes the old export output, which may be an existing file or directory.

Parameters:
exportPath - the export output path

writeFile2Rfs

protected void writeFile2Rfs(CmsFile file,
                             java.lang.String name)
                      throws java.io.IOException
Writes a single OpenCms VFS file to the RFS export.

Parameters:
file - the OpenCms VFS file to write
name - the name of the file in the export
Throws:
java.io.IOException - in case of file access issues

writeFile2Zip

protected void writeFile2Zip(CmsFile file,
                             java.lang.String name)
                      throws java.io.IOException
Writes a single OpenCms VFS file to the ZIP export.

Parameters:
file - the OpenCms VFS file to write
name - the name of the file in the export
Throws:
java.io.IOException - in case of file access issues

writeManifest2Rfs

protected void writeManifest2Rfs(CmsXmlSaxWriter xmlSaxWriter)
                          throws org.xml.sax.SAXException,
                                 java.io.IOException
Writes the OpenCms manifest.xml file to the RFS export.

In case of the RFS export the file is directly written to a file output stream, so calling this method just closes the XML and finishes the stream.

Parameters:
xmlSaxWriter - the SAX writer to use
Throws:
org.xml.sax.SAXException - in case of issues creating the manifest.xml
java.io.IOException - in case of issues closing the file writer

writeManifest2Zip

protected void writeManifest2Zip(CmsXmlSaxWriter xmlSaxWriter)
                          throws java.io.IOException,
                                 org.xml.sax.SAXException
Writes the OpenCms manifest.xml file to the ZIP export.

In case of the ZIP export the manifest is written to an internal StringBuffer first, which is then stored in the ZIP file when this method is called.

Parameters:
xmlSaxWriter - the SAX writer to use
Throws:
org.xml.sax.SAXException - in case of issues creating the manifest.xml
java.io.IOException - in case of file access issues