org.opencms.importexport
Class CmsImport

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

public class CmsImport
extends java.lang.Object

Holds the functionaility to import resources from the filesystem or a zip file into the OpenCms VFS.

Since:
6.0.0
Version:
$Revision: 1.45 $
Author:
Andreas Zahner, Alexander Kandzior, Michael Emmerich, Thomas Weckert

Field Summary
protected  CmsObject m_cms
          The cms context to do the operations with.
protected  org.dom4j.Document m_docXml
          The xml manifest-file.
protected  java.lang.String m_importFile
          The import-file to load resources from.
protected  java.util.List m_importImplementations
          Stores all import interface implementations .
protected  java.lang.String m_importPath
          The import-path to write resources into the cms.
protected  java.io.File m_importResource
          The import-resource (folder) to load resources from.
protected  int m_importVersion
          The version of this import, noted in the info tag of the manifest.xml.
protected  java.util.zip.ZipFile m_importZip
          The import-resource (zip) to load resources from.
protected  I_CmsReport m_report
          The object to report the log messages.
 
Constructor Summary
CmsImport()
          Constructs a new uninitialized import, required for special subclass data import.
CmsImport(CmsObject cms, java.lang.String importFile, java.lang.String importPath, I_CmsReport report)
          Constructs a new import object which imports the resources from an OpenCms export zip file or a folder in the "real" file system.
 
Method Summary
protected  void closeImportFile()
          Closes the import file.
static java.lang.String getChildElementTextValue(org.dom4j.Element parentElement, java.lang.String elementName)
          Returns the value of a child element with a specified name for a given parent element.
 java.util.List getConflictingFilenames()
          Returns a list of files which are both in the import and in the virtual file system.
protected  byte[] getFileBytes(java.lang.String filename)
          Returns a byte array containing the content of the file.
protected  void getImportResource()
          Gets the import resource and stores it in object-member.
 java.util.List getResourcesForProject()
          Returns a list of resource names that are needed to create a project for this import.
 void importResources()
          Imports the resources and writes them to the cms VFS, even if there already exist files with the same name.
protected  void openImportFile()
          Initalizes the import.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_cms

protected CmsObject m_cms
The cms context to do the operations with.


m_docXml

protected org.dom4j.Document m_docXml
The xml manifest-file.


m_importFile

protected java.lang.String m_importFile
The import-file to load resources from.


m_importImplementations

protected java.util.List m_importImplementations
Stores all import interface implementations .


m_importPath

protected java.lang.String m_importPath
The import-path to write resources into the cms.


m_importResource

protected java.io.File m_importResource
The import-resource (folder) to load resources from.


m_importVersion

protected int m_importVersion
The version of this import, noted in the info tag of the manifest.xml.

0 indicates an export file without a version number, that is before version 4.3.23 of OpenCms.
1 indicates an export file of OpenCms with a version before 5.0.0 2 indicates an export file of OpenCms with a version before 5.1.2 3 indicates an export file of OpenCms with a version before 5.1.6 4 indicates an export file of OpenCms with a version after 5.1.6


m_importZip

protected java.util.zip.ZipFile m_importZip
The import-resource (zip) to load resources from.


m_report

protected I_CmsReport m_report
The object to report the log messages.

Constructor Detail

CmsImport

public CmsImport()
Constructs a new uninitialized import, required for special subclass data import.


CmsImport

public CmsImport(CmsObject cms,
                 java.lang.String importFile,
                 java.lang.String importPath,
                 I_CmsReport report)
          throws CmsRoleViolationException
Constructs a new import object which imports the resources from an OpenCms export zip file or a folder in the "real" file system.

Parameters:
cms - the current cms object
importFile - the file or folder to import from
importPath - the path in the cms VFS to import into
report - a report object to output the progress information to
Throws:
CmsRoleViolationException - if the current user dies not have role permissions to import the database
Method Detail

getChildElementTextValue

public static java.lang.String getChildElementTextValue(org.dom4j.Element parentElement,
                                                        java.lang.String elementName)
Returns the value of a child element with a specified name for a given parent element.

Parameters:
parentElement - the parent element
elementName - the child element name
Returns:
the value of the child node, or null if something went wrong

getConflictingFilenames

public java.util.List getConflictingFilenames()
                                       throws CmsXmlException,
                                              CmsImportExportException
Returns a list of files which are both in the import and in the virtual file system.

Returns:
a list of Strings, complete path of the files
Throws:
CmsImportExportException - if the import file could not be opened
CmsXmlException - if the manifest of the import could not be unmarshalled

getResourcesForProject

public java.util.List getResourcesForProject()
                                      throws CmsImportExportException
Returns a list of resource names that are needed to create a project for this import.

It calls the method getConflictingFileNames if needed, to calculate these resources.

Returns:
a list of resource names that are needed to create a project for this import
Throws:
CmsImportExportException - if ZIP archive could not be closed

importResources

public void importResources()
                     throws CmsImportExportException,
                            CmsXmlException
Imports the resources and writes them to the cms VFS, even if there already exist files with the same name.

Throws:
CmsImportExportException - if something goes wrong
CmsXmlException - if the manifest of the import file could not be unmarshalled

closeImportFile

protected void closeImportFile()
                        throws CmsImportExportException
Closes the import file.

Throws:
CmsImportExportException - if the ZIP archive could not be closed

getFileBytes

protected byte[] getFileBytes(java.lang.String filename)
Returns a byte array containing the content of the file.

Parameters:
filename - the name of the file to read
Returns:
a byte array containing the content of the file

getImportResource

protected void getImportResource()
                          throws CmsImportExportException
Gets the import resource and stores it in object-member.

Throws:
CmsImportExportException - if the import file could not be opened

openImportFile

protected void openImportFile()
                       throws CmsXmlException,
                              CmsImportExportException
Initalizes the import.

Throws:
CmsImportExportException - if the import file could not be opened
CmsXmlException - if the manifest of the import could not be unmarshalled