org.opencms.importexport
Class CmsExport

java.lang.Object
  extended by org.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 which all meta-information about this files are stored, like permissions etc.

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

Constructor Summary
CmsExport()
          Constructs a new uninitialized export, required for special subclass data export.
CmsExport(CmsObject cms, I_CmsReport report)
          Constructs a new export.
CmsExport(CmsObject cms, java.lang.String exportFile, java.util.List resourcesToExport, boolean includeSystem, boolean includeUnchanged)
          Deprecated. use the CmsExportParameters constructor instead
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)
          Deprecated. use the CmsExportParameters constructor instead
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)
          Deprecated. use the CmsExportParameters constructor instead
 
Method Summary
protected  void addChildResources(java.lang.String folderName)
          Exports the given folder and all child resources.
protected  void addFiles(java.util.List<java.lang.String> fileNames)
          Adds all files in fileNames to the manifest.xml file.
protected  void addParentFolders(java.lang.String resourceName)
          Adds the parent folders of the given resource to the config file, starting at the top, excluding the root folder.
protected  void addPropertyNode(org.dom4j.Element propertiesElement, java.lang.String propertyName, java.lang.String propertyValue, boolean shared)
          Adds a property node to the manifest.xml.
protected  void addRelationNode(org.dom4j.Element relationsElement, java.lang.String structureId, java.lang.String sitePath, java.lang.String relationType)
          Adds a relation node to the manifest.xml.
protected  void appendResourceToManifest(CmsResource resource, boolean source)
          Writes the data for a resource (like access-rights) to the manifest.xml file.
protected  boolean checkExportResource(java.lang.String resourcename)
          Returns true if the checked resource name can be exported depending on the include settings.
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<java.lang.String> resourcesToExport)
          Exports all resources and possible sub-folders form the provided list of resources.
 void exportData(CmsExportParameters parameters)
          Export the data.
protected  void exportFile(CmsFile file)
          Exports one single file with all its data and content.
protected  void exportGroup(org.dom4j.Element parent, CmsGroup group)
          Exports one single group with all it's data.
protected  void exportGroups(org.dom4j.Element parent, CmsOrganizationalUnit orgunit)
          Exports all groups of the given organizational unit.
protected  void exportOrgUnit(org.dom4j.Element parent, CmsOrganizationalUnit orgunit)
          Exports one single organizational unit with all it's data.
protected  void exportOrgUnits(org.dom4j.Element parent)
          Exports all organizational units with all data.
protected  void exportProject(org.dom4j.Element parent, CmsProject project)
          Exports one single project with all it's data.
protected  void exportProjects(org.dom4j.Element parent)
          Exports all projects with all data.
protected  void exportUser(org.dom4j.Element parent, CmsUser user)
          Exports one single user with all its data.
protected  void exportUsers(org.dom4j.Element parent, CmsOrganizationalUnit orgunit)
          Exports all users of the given organizational unit.
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  I_CmsReport getReport()
          Returns the report to write progress messages to.
protected  java.lang.String getResourceNodeName()
          Returns the name for the main resource node.
protected  org.dom4j.io.SAXWriter getSaxWriter()
          Returns the SAX based 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  boolean isInExportableProject(CmsResource res)
          Checks if a resource is belongs to the correct project for exporting.
protected  org.dom4j.Element openExportFile()
          Opens the export ZIP file and initializes the internal XML document for the manifest.
protected  void setSaxWriter(org.dom4j.io.SAXWriter saxWriter)
          Sets the SAX based XML writer to write the XML output to.
protected  java.lang.String trimResourceName(java.lang.String resourceName)
          Cuts leading and trailing '/' from the given resource name.
 
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,
                 I_CmsReport report)
          throws CmsRoleViolationException
Constructs a new export.

Parameters:
cms - the cms context
report - the report
Throws:
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)
          throws CmsImportExportException,
                 CmsRoleViolationException
