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

📄 cmsadminmodulenew.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                filecontent = cms.getRequestContext().getRequest().getFile(filename);
            }
            if (filecontent != null) {
                session.putValue(C_PARA_FILECONTENT, filecontent);
            }
            filecontent = (byte[]) session.getValue(C_PARA_FILECONTENT);

            // first create the folder if it doesnt exists
            File discFolder =
                new File(
                    com.opencms.boot.CmsBase.getAbsolutePath(cms.readExportPath())
                        + "/"
                        + I_CmsRegistry.C_MODULE_PATH);
            if (!discFolder.exists()) {
                boolean success = discFolder.mkdir();
                if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING
                    && A_OpenCms.isLogging()
                    && (!success)) {
                    A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INFO,
                        "[CmsAccessFilesystem] Couldn't create folder "
                            + com.opencms.boot.CmsBase.getAbsolutePath(cms.readExportPath())
                            + "/"
                            + I_CmsRegistry.C_MODULE_PATH
                            + ".");
                }
            }

            // now write the file into the modules dierectory in the exportpaht
            File discFile =
                new File(com.opencms.boot.CmsBase.getAbsolutePath(cms.readExportPath())
                    + "/" + I_CmsRegistry.C_MODULE_PATH + filename);
            try {

                // write the new file to disk
                OutputStream s = new FileOutputStream(discFile);
                s.write(filecontent);
                s.close();
            } catch (Exception e) {
                throw new CmsException("[" + this.getClass().getName() + "] " + e.getMessage());
            }
            session.removeValue(C_MODULE_NAV);
            templateSelector = 
                importModule(cms, reg, xmlTemplateDocument, session,
                    com.opencms.boot.CmsBase.getAbsolutePath(cms.readExportPath())
                        + "/"
                        + I_CmsRegistry.C_MODULE_PATH
                        + filename);
                        
        } else if ("serverupload".equals(step)) {
            String filename = (String) parameters.get("moduleselect");
            session.removeValue(C_MODULE_NAV);
            if ((filename == null) || ("".equals(filename))) {
                templateSelector = C_DONE;
            } else {
                templateSelector = 
                    importModule(cms, reg, xmlTemplateDocument, session,
                        com.opencms.boot.CmsBase.getAbsolutePath(cms.readExportPath())
                            + "/"
                            + I_CmsRegistry.C_MODULE_PATH
                            + filename);
            }
        }

        // Now load the template file and start the processing
        return startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
    }

    /**
     * Imports the file zipName.
     * Creation date: (05.09.00 10:17:56)
     * @param reg com.opencms.file.I_CmsRegistry
     * @param zipName the complete path and name of the zip-file to import.
     * @return the new templateSelector.
     */
    private String importModule(CmsObject cms, I_CmsRegistry reg, CmsXmlTemplateFile xmlDocument, I_CmsSession session, String zipName) throws CmsException {
        String nav = (String)session.getValue(C_MODULE_NAV);
        Vector conflictFiles = null;
        String moduleName = null;
        boolean importNewModule = true;
        String moduleType = I_CmsRegistry.C_MODULE_TYPE_TRADITIONAL;
        
        if(nav == null) {
            // this is the first go. Try to import the module and if it dont't work return the corresponding errorpage
            Map moduleInfo = reg.importGetModuleInfo(zipName);
            
            moduleName = (String)moduleInfo.get("name");
            moduleType = (String)moduleInfo.get("type");
            
            if(reg.moduleExists(moduleName)) {
                if (! I_CmsRegistry.C_MODULE_TYPE_SIMPLE.equals(moduleType)) {
                    // not a simple module, can not be replaced
                    xmlDocument.setData("name", moduleName);
                    xmlDocument.setData("version", "" + reg.getModuleVersion(moduleName));
                    session.removeValue(C_MODULE_NAV);
                    return C_ERRORREPLACE;
                } else {
                    // simple module, start module replacement
                    session.putValue(C_MODULE_NAME, moduleName);                    
                    importNewModule = false;
                }
            }
            Vector needs = reg.importCheckDependencies(zipName, true);
            if(!needs.isEmpty()) {
                // there are dependences not fulfilled
                xmlDocument.setData("name", moduleName);
                xmlDocument.setData("version", "" + reg.getModuleVersion(moduleName));
                String preconditions = "";
                for(int i = 0;i < needs.size();i++) {
                    preconditions += "<br><br>" + needs.elementAt(i);
                }
                xmlDocument.setData("precondition", preconditions);
                session.removeValue(C_MODULE_NAV);
                return C_ERRORDEP;
            }
            if (! I_CmsRegistry.C_MODULE_TYPE_SIMPLE.equals(moduleType)) {
                conflictFiles = reg.importGetConflictingFileNames(zipName);
                if (!conflictFiles.isEmpty()) {
                    session.putValue(C_SESSION_MODULE_VECTOR, conflictFiles);
                    session.putValue(C_MODULE_NAV, C_FILES);
                    session.putValue(C_MODULE_FILENAME, zipName);
                    return C_FILES;
                }
            } else {
                // simple module, no "confict file" check performed
                conflictFiles = new Vector();
            }
            
        }
        else {
            if(C_FILES.equals(nav)) {
                zipName = (String)session.getValue(C_MODULE_FILENAME);
                moduleName = (String)session.getValue(C_MODULE_NAME);
                if (moduleName != null) importNewModule = false; 
                conflictFiles = (Vector)session.getValue(C_SESSION_MODULE_VECTOR);
                session.removeValue(C_MODULE_NAV);
            }
        }
        	
        // add root folder as file list for the project
        Vector projectFiles = new Vector();
        projectFiles.add("/");
        if (importNewModule) {
            A_CmsReportThread doTheImport = new CmsAdminModuleImportThread(cms, reg, moduleName, zipName, conflictFiles, projectFiles);
            doTheImport.start();
            session.putValue(C_MODULE_THREAD, doTheImport);
        } else {
            A_CmsReportThread doTheReplace = new CmsAdminModuleReplaceThread(cms, reg, moduleName, zipName, conflictFiles, projectFiles);
            doTheReplace.start();
            session.putValue(C_MODULE_THREAD, doTheReplace);
        }
        xmlDocument.setData("time", "5");      
        return "showresult";                
    }

    /**
     * Indicates if the results of this class are cacheable.
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
     */
    public boolean isCacheable(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
        return false;
    }
}

⌨️ 快捷键说明

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