org.opencms.importexport
Class CmsExport

java.lang.Object
  extended byorg.opencms.importexport.CmsExport

public class CmsExport
extends java.lang.Object

Provides the functionality to export files from the OpenCms VFS to a ZIP file.

The ZIP file written will contain a copy of all exported files with their contents. It will also contain a manifest.xml file in wich all meta-information about this files are stored, like permissions etc.

Since:
6.0.0
Version:
$Revision: 1.84 $
Author:
Alexander Kandzior, Michael Emmerich

Constructor Summary
CmsExport()
          Constructs a new uninitialized export, required for special subclass data export.
CmsExport(CmsObject cms, java.lang.String exportFile, java.util.List resourcesToExport, boolean includeSystem, boolean includeUnchanged)
          Constructs a new export.
CmsExport(CmsObject cms, java.lang.String exportFile, java.util.List resourcesToExport, boolean includeSystem, boolean includeUnchanged, org.dom4j.Element moduleElement, boolean exportUserdata, boolean exportWebusers, long contentAge, I_CmsReport report, boolean recursive)
          Constructs a new export.
CmsExport(CmsObject cms, java.lang.String exportFile, java.util.List resourcesToExport, boolean includeSystem, boolean includeUnchanged, org.dom4j.Element moduleElement, boolean exportUserdata, long contentAge, I_CmsReport report)
          Constructs a new export.
CmsExport(CmsObject cms, java.lang.String exportFile, java.util.List resourcesToExport, boolean includeSystem, boolean includeUnchanged, org.dom4j.Element moduleElement, boolean exportUserdata, long contentAge, I_CmsReport report, boolean recursive)
          Constructs a new export.
 
Method Summary
protected  void addChildResources(java.lang.String folderName)
          Exports the given folder and all child resources.
protected  void closeExportFile(org.dom4j.Element exportNode)
          Closes the export ZIP file and saves the XML document for the manifest.
protected  void digestElement(org.dom4j.Element parent, org.dom4j.Element output)
          Writes the output element to the XML output writer and detaches it from it's parent element.
protected  void exportAllResources(org.dom4j.Element parent, java.util.List resourcesToExport)
          Exports all resources and possible sub-folders form the provided list of resources.
protected  CmsObject getCms()
          Returns the OpenCms context object this export was initialized with.
protected  java.lang.String getExportFileName()
          Returns the name of the export file.
protected  java.lang.String getExportNodeName()
          Returns the name of the main export node.
protected  java.util.zip.ZipOutputStream getExportZipStream()
          Returns the zip output stream to write to.
protected  I_CmsReport getReport()
          Returns the report to write progess messages to.
protected  java.lang.String getResourceNodeName()
          Returns the name for the main resource node.
protected  org.dom4j.io.SAXWriter getSaxWriter()
          Returns the SAX baesed xml writer to write the XML output to.
protected  boolean isIgnoredProperty(CmsProperty property)
          Checks if a property should be written to the export or not.
protected  org.dom4j.Element openExportFile()
          Opens the export ZIP file and initializes the internal XML document for the manifest.
protected  void setCms(CmsObject cms)
          Sets the OpenCms context object this export was initialized with.
protected  void setExportFileName(java.lang.String exportFileName)
          Sets the name of the export file.
protected  void setExportZipStream(java.util.zip.ZipOutputStream exportZipStream)
          Sets the zip output stream to write to.
protected  void setReport(I_CmsReport report)
          Sets the report to write progess messages to.
protected  void setSaxWriter(org.dom4j.io.SAXWriter saxWriter)
          Sets the SAX baesed xml writer to write the XML output to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmsExport

public CmsExport()
Constructs a new uninitialized export, required for special subclass data export.


CmsExport

public CmsExport(CmsObject cms,
                 java.lang.String exportFile,
                 java.util.List resourcesToExport,
                 boolean includeSystem,
                 boolean includeUnchanged)
          throws CmsImportExportException,
                 CmsRoleViolationException
Constructs a new export.

Parameters:
cms - the cmsObject to work with
exportFile - the file or folder to export to
resourcesToExport - the paths of folders and files to export
includeSystem - if true, the system folder is included
includeUnchanged - true, if unchanged files should be included
Throws:
CmsImportExportException - if something goes wrong
CmsRoleViolationException - if the current user has not the required role

CmsExport

public CmsExport(CmsObject cms,
                 java.lang.String exportFile,
                 java.util.List resourcesToExport,
                 boolean includeSystem,
                 boolean includeUnchanged,
                 org.dom4j.Element moduleElement,
                 boolean exportUserdata,
                 boolean exportWebusers,
                 long contentAge,
                 I_CmsReport report,
                 boolean recursive)
          throws CmsImportExportException,
                 CmsRoleViolationException
Constructs a new export.

Parameters:
cms - the cmsObject to work with
exportFile - the file or folder to export to
resourcesToExport - the paths of folders and files to export
includeSystem - if true, the system folder is included
includeUnchanged - true, if unchanged files should be included
moduleElement - module informations in a Node for module export
exportUserdata - if true, the user and group data will also be exported
exportWebusers - if true, the webuser data will also be exported
contentAge - export contents changed after this date/time
report - to handle the log messages
recursive - recursive flag
Throws:
CmsImportExportException - if something goes wrong
CmsRoleViolationException - if the current user has not the required role

CmsExport

public CmsExport(CmsObject cms,
                 java.lang.String exportFile,
                 java.util.List resourcesToExport,
                 boolean includeSystem,
                 boolean includeUnchanged,
                 org.dom4j.Element moduleElement,
                 boolean exportUserdata,
                 long contentAge,
                 I_CmsReport report)
          throws CmsImportExportException,
                 CmsRoleViolationException
Constructs a new export.

