⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmsimportexportmanager.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

    /** The initialized import/export handlers. */
    private List m_importExportHandlers;

    /** Import princial group translations. */
    private Map m_importGroupTranslations;

    /** 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 user export settings. */
    private CmsUserExportSettings m_userExportSettings;

    /** 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, or <code>null</code> if not found
     */
    public static Document getManifest(File resource) {

        try {
            if (resource.isFile()) {
                if (!resource.getName().toLowerCase().endsWith(".zip")) {
                    // skip non-ZIP files
                    return null;
                }
                // create a Reader for a ZIP file
                ZipFile zipFile = new ZipFile(resource);
                ZipEntry zipFileEntry = zipFile.getEntry(EXPORT_MANIFEST);
                if (zipFileEntry == null) {
                    throw new CmsImportExportException(Messages.get().container(
                        Messages.ERR_IMPORTEXPORT_FILE_NOT_FOUND_1,
                        EXPORT_MANIFEST));
                }
                InputStream input = null;
                try {
                    input = zipFile.getInputStream(zipFileEntry);
                    // transform the manifest.xml file into a dom4j Document
                    return new SAXReader().read(input);
                } finally {
                    try {
                        if (input != null) {
                            input.close();
                        }
                    } catch (Exception e) {
                        // noop
                    }
                }
            } else if (resource.isDirectory()) {
                // create a Reader for a file in the file system
                File manifestFile = new File(resource, EXPORT_MANIFEST);
                if (!manifestFile.exists()) {
                    throw new CmsImportExportException(Messages.get().container(
                        Messages.ERR_IMPORTEXPORT_FILE_NOT_FOUND_1,
                        EXPORT_MANIFEST));
                }
                Reader reader = null;
                try {
                    reader = new BufferedReader(new FileReader(manifestFile));
                    // transform the manifest.xml file into a dom4j Document
                    return new SAXReader().read(reader);
                } finally {
                    try {
                        if (reader != null) {
                            reader.close();
                        }
                    } catch (Exception e) {
                        // noop
                    }
                }
            }
        } catch (Throwable e) {
            if (LOG.isWarnEnabled()) {
                LOG.warn(
                    Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_ERROR_READING_MANIFEST_1, resource),
                    e);
            }
        }
        return null;
    }

    /**
     * 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 {

        OpenCms.getRoleManager().checkRole(cms, CmsRole.DATABASE_MANAGER);
        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 {@link 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 something goes wrong
     */
    public I_CmsImportExportHandler getImportExportHandler(String importFile) throws CmsImportExportException {

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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -