?? cmsimportexportmanager.java
字號:
/** Import princial user translations. */
private Map m_importUserTranslations;
/** The configured import versions class names. */
private List m_importVersionClasses;
/** Boolean flag whether colliding resources should be overwritten during the import. */
private boolean m_overwriteCollidingResources;
/** The URL of a 4.x OpenCms app. to import content correct into 5.x OpenCms apps. */
private String m_webAppUrl;
/**
* Creates a new instance for the import/export manager, will be called by the import/export configuration manager.
*/
public CmsImportExportManager() {
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(Messages.INIT_IMPORTEXPORT_INITIALIZING_0));
}
m_importExportHandlers = new ArrayList();
m_immutableResources = new ArrayList();
m_ignoredProperties = new ArrayList();
m_convertToXmlPage = true;
m_importGroupTranslations = new HashMap();
m_importUserTranslations = new HashMap();
m_overwriteCollidingResources = true;
m_importVersionClasses = new ArrayList();
}
/**
* Returns the "manifest.xml" of an available import resource as a dom4j document.<p>
*
* The manifest is either read as a ZIP entry, or from a subfolder of the specified
* file resource.<p>
*
* @param resource a File resource
* @return the "manifest.xml" as a dom4j document
*/
public static Document getManifest(File resource) {
Document manifest = null;
ZipFile zipFile = null;
ZipEntry zipFileEntry = null;
InputStream input = null;
Reader reader = null;
SAXReader saxReader = null;
File manifestFile = null;
try {
if (resource.isFile()) {
if (!resource.getName().toLowerCase().endsWith(".zip")) {
// skip non-ZIP files
return null;
}
// create a Reader for a ZIP file
zipFile = new ZipFile(resource);
zipFileEntry = zipFile.getEntry(EXPORT_MANIFEST);
input = zipFile.getInputStream(zipFileEntry);
// transform the manifest.xml file into a dom4j Document
saxReader = new SAXReader();
manifest = saxReader.read(input);
} else if (resource.isDirectory()) {
// create a Reader for a file in the file system
manifestFile = new File(resource, EXPORT_MANIFEST);
reader = new BufferedReader(new FileReader(manifestFile));
// transform the manifest.xml file into a dom4j Document
saxReader = new SAXReader();
manifest = saxReader.read(reader);
}
} catch (Exception e) {
if (LOG.isDebugEnabled()) {
LOG.debug(
Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_ERROR_READING_MANIFEST_1, resource),
e);
}
manifest = null;
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (Exception e) {
// noop
}
}
return manifest;
}
/**
* Adds a property name to the list of properties that should be removed from imported resources.<p>
*
* @param propertyName a property name
*/
public void addIgnoredProperty(String propertyName) {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_IGNORING_PROPERTY_1, propertyName));
}
m_ignoredProperties.add(propertyName);
}
/**
* Adds a resource to the list of immutable resources that should remain
* unchanged when resources are imported.<p>
*
* @param immutableResource a resources uri in the OpenCms VFS
*/
public void addImmutableResource(String immutableResource) {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_IMPORTEXPORT_ADDED_IMMUTABLE_RESOURCE_1,
immutableResource));
}
m_immutableResources.add(immutableResource);
}
/**
* Adds an import/export handler to the list of configured handlers.<p>
*
* @param handler the import/export handler to add
*/
public void addImportExportHandler(I_CmsImportExportHandler handler) {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_ADDED_IMPORTEXPORT_HANDLER_1, handler));
}
m_importExportHandlers.add(handler);
}
/**
* Adds an import princial translation to the configuration.<p>
*
* @param type the princial type ("USER" or "GROUP")
* @param from the "from" translation source
* @param to the "to" translation target
*/
public void addImportPrincipalTranslation(String type, String from, String to) {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_IMPORTEXPORT_ADDED_PRINCIPAL_TRANSLATION_3,
type,
from,
to));
}
if (I_CmsPrincipal.PRINCIPAL_GROUP.equalsIgnoreCase(type)) {
m_importGroupTranslations.put(from, to);
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(Messages.INIT_IMPORTEXPORT_ADDED_GROUP_TRANSLATION_2, from, to));
}
} else if (I_CmsPrincipal.PRINCIPAL_USER.equalsIgnoreCase(type)) {
m_importUserTranslations.put(from, to);
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(Messages.INIT_IMPORTEXPORT_ADDED_USER_TRANSLATION_2, from, to));
}
}
}
/**
* Adds a import version class name to the configuration.<p>
*
* @param importVersionClass the import version class name to add
*/
public void addImportVersionClass(I_CmsImport importVersionClass) {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_IMPORTEXPORT_ADDED_IMPORT_VERSION_1,
importVersionClass));
}
m_importVersionClasses.add(importVersionClass);
}
/**
* Checks if imported pages should be converted into XML pages.<p>
*
* @return true, if imported pages should be converted into XML pages
*/
public boolean convertToXmlPage() {
return m_convertToXmlPage;
}
/**
* Checks if the current user has permissions to export Cms data of a specified export handler,
* and if so, triggers the handler to write the export.<p>
*
* @param cms the current OpenCms context object
* @param handler handler containing the export data
* @param report a Cms report to print log messages
* @throws CmsRoleViolationException if the current user is not a allowed to export the OpenCms database
* @throws CmsImportExportException if operation was not successful
* @throws CmsConfigurationException if something goes wrong
* @see I_CmsImportExportHandler
*/
public void exportData(CmsObject cms, I_CmsImportExportHandler handler, I_CmsReport report)
throws CmsConfigurationException, CmsImportExportException, CmsRoleViolationException {
cms.checkRole(CmsRole.EXPORT_DATABASE);
handler.exportData(cms, report);
}
/**
* Returns the list of property keys that should be removed from imported resources.<p>
*
* @return the list of property keys that should be removed from imported resources, or Collections.EMPTY_LIST
*/
public List getIgnoredProperties() {
return m_ignoredProperties;
}
/**
* Returns the list of immutable resources that should remain unchanged when resources are
* imported.<p>
*
* Certain system resources should not be changed during import. This is the case for the main
* folders in the /system/ folder. Changes to these folders usually should not be imported to
* another system.<p>
*
* @return the list of immutable resources, or Collections.EMPTY_LIST
*/
public List getImmutableResources() {
return m_immutableResources;
}
/**
* Returns an instance of an import/export handler implementation that is able to import
* a specified resource.<p>
*
* @param importFile the name (absolute path) of the resource (zipfile or folder) to be imported
* @return an instance of an import/export handler implementation
* @throws CmsImportExportException if somethong goes wrong
*/
public I_CmsImportExportHandler getImportExportHandler(String importFile) throws CmsImportExportException {
Document manifest = null;
I_CmsImportExportHandler handler = null;
File file = new File(importFile);
if (!file.exists()) {
// file does not exist
CmsMessageContainer message = Messages.get().container(
Messages.ERR_IMPORTEXPORT_ERROR_IMPORT_FILE_DOES_NOT_EXIST_1,
importFile);
if (LOG.isDebugEnabled()) {
LOG.debug(message.key());
}
throw new CmsImportExportException(message);
}
manifest = getManifest(file);
for (int i = 0; i < m_importExportHandlers.size(); i++) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -