Class CmsExportHelper

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

public class CmsExportHelper extends Object
Wrapper to write exported OpenCms resources either to a .ZIP file or to the file system.

Since:
7.5.1
  • Constructor Details

    • CmsExportHelper

      public CmsExportHelper(String exportPath, boolean exportAsFiles, boolean validateXml) throws SAXException, 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:
      SAXException - in case of issues creating the manifest.xml
      IOException - in case of file access issues
  • Method Details

    • ensureZipStreamClosed

      public void ensureZipStreamClosed()
      Ensures the zip stream is closed (if there is one).
    • 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, String name) throws 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:
      IOException - in case of file access issues
    • writeManifest

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

      Parameters:
      xmlSaxWriter - the SAX writer to use
      Throws:
      SAXException - in case of issues creating the manifest.xml
      IOException - in case of file access issues
    • getRfsFileName

      protected String getRfsFileName(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(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, String name) throws 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:
      IOException - in case of file access issues
    • writeFile2Zip

      protected void writeFile2Zip(CmsFile file, String name) throws 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:
      IOException - in case of file access issues
    • writeManifest2Rfs

      protected void writeManifest2Rfs(CmsXmlSaxWriter xmlSaxWriter) throws SAXException, 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:
      SAXException - in case of issues creating the manifest.xml
      IOException - in case of issues closing the file writer
    • writeManifest2Zip

      protected void writeManifest2Zip(CmsXmlSaxWriter xmlSaxWriter) throws IOException, 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:
      SAXException - in case of issues creating the manifest.xml
      IOException - in case of file access issues