Class CmsExport

java.lang.Object
org.opencms.importexport.CmsExport

public class CmsExport extends 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
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new uninitialized export, required for special subclass data export.
    Constructs a new export.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Exports the given folder and all child resources.
    protected void
    addFiles(List<String> fileNames)
    Adds all files in fileNames to the manifest.xml file.
    protected void
    addParentFolders(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, String propertyName, String propertyValue, boolean shared)
    Adds a property node to the manifest.xml.
    protected void
    addRelationNode(org.dom4j.Element relationsElement, String structureId, String sitePath, String relationType)
    Adds a relation node to the manifest.xml.
    protected void
    appendResourceToManifest(CmsResource resource, boolean source)
     
    protected void
    appendResourceToManifest(CmsResource resource, boolean source, boolean isSuperFolder)
    Writes the data for a resource (like access-rights) to the manifest.xml file.
    protected boolean
    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, List<String> resourcesToExport)
    Exports all resources and possible sub-folders form the provided list of resources.
    void
    Export the data.
    protected void
    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 boolean
    Check, if the resource should be exported with minimal meta-data.
    protected CmsObject
    Returns the OpenCms context object this export was initialized with.
    protected String
    Returns the name of the export file.
    protected String
    Returns the name of the main export node.
    protected I_CmsReport
    Returns the report to write progress messages to.
    protected String
    Returns the name for the main resource node.
    protected org.dom4j.io.SAXWriter
    Returns the SAX based xml writer to write the XML output to.
    protected boolean
    Checks if a property should be written to the export or not.
    protected boolean
    Checks if a resource is belongs to the correct project for exporting.
    protected org.dom4j.Element
    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 String
    trimResourceName(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 Details

  • Method Details

    • exportData

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

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

      Exports the given folder and all child resources.

      Parameters:
      folderName - to complete path to the resource to export
      Throws:
      CmsImportExportException - if something goes wrong
      SAXException - if something goes wrong processing the manifest.xml
      IOException - if not all resources could be appended to the ZIP archive
    • addFiles

      protected void addFiles(List<String> fileNames) throws CmsImportExportException, IOException, 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
      IOException - if a file could not be exported
      SAXException - if something goes wrong processing the manifest.xml
    • addParentFolders

      protected void addParentFolders(String resourceName) throws CmsImportExportException, 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
      SAXException - if something goes wrong processing the manifest.xml
    • addPropertyNode

      protected void addPropertyNode(org.dom4j.Element propertiesElement, String propertyName, 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, String structureId, String sitePath, 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, SAXException
      Parameters:
      resource -
      source -
      Throws:
      CmsImportExportException - @see #appendResourceToManifest(CmsResource, boolean, boolean)
      SAXException - @see #appendResourceToManifest(CmsResource, boolean, boolean)
      See Also:
    • appendResourceToManifest

      protected void appendResourceToManifest(CmsResource resource, boolean source, boolean isSuperFolder) throws CmsImportExportException, 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
      isSuperFolder - flag to indicate that the resource is only a super folder of a module resource. This will prevent exporting uuid and creation date in the reduced export mode.
      Throws:
      CmsImportExportException - if something goes wrong
      SAXException - if something goes wrong processing the manifest.xml
    • checkExportResource

      protected boolean checkExportResource(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 IOException, SAXException
      Closes the export ZIP file and saves the XML document for the manifest.

      Parameters:
      exportNode - the export root node
      Throws:
      SAXException - if something goes wrong processing the manifest.xml
      IOException - if something goes wrong while closing the export file
    • digestElement

      protected void digestElement(org.dom4j.Element parent, org.dom4j.Element output) throws 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:
      SAXException - if something goes wrong processing the manifest.xml
    • exportAllResources

      protected void exportAllResources(org.dom4j.Element parent, List<String> resourcesToExport) throws CmsImportExportException, IOException, 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
      SAXException - if something goes wrong processing the manifest.xml
      IOException - if not all resources could be appended to the ZIP archive
    • exportFile

      Exports one single file with all its data and content.

      Parameters:
      file - the file to be exported
      Throws:
      CmsImportExportException - if something goes wrong
      SAXException - if something goes wrong processing the manifest.xml
      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, 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
      SAXException - if something goes wrong processing the manifest.xml
    • exportGroups

      protected void exportGroups(org.dom4j.Element parent, CmsOrganizationalUnit orgunit) throws CmsImportExportException, 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
      SAXException - if something goes wrong processing the manifest.xml
    • exportOrgUnit

      protected void exportOrgUnit(org.dom4j.Element parent, CmsOrganizationalUnit orgunit) throws 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:
      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, 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
      SAXException - if something goes wrong processing the manifest.xml
    • exportProject

      protected void exportProject(org.dom4j.Element parent, CmsProject project) throws CmsImportExportException, 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
      SAXException - if something goes wrong processing the manifest.xml
    • exportProjects

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

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

      protected void exportUser(org.dom4j.Element parent, CmsUser user) throws CmsImportExportException, 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
      SAXException - if something goes wrong processing the manifest.xml
    • exportUsers

      protected void exportUsers(org.dom4j.Element parent, CmsOrganizationalUnit orgunit) throws CmsImportExportException, 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
      SAXException - if something goes wrong processing the manifest.xml
    • exportWithMinimalMetaData

      protected boolean exportWithMinimalMetaData(String path)
      Check, if the resource should be exported with minimal meta-data. This holds for resources that are not part of the export, but must be exported as super-folders.
      Parameters:
      path - export-site relative path of the resource to check.
      Returns:
      flag, indicating if the resource should be exported with minimal meta data.
    • 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

      Returns the name of the export file.

      Returns:
      the name of the export file
    • 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

      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(CmsModule.ExportMode exportMode) throws IOException, SAXException
      Opens the export ZIP file and initializes the internal XML document for the manifest.

      Parameters:
      exportMode - the export mode to use.
      Returns:
      the node in the XML document where all files are appended to
      Throws:
      SAXException - if something goes wrong processing the manifest.xml
      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 String trimResourceName(String resourceName)
      Cuts leading and trailing '/' from the given resource name.

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