Deprecated. use the CmsExportParameters constructor instead

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,
                 long contentAge,
                 I_CmsReport report)
          throws CmsImportExportException,
                 CmsRoleViolationException
Deprecated. use the CmsExportParameters constructor instead

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
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
Deprecated. use the CmsExportParameters constructor instead

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
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

exportData

public void exportData(CmsExportParameters parameters)
                throws CmsImportExportException
Export the data.

Parameters:
parameters - the export parameters
Throws:
CmsImportExportException - if something goes wrong

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 processing the manifest.xml
java.io.IOException - if not all resources could be appended to the ZIP archive

addFiles

protected void addFiles(java.util.List<java.lang.String> fileNames)
                 throws CmsImportExportException,
                        java.io.IOException,
                        org.xml.sax.SAXException
Adds all files in fileNames to the manifest.xml file.

Parameters:
fileNames - list of path Strings, e.g. /folder/index.html
Throws:
CmsImportExportException - if something goes wrong
java.io.IOException - if a file could not be exported
org.xml.sax.SAXException - if something goes wrong processing the manifest.xml

addParentFolders

protected void addParentFolders(java.lang.String resourceName)
                         throws CmsImportExportException,
                                org.xml.sax.SAXException
Adds the parent folders of the given resource to the config file, starting at the top, excluding the root folder.

Parameters:
resourceName - the name of a resource in the VFS
Throws:
CmsImportExportException - if something goes wrong
org.xml.sax.SAXException - if something goes wrong processing the manifest.xml

addPropertyNode

protected void addPropertyNode(org.dom4j.Element propertiesElement,
                               java.lang.String propertyName,
                               java.lang.String propertyValue,
                               boolean shared)
Adds a property node to the manifest.xml.

Parameters:
propertiesElement - the parent element to append the node to
propertyName - the name of the property
propertyValue - the value of the property
shared - if true, add a shared property attribute to the generated property node

addRelationNode

protected void addRelationNode(org.dom4j.Element relationsElement,
                               java.lang.String structureId,
                               java.lang.String sitePath,
                               java.lang.String relationType)
Adds a relation node to the manifest.xml.

Parameters:
relationsElement - the parent element to append the node to
structureId - the structure id of the target relation
sitePath - the site path of the target relation
relationType - the type of the relation

appendResourceToManifest

protected void appendResourceToManifest(CmsResource resource,
                                        boolean source)
                                 throws CmsImportExportException,
                                        org.xml.sax.SAXException
Writes the data for a resource (like access-rights) to the manifest.xml file.

Parameters:
resource - the resource to get the data from
source - flag to show if the source information in the xml file must be written
Throws:
CmsImportExportException - if something goes wrong
org.xml.sax.SAXException - if something goes wrong processing the manifest.xml

checkExportResource

protected boolean checkExportResource(java.lang.String resourcename)
Returns true if the checked resource name can be exported depending on the include settings.

Parameters:
resourcename - the absolute path of the resource
Returns:
true if the checked resource name can be exported depending on the include settings

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 processing 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 processing the manifest.xml

exportAllResources

