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

📄 cmsmodulemanager.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                List deps = (List)moduleDependencies.get(moduleName);
                if ((deps == null) || deps.isEmpty()) {
                    retList.add(moduleName);
                    Iterator itDeps = moduleDependencies.values().iterator();
                    while (itDeps.hasNext()) {
                        List dependencies = (List)itDeps.next();
                        dependencies.remove(moduleName);
                    }
                    finished = false;
                    itMods.remove();
                }
            }
        }
        if (!modules.isEmpty()) {
            throw new CmsIllegalStateException(Messages.get().container(
                Messages.ERR_MODULE_DEPENDENCY_CYCLE_1,
                modules.toString()));
        }
        Collections.reverse(retList);
        return retList;
    }

    /**
     * Adds a new module to the module manager.<p>
     * 
     * @param cms must be initialized with "Admin" permissions 
     * @param module the module to add
     * 
     * @throws CmsSecurityException if the required permissions are not available (i.e. no "Admin" CmsObject has been provided)
     * @throws CmsConfigurationException if a module with this name is already configured 
     */
    public synchronized void addModule(CmsObject cms, CmsModule module)
    throws CmsSecurityException, CmsConfigurationException {

        // check the role permissions
        OpenCms.getRoleManager().checkRole(cms, CmsRole.DATABASE_MANAGER);

        if (m_modules.containsKey(module.getName())) {
            // module is currently configured, no create possible
            throw new CmsConfigurationException(Messages.get().container(
                Messages.ERR_MODULE_ALREADY_CONFIGURED_1,
                module.getName()));

        }

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

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

        m_modules.put(module.getName(), module);

        try {
            I_CmsModuleAction moduleAction = module.getActionInstance();
            // handle module action instance if initialized
            if (moduleAction != null) {
                moduleAction.moduleUpdate(module);
            }
        } catch (Throwable t) {
            LOG.error(Messages.get().getBundle().key(Messages.LOG_MOD_UPDATE_ERR_1, module.getName()), t);
        }

        // initialize the export points
        initModuleExportPoints();

        // update the configuration
        updateModuleConfiguration();
    }

    /**
     * Checks if a modules depedencies are fulfilled.<p> 
     * 
     * The possible values for the <code>mode</code> parameter are:<dl>
     * <dt>{@link #DEPENDENCY_MODE_DELETE}</dt>
     *      <dd>Check for module deleting, i.e. are other modules dependent on the 
     *          given module?</dd>
     * <dt>{@link #DEPENDENCY_MODE_IMPORT}</dt>
     *      <dd>Check for module importing, i.e. are all dependencies required by the given
     *          module available?</dd></dl>
     * 
     * @param module the module to check the dependencies for
     * @param mode the dependency check mode
     * @return a list of dependencies that are not fulfilled, if empty all dependencies are fulfilled
     */
    public List checkDependencies(CmsModule module, int mode) {

        List result = new ArrayList();

        if (mode == DEPENDENCY_MODE_DELETE) {
            // delete mode, check if other modules depend on this module
            Iterator i = m_modules.values().iterator();
            while (i.hasNext()) {
                CmsModule otherModule = (CmsModule)i.next();
                CmsModuleDependency dependency = otherModule.checkDependency(module);
                if (dependency != null) {
                    // dependency found, add to list
                    result.add(new CmsModuleDependency(otherModule.getName(), otherModule.getVersion()));
                }
            }

        } else if (mode == DEPENDENCY_MODE_IMPORT) {
            // import mode, check if all module dependencies are fulfilled            
            Iterator i = m_modules.values().iterator();
            // add all dependencies that must be found
            result.addAll(module.getDependencies());
            while (i.hasNext() && (result.size() > 0)) {
                CmsModule otherModule = (CmsModule)i.next();
                CmsModuleDependency dependency = module.checkDependency(otherModule);
                if (dependency != null) {
                    // dependency found, remove from list
                    result.remove(dependency);
                }
            }
        } else {
            // invalid mode selected
            throw new CmsRuntimeException(Messages.get().container(
                Messages.ERR_CHECK_DEPENDENCY_INVALID_MODE_1,
                new Integer(mode)));
        }

        return result;
    }

    /**
     * Checks the module selection list for consistency, that means 
     * that if a module is selected, all its dependencies are also selected.<p>
     * 
     * The module dependencies are get from the installed modules or
     * from the module manifest.xml files found in the given FRS path.<p>
     * 
     * @param moduleNames a list of module names
     * @param rfsAbsPath a RFS absolute path to search for modules, or <code>null</code> to use the installed modules
     * @param forDeletion there are two modes, one for installation of modules, and one for deletion.
     * 
     * @throws CmsIllegalArgumentException if the module list is not consistent
     * @throws CmsConfigurationException if something goes wrong
     */
    public void checkModuleSelectionList(List moduleNames, String rfsAbsPath, boolean forDeletion)
    throws CmsIllegalArgumentException, CmsConfigurationException {

        Map moduleDependencies = buildDepsForAllModules(rfsAbsPath, forDeletion);
        Iterator itMods = moduleNames.iterator();
        while (itMods.hasNext()) {
            String moduleName = (String)itMods.next();
            List dependencies = (List)moduleDependencies.get(moduleName);
            if (dependencies != null) {
                List depModules = new ArrayList(dependencies);
                depModules.removeAll(moduleNames);
                if (!depModules.isEmpty()) {
                    throw new CmsIllegalArgumentException(Messages.get().container(
                        Messages.ERR_MODULE_SELECTION_INCONSISTENT_2,
                        moduleName,
                        depModules.toString()));
                }
            }
        }
    }

    /**
     * Deletes a module from the configuration.<p>
     * 
     * @param cms must be initialized with "Admin" permissions 
     * @param moduleName the name of the module to delete
     * @param replace indicates if the module is replaced (true) or finally deleted (false)
     * @param report the report to print progesss messages to
     * 
     * @throws CmsRoleViolationException if the required module manager role permissions are not available 
     * @throws CmsConfigurationException if a module with this name is not available for deleting
     */
    public synchronized void deleteModule(CmsObject cms, String moduleName, boolean replace, I_CmsReport report)
    throws CmsRoleViolationException, CmsConfigurationException {

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

        if (!m_modules.containsKey(moduleName)) {
            // module is not currently configured, no update possible
            throw new CmsConfigurationException(Messages.get().container(
                Messages.ERR_MODULE_NOT_CONFIGURED_1,
                moduleName));
        }

        if (LOG.isInfoEnabled()) {
            LOG.info(Messages.get().getBundle().key(Messages.LOG_DEL_MOD_1, moduleName));
        }

        CmsModule module = (CmsModule)m_modules.get(moduleName);
        boolean removeResourceTypes = !module.getResourceTypes().isEmpty();
        if (removeResourceTypes) {
            // mark the resource manager to reinitialize if necessary
            OpenCms.getWorkplaceManager().removeExplorerTypeSettings(module);
        }

        if (!replace) {
            // module is deleted, not replaced

            // perform dependency check
            List dependencies = checkDependencies(module, DEPENDENCY_MODE_DELETE);
            if (!dependencies.isEmpty()) {
                StringBuffer message = new StringBuffer();
                Iterator it = dependencies.iterator();
                while (it.hasNext()) {
                    message.append("  ").append(((CmsModuleDependency)it.next()).getName()).append("\r\n");
                }
                throw new CmsConfigurationException(Messages.get().container(
                    Messages.ERR_MOD_DEPENDENCIES_2,
                    moduleName,
                    message.toString()));
            }
            try {
                I_CmsModuleAction moduleAction = module.getActionInstance();
                // handle module action instance if initialized
                if (moduleAction != null) {
                    moduleAction.moduleUninstall(module);
                }
            } catch (Throwable t) {
                LOG.error(Messages.get().getBundle().key(Messages.LOG_MOD_UNINSTALL_ERR_1, moduleName), t);
            }
        }

        // now remove the module
        module = (CmsModule)m_modules.remove(moduleName);

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

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

            cms.getRequestContext().setCurrentProject(deleteProject);

            // copy the module resources to the project
            List projectFiles = module.getResources();
            for (int i = 0; i < projectFiles.size(); i++) {
                try {
                    String resourceName = (String)projectFiles.get(i);
                    if (cms.existsResource(resourceName, CmsResourceFilter.ALL)) {
                        cms.copyResourceToProject(resourceName);
                    }
                } catch (CmsException e) {
                    // may happen if the resource has already been deleted
                    LOG.error(
                        Messages.get().getBundle().key(Messages.LOG_MOVE_RESOURCE_FAILED_1, projectFiles.get(i)),
                        e);
                    report.println(e);
                }
            }

            report.print(Messages.get().container(Messages.RPT_DELETE_MODULE_BEGIN_0), I_CmsReport.FORMAT_HEADLINE);
            report.println(org.opencms.report.Messages.get().container(
                org.opencms.report.Messages.RPT_ARGUMENT_HTML_ITAG_1,
                moduleName), I_CmsReport.FORMAT_HEADLINE);

            // move through all module resources and delete them
            for (int i = 0; i < module.getResources().size(); i++) {
                String currentResource = null;
                try {
                    currentResource = (String)module.getResources().get(i);
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(Messages.get().getBundle().key(Messages.LOG_DEL_MOD_RESOURCE_1, currentResource));
                    }
                    CmsResource resource = null;
                    try {
                        resource = cms.readResource(currentResource, CmsResourceFilter.ALL);
                    } catch (CmsVfsResourceNotFoundException e) {
                        // ignore
                    }
                    if (resource != null) {
                        CmsLock lock = cms.getLock(currentResource);
                        if (lock.isUnlocked()) {
                            // lock the resource
                            cms.lockResource(currentResource);
                        } else if (lock.isLockableBy(cms.getRequestContext().currentUser())) {
                            // steal the resource
                            cms.changeLock(currentResource);
                        }
                        if (!resource.getState().isDeleted()) {
                            // delete the resource
                            cms.deleteResource(currentResource, CmsResource.DELETE_PRESERVE_SIBLINGS);
                        }
                        // update the report
                        report.print(Messages.get().container(Messages.RPT_DELETE_0), I_CmsReport.FORMAT_NOTE);
                        report.println(org.opencms.report.Messages.get().container(
                            org.opencms.report.Messages.RPT_ARGUMENT_1,
                            currentResource));
                        if (!resource.getState().isNew()) {
                            // unlock the resource (so it gets deleted with next publish)

⌨️ 快捷键说明

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