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

📄 cmsmodulemanager.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                            cms.unlockResource(currentResource);
                        }
                    }
                } catch (CmsException e) {
                    // ignore the exception and delete the next resource
                    LOG.error(Messages.get().getBundle().key(Messages.LOG_DEL_MOD_EXC_1, currentResource), e);
                    report.println(e);
                }
            }

            report.println(Messages.get().container(Messages.RPT_PUBLISH_PROJECT_BEGIN_0), I_CmsReport.FORMAT_HEADLINE);

            // now unlock and publish the project
            cms.unlockProject(deleteProject.getUuid());
            OpenCms.getPublishManager().publishProject(cms, report);
            OpenCms.getPublishManager().waitWhileRunning();

            report.println(Messages.get().container(Messages.RPT_PUBLISH_PROJECT_END_0), I_CmsReport.FORMAT_HEADLINE);
            report.println(Messages.get().container(Messages.RPT_DELETE_MODULE_END_0), I_CmsReport.FORMAT_HEADLINE);
        } catch (CmsException e) {
            throw new CmsConfigurationException(e.getMessageContainer(), e);
        } finally {
            cms.getRequestContext().setCurrentProject(previousProject);
        }

        // initialize the export points (removes export points from deleted module)
        initModuleExportPoints();

        // update the configuration
        updateModuleConfiguration();

        // reinit the manager is nescessary
        if (removeResourceTypes) {
            OpenCms.getResourceManager().initialize(cms);
        }
    }

    /**
     * Returns a list of installed modules.<p>
     * 
     * @return a list of <code>{@link CmsModule}</code> objects
     */
    public List getAllInstalledModules() {

        return new ArrayList(m_modules.values());
    }

    /**
     * Returns the (immutable) list of configured module export points.<p>
     * 
     * @return the (immutable) list of configured module export points
     * @see CmsExportPoint
     */
    public Set getExportPoints() {

        return m_moduleExportPoints;
    }

    /**
     * Returns the module with the given module name,
     * or <code>null</code> if no module with the given name is configured.<p>
     * 
     * @param name the name of the module to return
     * @return the module with the given module name
     */
    public CmsModule getModule(String name) {

        return (CmsModule)m_modules.get(name);
    }

    /**
     * Returns the set of names of all the installed modules.<p>
     * 
     * @return the set of names of all the installed modules
     */
    public Set getModuleNames() {

        synchronized (m_modules) {
            return new HashSet(m_modules.keySet());
        }
    }

    /**
     * Checks if this module manager has a module with the given name installed.<p>
     * 
     * @param name the name of the module to check
     * @return true if this module manager has a module with the given name installed
     */
    public boolean hasModule(String name) {

        return m_modules.containsKey(name);
    }

    /**
     * Initializes all module instance classes managed in this module manager.<p>
     * 
     * @param cms an initialized CmsObject with "manage modules" role permissions
     * @param configurationManager the initialized OpenCms configuration manager
     * 
     * @throws CmsRoleViolationException if the provided OpenCms context does not have "manage modules" role permissions
     */
    public synchronized void initialize(CmsObject cms, CmsConfigurationManager configurationManager)
    throws CmsRoleViolationException {

        if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_1_CORE_OBJECT) {
            // certain test cases won't have an OpenCms context
            OpenCms.getRoleManager().checkRole(cms, CmsRole.DATABASE_MANAGER);
        }

        Iterator it;
        int count = 0;
        it = m_modules.keySet().iterator();
        while (it.hasNext()) {
            // get the module description
            CmsModule module = (CmsModule)m_modules.get(it.next());

            if (module.getActionClass() != null) {
                // create module instance class
                I_CmsModuleAction moduleAction = module.getActionInstance();
                if (module.getActionClass() != null) {
                    try {
                        moduleAction = (I_CmsModuleAction)Class.forName(module.getActionClass()).newInstance();
                    } catch (Exception e) {
                        CmsLog.INIT.info(Messages.get().getBundle().key(
                            Messages.INIT_CREATE_INSTANCE_FAILED_1,
                            module.getName()), e);
                    }
                }
                if (moduleAction != null) {
                    count++;
                    module.setActionInstance(moduleAction);
                    if (CmsLog.INIT.isInfoEnabled()) {
                        CmsLog.INIT.info(Messages.get().getBundle().key(
                            Messages.INIT_INITIALIZE_MOD_CLASS_1,
                            moduleAction.getClass().getName()));
                    }
                    try {
                        // create a copy of the adminCms so that each module instance does have 
                        // it's own context, a shared context might introduce side - effects
                        CmsObject adminCmsCopy = OpenCms.initCmsObject(cms);
                        // initialize the module
                        moduleAction.initialize(adminCmsCopy, configurationManager, module);
                    } catch (Throwable t) {
                        LOG.error(Messages.get().getBundle().key(
                            Messages.LOG_INSTANCE_INIT_ERR_1,
                            moduleAction.getClass().getName()), t);
                    }
                }
            }
        }

        // initialize the export points
        initModuleExportPoints();

        if (CmsLog.INIT.isInfoEnabled()) {
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_NUM_CLASSES_INITIALIZED_1, new Integer(count)));
        }
    }

    /**
     * Shuts down all module instance classes managed in this module manager.<p>
     */
    public synchronized void shutDown() {

        int count = 0;
        Iterator it = getModuleNames().iterator();
        while (it.hasNext()) {
            String moduleName = (String)it.next();
            // get the module
            CmsModule module = (CmsModule)m_modules.get(moduleName);
            if (module == null) {
                continue;
            }
            // get the module action instance            
            I_CmsModuleAction moduleAction = module.getActionInstance();
            if (moduleAction == null) {
                continue;
            }

            count++;
            if (CmsLog.INIT.isInfoEnabled()) {
                CmsLog.INIT.info(Messages.get().getBundle().key(
                    Messages.INIT_SHUTDOWN_MOD_CLASS_1,
                    moduleAction.getClass().getName()));
            }
            try {
                // shut down the module
                moduleAction.shutDown(module);
            } catch (Throwable t) {
                LOG.error(Messages.get().getBundle().key(
                    Messages.LOG_INSTANCE_SHUTDOWN_ERR_1,
                    moduleAction.getClass().getName()), t);
            }
        }

        if (CmsLog.INIT.isInfoEnabled()) {
            CmsLog.INIT.info(Messages.get().getBundle().key(
                Messages.INIT_SHUTDOWN_NUM_MOD_CLASSES_1,
                new Integer(count)));
        }

        if (CmsLog.INIT.isInfoEnabled()) {
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SHUTDOWN_1, this.getClass().getName()));
        }
    }

    /**
     * Updates a already configured module with new values.<p>
     * 
     * @param cms must be initialized with "Admin" permissions 
     * @param module the module to update
     * 
     * @throws CmsRoleViolationException if the required module manager role permissions are not available 
     * @throws CmsConfigurationException if a module with this name is not available for updateing 
     */
    public synchronized void updateModule(CmsObject cms, CmsModule module)
    throws CmsRoleViolationException, CmsConfigurationException {

        // check for module manager role permissions
        OpenCms.getRoleManager().checkRole(cms, CmsRole.DATABASE_MANAGER);

        CmsModule oldModule = (CmsModule)m_modules.get(module.getName());

        if (oldModule == null) {
            // module is not currently configured, no update possible
            throw new CmsConfigurationException(Messages.get().container(Messages.ERR_OLD_MOD_ERR_1, module.getName()));
        }

        if (LOG.isInfoEnabled()) {
            LOG.info(Messages.get().getBundle().key(Messages.LOG_MOD_UPDATE_1, module.getName()));
        }

        if (oldModule.getVersion().compareTo(module.getVersion()) == 0) {
            // module version has not changed - auto increment version number
            module.getVersion().increment();
        }
        // indicate that the version number was recently updated
        module.getVersion().setUpdated(true);

        // initialize (freeze) the module
        module.initialize(cms);

        // replace old version of module with new version
        m_modules.put(module.getName(), module);

        try {
            I_CmsModuleAction moduleAction = oldModule.getActionInstance();
            // handle module action instance if initialized
            if (moduleAction != null) {
                moduleAction.moduleUpdate(module);
                // set the old action instance
                // the new action instance will be used after a system restart
                module.setActionInstance(moduleAction);
            }
        } catch (Throwable t) {
            LOG.error(Messages.get().getBundle().key(Messages.LOG_INSTANCE_UPDATE_ERR_1, module.getName()), t);
        }

        // initialize the export points
        initModuleExportPoints();

        // update the configuration
        updateModuleConfiguration();
    }

    /**
     * Initializes the list of esport points from all configured modules.<p>
     */
    private synchronized void initModuleExportPoints() {

        Set exportPoints = new HashSet();
        Iterator i = m_modules.values().iterator();
        while (i.hasNext()) {
            CmsModule module = (CmsModule)i.next();
            List moduleExportPoints = module.getExportPoints();
            for (int j = 0; j < moduleExportPoints.size(); j++) {
                CmsExportPoint point = (CmsExportPoint)moduleExportPoints.get(j);
                if (exportPoints.contains(point)) {
                    if (LOG.isWarnEnabled()) {
                        LOG.warn(Messages.get().getBundle().key(
                            Messages.LOG_DUPLICATE_EXPORT_POINT_2,
                            point,
                            module.getName()));
                    }
                } else {
                    exportPoints.add(point);
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(Messages.get().getBundle().key(
                            Messages.LOG_ADD_EXPORT_POINT_2,
                            point,
                            module.getName()));
                    }
                }
            }
        }
        m_moduleExportPoints = Collections.unmodifiableSet(exportPoints);
    }

    /**
     * Updates the module configuration.<p>
     */
    private void updateModuleConfiguration() {

        OpenCms.writeConfiguration(CmsModuleConfiguration.class);
    }
}

⌨️ 快捷键说明

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