protected void exportAllResources(org.dom4j.Element parent,
                                  java.util.List<java.lang.String> 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 processing the manifest.xml
java.io.IOException - if not all resources could be appended to the ZIP archive

exportFile

protected void exportFile(CmsFile file)
                   throws CmsImportExportException,
                          org.xml.sax.SAXException,
                          java.io.IOException
Exports one single file with all its data and content.

Parameters:
file - the file to be exported
Throws:
CmsImportExportException - if something goes wrong
org.xml.sax.SAXException - if something goes wrong processing the manifest.xml
java.io.IOException - if the ZIP entry for the file could be appended to the ZIP archive

exportGroup

protected void exportGroup(org.dom4j.Element parent,
                           CmsGroup group)
                    throws CmsImportExportException,
                           org.xml.sax.SAXException
Exports one single group with all it's data.

Parameters:
parent - the parent node to add the groups to
group - the group to be exported
Throws:
CmsImportExportException - if something goes wrong
org.xml.sax.SAXException - if something goes wrong processing the manifest.xml

exportGroups

protected void exportGroups(org.dom4j.Element parent,
                            CmsOrganizationalUnit orgunit)
                     throws CmsImportExportException,
                            org.xml.sax.SAXException
Exports all groups of the given organizational unit.

Parameters:
parent - the parent node to add the groups to
orgunit - the organizational unit to write the groups for
Throws:
CmsImportExportException - if something goes wrong
org.xml.sax.SAXException - if something goes wrong processing the manifest.xml

exportOrgUnit

protected void exportOrgUnit(org.dom4j.Element parent,
                             CmsOrganizationalUnit orgunit)
                      throws org.xml.sax.SAXException,
                             CmsException
Exports one single organizational unit with all it's data.

Parameters:
parent - the parent node to add the groups to
orgunit - the group to be exported
Throws:
org.xml.sax.SAXException - if something goes wrong processing the manifest.xml
CmsException - if something goes wrong reading the data to export

exportOrgUnits

protected void exportOrgUnits(org.dom4j.Element parent)
                       throws CmsImportExportException,
                              org.xml.sax.SAXException
Exports all organizational units with all data.

Parameters:
parent - the parent node to add the organizational units to
Throws:
CmsImportExportException - if something goes wrong
org.xml.sax.SAXException - if something goes wrong processing the manifest.xml

exportProject

protected void exportProject(org.dom4j.Element parent,
                             CmsProject project)
                      throws CmsImportExportException,
                             org.xml.sax.SAXException
Exports one single project with all it's data.

Parameters:
parent - the parent node to add the project to
project - the project to be exported
Throws:
CmsImportExportException - if something goes wrong
org.xml.sax.SAXException - if something goes wrong processing the manifest.xml

exportProjects

protected void exportProjects(org.dom4j.Element parent)
                       throws CmsImportExportException,
                              org.xml.sax.SAXException
Exports all projects with all data.

Parameters:
parent - the parent node to add the projects to
Throws:
CmsImportExportException - if something goes wrong
org.xml.sax.SAXException - if something goes wrong processing the manifest.xml

exportUser

protected void exportUser(org.dom4j.Element parent,
                          CmsUser user)
                   throws CmsImportExportException,
                          org.xml.sax.SAXException
Exports one single user with all its data.

Parameters:
parent - the parent node to add the users to
user - the user to be exported
Throws:
CmsImportExportException - if something goes wrong
org.xml.sax.SAXException - if something goes wrong processing the manifest.xml

exportUsers

protected void exportUsers(org.dom4j.Element parent,
                           CmsOrganizationalUnit orgunit)
                    throws CmsImportExportException,
                           org.xml.sax.SAXException
Exports all users of the given organizational unit.

Parameters:
parent - the parent node to add the users to
orgunit - the organizational unit to write the groups for
Throws:
CmsImportExportException - if something goes wrong
org.xml.sax.SAXException - if something goes wrong processing the manifest.xml

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

getReport

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

Returns:
the report to write progress 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 based xml writer to write the XML output to.

Returns:
the SAX based 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

isInExportableProject

protected boolean isInExportableProject(CmsResource res)
Checks if a resource is belongs to the correct project for exporting.

Parameters:
res - the resource to check
Returns:
true, if the resource can be exported, false otherwise

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 processing the manifest.xml
java.io.IOException - if something goes wrong while closing the export file

setSaxWriter

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

Parameters:
saxWriter - the SAX based XML writer to write the XML output to

trimResourceName

protected java.lang.String trimResourceName(java.lang.String resourceName)
Cuts leading and trailing '/' from the given resource name.

Parameters:
resourceName - the absolute path of a resource
Returns:
the trimmed resource name