Parameters:
cms - the cmsObject to work with
exportFile - the file or folder to export to
resourcesToExport - the paths of folders and files to export
includeSystem - if true, the system folder is included
includeUnchanged - true, if unchanged files should be included
moduleElement - module informations in a Node for module export
exportUserdata - if true, the user and grou pdata will also be exported
contentAge - export contents changed after this date/time
report - to handle the log messages
Throws:
CmsImportExportException - if something goes wrong
CmsRoleViolationException - if the current user has not the required role

CmsExport

public CmsExport(CmsObject cms,
                 java.lang.String exportFile,
                 java.util.List resourcesToExport,
                 boolean includeSystem,
                 boolean includeUnchanged,
                 org.dom4j.Element moduleElement,
                 boolean exportUserdata,
                 long contentAge,
                 I_CmsReport report,
                 boolean recursive)
          throws CmsImportExportException,
                 CmsRoleViolationException
Constructs a new export.

Parameters:
cms - the cmsObject to work with
exportFile - the file or folder to export to
resourcesToExport - the paths of folders and files to export
includeSystem - if true, the system folder is included
includeUnchanged - true, if unchanged files should be included
moduleElement - module informations in a Node for module export
exportUserdata - if true, the user and grou pdata will also be exported
contentAge - export contents changed after this date/time
report - to handle the log messages
recursive - recursive flag
Throws:
CmsImportExportException - if something goes wrong
CmsRoleViolationException - if the current user has not the required role
Method Detail

addChildResources

protected void addChildResources(java.lang.String folderName)
                          throws CmsImportExportException,
                                 java.io.IOException,
                                 org.xml.sax.SAXException
Exports the given folder and all child resources.

Parameters:
folderName - to complete path to the resource to export
Throws:
CmsImportExportException - if something goes wrong
org.xml.sax.SAXException - if something goes wrong procesing the manifest.xml
java.io.IOException - if not all resources could be appended to the ZIP archive

closeExportFile

protected void closeExportFile(org.dom4j.Element exportNode)
                        throws java.io.IOException,
                               org.xml.sax.SAXException
Closes the export ZIP file and saves the XML document for the manifest.

Parameters:
exportNode - the export root node
Throws:
org.xml.sax.SAXException - if something goes wrong procesing the manifest.xml
java.io.IOException - if something goes wrong while closing the export file

digestElement

protected void digestElement(org.dom4j.Element parent,
                             org.dom4j.Element output)
                      throws org.xml.sax.SAXException
Writes the output element to the XML output writer and detaches it from it's parent element.

Parameters:
parent - the parent element
output - the output element
Throws:
org.xml.sax.SAXException - if something goes wrong procesing the manifest.xml

exportAllResources

protected void exportAllResources(org.dom4j.Element parent,
                                  java.util.List resourcesToExport)
                           throws CmsImportExportException,
                                  java.io.IOException,
                                  org.xml.sax.SAXException
Exports all resources and possible sub-folders form the provided list of resources.

Parameters:
parent - the parent node to add the resources to
resourcesToExport - the list of resources to export
Throws:
CmsImportExportException - if something goes wrong
org.xml.sax.SAXException - if something goes wrong procesing the manifest.xml
java.io.IOException - if not all resources could be appended to the ZIP archive

getCms

protected CmsObject getCms()
Returns the OpenCms context object this export was initialized with.

Returns:
the OpenCms context object this export was initialized with

getExportFileName

protected java.lang.String getExportFileName()
Returns the name of the export file.

Returns:
the name of the export file

getExportNodeName

protected java.lang.String getExportNodeName()
Returns the name of the main export node.

Returns:
the name of the main export node

getExportZipStream

protected java.util.zip.ZipOutputStream getExportZipStream()
Returns the zip output stream to write to.

Returns:
the zip output stream to write to

getReport

protected I_CmsReport getReport()
Returns the report to write progess messages to.

Returns:
the report to write progess messages to

getResourceNodeName

protected java.lang.String getResourceNodeName()
Returns the name for the main resource node.

Returns:
the name for the main resource node

getSaxWriter

protected org.dom4j.io.SAXWriter getSaxWriter()
Returns the SAX baesed xml writer to write the XML output to.

Returns:
the SAX baesed xml writer to write the XML output to

isIgnoredProperty

protected boolean isIgnoredProperty(CmsProperty property)
Checks if a property should be written to the export or not.

Parameters:
property - the property to check
Returns:
if true, the property is to be ignored, otherwise it should be exported

openExportFile

protected org.dom4j.Element openExportFile()
                                    throws java.io.IOException,
                                           org.xml.sax.SAXException
Opens the export ZIP file and initializes the internal XML document for the manifest.

Returns:
the node in the XML document where all files are appended to
Throws:
org.xml.sax.SAXException - if something goes wrong procesing the manifest.xml
java.io.IOException - if something goes wrong while closing the export file

setCms

protected void setCms(CmsObject cms)
Sets the OpenCms context object this export was initialized with.

Parameters:
cms - the OpenCms context object this export was initialized with

setExportFileName

protected void setExportFileName(java.lang.String exportFileName)
Sets the name of the export file.

Parameters:
exportFileName - the name of the export file

setExportZipStream

protected void setExportZipStream(java.util.zip.ZipOutputStream exportZipStream)
Sets the zip output stream to write to.

Parameters:
exportZipStream - the zip output stream to write to

setReport

protected void setReport(I_CmsReport report)
Sets the report to write progess messages to.

Parameters:
report - the report to write progess messages to

setSaxWriter

protected void setSaxWriter(org.dom4j.io.SAXWriter saxWriter)
Sets the SAX baesed xml writer to write the XML output to.

Parameters:
saxWriter - the SAX baesed xml writer to write the XML output to