Package org.opencms.importexport
Class CmsExport
java.lang.Object
org.opencms.importexport.CmsExport
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
ConstructorsConstructorDescriptionConstructs a new uninitialized export, required for special subclass data export.CmsExport(CmsObject cms, I_CmsReport report) Constructs a new export. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddChildResources(String folderName) Exports the given folder and all child resources.protected voidAdds all files in fileNames to the manifest.xml file.protected voidaddParentFolders(String resourceName) Adds the parent folders of the given resource to the config file, starting at the top, excluding the root folder.protected voidaddPropertyNode(org.dom4j.Element propertiesElement, String propertyName, String propertyValue, boolean shared) Adds a property node to the manifest.xml.protected voidaddRelationNode(org.dom4j.Element relationsElement, String structureId, String sitePath, String relationType) Adds a relation node to themanifest.xml.protected voidappendResourceToManifest(CmsResource resource, boolean source) protected voidappendResourceToManifest(CmsResource resource, boolean source, boolean isSuperFolder) Writes the data for a resource (like access-rights) to themanifest.xmlfile.protected booleancheckExportResource(String resourcename) Returns true if the checked resource name can be exported depending on the include settings.protected voidcloseExportFile(org.dom4j.Element exportNode) Closes the export ZIP file and saves the XML document for the manifest.protected voiddigestElement(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 voidexportAllResources(org.dom4j.Element parent, List<String> resourcesToExport) Exports all resources and possible sub-folders form the provided list of resources.voidexportData(CmsExportParameters parameters) Export the data.protected voidexportFile(CmsFile file) Exports one single file with all its data and content.protected voidexportGroup(org.dom4j.Element parent, CmsGroup group) Exports one single group with all it's data.protected voidexportGroups(org.dom4j.Element parent, CmsOrganizationalUnit orgunit) Exports all groups of the given organizational unit.protected voidexportOrgUnit(org.dom4j.Element parent, CmsOrganizationalUnit orgunit) Exports one single organizational unit with all it's data.protected voidexportOrgUnits(org.dom4j.Element parent) Exports all organizational units with all data.protected voidexportProject(org.dom4j.Element parent, CmsProject project) Exports one single project with all it's data.protected voidexportProjects(org.dom4j.Element parent) Exports all projects with all data.protected voidexportUser(org.dom4j.Element parent, CmsUser user) Exports one single user with all its data.protected voidexportUsers(org.dom4j.Element parent, CmsOrganizationalUnit orgunit) Exports all users of the given organizational unit.protected booleanCheck, if the resource should be exported with minimal meta-data.protected CmsObjectgetCms()Returns the OpenCms context object this export was initialized with.protected StringReturns the name of the export file.protected StringReturns the name of the main export node.protected I_CmsReportReturns the report to write progress messages to.protected StringReturns the name for the main resource node.protected org.dom4j.io.SAXWriterReturns the SAX based xml writer to write the XML output to.protected booleanisIgnoredProperty(CmsProperty property) Checks if a property should be written to the export or not.protected booleanChecks if a resource is belongs to the correct project for exporting.protected org.dom4j.ElementopenExportFile(CmsModule.ExportMode exportMode) Opens the export ZIP file and initializes the internal XML document for the manifest.protected voidsetSaxWriter(org.dom4j.io.SAXWriter saxWriter) Sets the SAX based XML writer to write the XML output to.protected StringtrimResourceName(String resourceName) Cuts leading and trailing '/' from the given resource name.
-
Constructor Details
-
CmsExport
public CmsExport()Constructs a new uninitialized export, required for special subclass data export. -
CmsExport
Constructs a new export.- Parameters:
cms- the cms contextreport- the report- Throws:
CmsRoleViolationException- if the current user has not the required role
-
-
Method Details
-
exportData
Export the data.- Parameters:
parameters- the export parameters- Throws:
CmsImportExportException- if something goes wrong
-
addChildResources
protected void addChildResources(String folderName) throws CmsImportExportException, IOException, SAXException Exports the given folder and all child resources.- Parameters:
folderName- to complete path to the resource to export- Throws:
CmsImportExportException- if something goes wrongSAXException- if something goes wrong processing the manifest.xmlIOException- 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 wrongIOException- if a file could not be exportedSAXException- if something goes wrong processing the manifest.xml
-
addParentFolders
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 wrongSAXException- 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 topropertyName- the name of the propertypropertyValue- the value of the propertyshared- iftrue, 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 themanifest.xml.- Parameters:
relationsElement- the parent element to append the node tostructureId- the structure id of the target relationsitePath- the site path of the target relationrelationType- the type of the relation
-
appendResourceToManifest
protected void appendResourceToManifest(CmsResource resource, boolean source) throws CmsImportExportException, SAXException - Parameters:
resource- @see #appendResourceToManifest(CmsResource, boolean, boolean)source- @see #appendResourceToManifest(CmsResource, boolean, boolean)- 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 themanifest.xmlfile.- Parameters:
resource- the resource to get the data fromsource- flag to show if the source information in the xml file must be writtenisSuperFolder- 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 wrongSAXException- if something goes wrong processing the manifest.xml
-
checkExportResource
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
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.xmlIOException- 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 elementoutput- 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 toresourcesToExport- the list of resources to export- Throws:
CmsImportExportException- if something goes wrongSAXException- if something goes wrong processing the manifest.xmlIOException- 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 wrongSAXException- if something goes wrong processing the manifest.xmlIOException- 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 togroup- the group to be exported- Throws:
CmsImportExportException- if something goes wrongSAXException- 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 toorgunit- the organizational unit to write the groups for- Throws:
CmsImportExportException- if something goes wrongSAXException- 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 toorgunit- the group to be exported- Throws:
SAXException- if something goes wrong processing the manifest.xmlCmsException- 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 wrongSAXException- 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 toproject- the project to be exported- Throws:
CmsImportExportException- if something goes wrongSAXException- 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 wrongSAXException- 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 touser- the user to be exported- Throws:
CmsImportExportException- if something goes wrongSAXException- 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 toorgunit- the organizational unit to write the groups for- Throws:
CmsImportExportException- if something goes wrongSAXException- if something goes wrong processing the manifest.xml
-
exportWithMinimalMetaData
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
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
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
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
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
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.xmlIOException- if something goes wrong while closing the export file
-
setSaxWriter
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
Cuts leading and trailing '/' from the given resource name.- Parameters:
resourceName- the absolute path of a resource- Returns:
- the trimmed resource name
-