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

📄 cmsmoduleimportexporthandler.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * 
     * @return the name of the export file in the real file system
     */
    public String getFileName() {

        return m_fileName;
    }

    /**
     * Returns the (package) name of the module to be exported.<p>
     * 
     * @return the (package) name of the module to be exported
     */
    public String getModuleName() {

        return m_moduleName;
    }

    /**
     * Returns the VFS resources to be exported additionally with the module as a list.<p>
     * 
     * @return the VFS resources to be exported additionally with the module as a list
     */
    public List getResourcesAsList() {

        return m_additionalResources;
    }

    /**
     * @see org.opencms.importexport.I_CmsImportExportHandler#importData(org.opencms.file.CmsObject, java.lang.String, java.lang.String, org.opencms.report.I_CmsReport)
     */
    public synchronized void importData(CmsObject cms, String importFile, String importPath, I_CmsReport report)
    throws CmsXmlException, CmsImportExportException, CmsRoleViolationException, CmsException {

        CmsProject previousProject = cms.getRequestContext().currentProject();
        try {

            importFile = importFile.replace('\\', '/');
            String moduleZipName = importFile.substring(importFile.lastIndexOf('/') + 1);
            String modulePackageName;

            if (moduleZipName.toLowerCase().endsWith(".zip")) {
                modulePackageName = moduleZipName.substring(0, moduleZipName.lastIndexOf('.'));
                int pos = modulePackageName.lastIndexOf('_');
                if (pos > 0) {
                    modulePackageName = modulePackageName.substring(0, pos);
                }
            } else {
                modulePackageName = moduleZipName;
            }

            CmsProject importProject = null;

            try {
                cms.getRequestContext().saveSiteRoot();
                cms.getRequestContext().setSiteRoot("/");

                try {
                    // try to read a (leftover) module import project
                    importProject = cms.readProject(Messages.get().getBundle(cms.getRequestContext().getLocale()).key(
                        Messages.GUI_IMPORT_MODULE_PROJECT_NAME_1,
                        new Object[] {modulePackageName}));
                } catch (CmsException e) {
                    // create a Project to import the module
                    importProject = cms.createProject(
                        Messages.get().getBundle(cms.getRequestContext().getLocale()).key(
                            Messages.GUI_IMPORT_MODULE_PROJECT_NAME_1,
                            new Object[] {modulePackageName}),
                        Messages.get().getBundle(cms.getRequestContext().getLocale()).key(
                            Messages.GUI_IMPORT_MODULE_PROJECT_DESC_1,
                            new Object[] {modulePackageName}),
                        OpenCms.getDefaultUsers().getGroupAdministrators(),
                        OpenCms.getDefaultUsers().getGroupAdministrators(),
                        CmsProject.PROJECT_TYPE_TEMPORARY);
                }

                cms.getRequestContext().setCurrentProject(importProject);

                // copy the root folder to the project
                cms.copyResourceToProject("/");
            } finally {
                cms.getRequestContext().restoreSiteRoot();
            }

            report.print(Messages.get().container(Messages.RPT_IMPORT_MODULE_BEGIN_0), I_CmsReport.FORMAT_HEADLINE);
            if (report instanceof CmsHtmlReport) {
                report.print(org.opencms.report.Messages.get().container(
                    org.opencms.report.Messages.RPT_ARGUMENT_1,
                    "<i>" + modulePackageName + "</i>"));
            } else {
                report.print(org.opencms.report.Messages.get().container(
                    org.opencms.report.Messages.RPT_ARGUMENT_1,
                    modulePackageName));
            }
            report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));

            importModule(cms, importFile, report);

            report.println(Messages.get().container(Messages.RPT_PUBLISH_PROJECT_BEGIN_0), I_CmsReport.FORMAT_HEADLINE);
            // now unlock and publish the project
            cms.unlockProject(importProject.getId());
            cms.publishProject(report);

            report.println(Messages.get().container(Messages.RPT_PUBLISH_PROJECT_END_0), I_CmsReport.FORMAT_HEADLINE);
            report.println(Messages.get().container(Messages.RPT_IMPORT_MODULE_END_0), I_CmsReport.FORMAT_HEADLINE);
        } finally {
            cms.getRequestContext().setCurrentProject(previousProject);
        }
    }

    /**
     * @see org.opencms.importexport.I_CmsImportExportHandler#matches(org.dom4j.Document)
     */
    public boolean matches(Document manifest) {

        Element rootElement = manifest.getRootElement();

        boolean hasModuleNode = (rootElement.selectNodes("./module/name").size() > 0);
        return (hasModuleNode);
    }

    /**
     * Sets the VFS resources to be exported additionally with the module.<p>
     * 
     * @param resources the VFS resources to be exported additionally with the module
     */
    public void setAdditionalResources(String[] resources) {

        m_additionalResources = Arrays.asList(resources);
    }

    /**
     * @see org.opencms.importexport.I_CmsImportExportHandler#setDescription(java.lang.String)
     */
    public void setDescription(String description) {

        m_description = description;
    }

    /**
     * Sets the name of the export file in the real file system.<p>
     * 
     * @param fileName the name of the export file in the real file system
     */
    public void setFileName(String fileName) {

        m_fileName = fileName;
    }

    /**
     * Will be called by the digester if a module was imported.<p>
     * 
     * @param moduleHandler contains the imported module
     */
    public void setModule(CmsModuleXmlHandler moduleHandler) {

        m_importedModule = moduleHandler.getModule();
    }

    /**
     * Sets the (package) name of the module to be exported.<p>
     * 
     * @param moduleName the (package) name of the module to be exported
     */
    public void setModuleName(String moduleName) {

        m_moduleName = moduleName;
    }

    /**
     * @see java.lang.Object#finalize()
     */
    protected void finalize() throws Throwable {

        try {
            if (m_additionalResources != null) {
                m_additionalResources.clear();
            }
            m_additionalResources = null;
        } catch (Exception e) {
            // noop
        } finally {
            super.finalize();
        }
    }

    /**
     * Returns the module imported with the digester.<p>
     * 
     * @return the module imported with the digester
     */
    private CmsModule getModule() {

        return m_importedModule;
    }

    /**
     * Imports a module from a external file source.<p>
     * 
     * @param cms must have been initialized with "Admin" permissions 
     * @param importResource the name of the input source
     * @param report the report to print the progess information to
     * @throws CmsSecurityException if no "Admin" permissions are available
     * @throws CmsConfigurationException if the module is already installed or the 
     *      dependencies are not fulfilled
     * @throws CmsException if errors occur reading the module data
     */
    private synchronized void importModule(CmsObject cms, String importResource, I_CmsReport report)
    throws CmsSecurityException, CmsConfigurationException, CmsException {

        // check if the user has the required permissions
        cms.checkRole(CmsRole.MODULE_MANAGER);

        // read the module from the import file
        CmsModule importedModule = readModuleFromImport(importResource);

        // check if the module is already istalled
        if (OpenCms.getModuleManager().hasModule(importedModule.getName())) {
            throw new CmsConfigurationException(Messages.get().container(
                Messages.ERR_MOD_ALREADY_INSTALLED_1,
                importedModule.getName()));
        }

        // check the module dependencies
        List dependencies = OpenCms.getModuleManager().checkDependencies(
            importedModule,
            CmsModuleManager.DEPENDENCY_MODE_IMPORT);
        if (dependencies.size() > 0) {
            // some dependencies not fulfilled
            StringBuffer missingModules = new StringBuffer();
            Iterator it = dependencies.iterator();
            while (it.hasNext()) {
                CmsModuleDependency dependency = (CmsModuleDependency)it.next();
                missingModules.append("  ").append(dependency.getName()).append(", Version ").append(
                    dependency.getVersion()).append("\r\n");
            }
            throw new CmsConfigurationException(Messages.get().container(
                Messages.ERR_MOD_DEPENDENCY_INFO_2,
                importedModule.getName() + ", Version " + importedModule.getVersion(),
                missingModules));
        }

        //  add the imported module to the module manager
        OpenCms.getModuleManager().addModule(cms, importedModule);

        // reinitialize the resource manager with additional module resourcetypes if nescessary
        if (importedModule.getResourceTypes() != Collections.EMPTY_LIST) {
            OpenCms.getResourceManager().initialize(cms);
        }
        // reinitialize the workplace manager with addititonal module explorertypes if nescessary
        if (importedModule.getExplorerTypes() != Collections.EMPTY_LIST) {
            OpenCms.getWorkplaceManager().addExplorerTypeSettings(importedModule);
        }

        // import the module resources
        CmsImport cmsImport = new CmsImport(cms, importResource, "/", report);
        cmsImport.importResources();
    }
}

⌨️ 快捷键说明

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