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

📄 cmssetupbean.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            OpenCmsServlet.SERVLET_PARAM_OPEN_CMS_SERVLET);

        // read the the default context name from the servlet context parameters
        String defaultWebApplication = pageContext.getServletContext().getInitParameter(
            OpenCmsServlet.SERVLET_PARAM_DEFAULT_WEB_APPLICATION);

        m_servletConfig = pageContext.getServletConfig();

        init(webAppRfsPath, servletMapping, defaultWebApplication);
    }

    /** 
     * Creates a new instance of the setup Bean.<p>
     * 
     * @param webAppRfsPath path to the OpenCms web application
     * @param servletMapping the OpenCms servlet mapping
     * @param defaultWebApplication the name of the default web application
     * 
     */
    public void init(String webAppRfsPath, String servletMapping, String defaultWebApplication) {

        try {
            // explicit set to null to overwrite exiting values from session
            m_availableModules = null;
            m_databaseKey = null;
            m_databaseKeys = null;
            m_databaseProperties = null;
            m_extProperties = null;
            m_installModules = null;
            m_moduleDependencies = null;
            m_sortedDatabaseKeys = null;
            m_moduleFilenames = null;

            if (servletMapping == null) {
                servletMapping = "/opencms/*";
            }
            if (defaultWebApplication == null) {
                defaultWebApplication = "ROOT";
            }
            m_servletMapping = servletMapping;
            m_defaultWebApplication = defaultWebApplication;

            setWebAppRfsPath(webAppRfsPath);
            m_errors = new ArrayList();

            if (CmsStringUtil.isNotEmpty(webAppRfsPath)) {
                // workaround for JUnit test cases, this must not be executed in a test case
                m_extProperties = loadProperties(m_configRfsPath + CmsSystemInfo.FILE_PROPERTIES);
                readDatabaseConfig();
            }

            if (m_workplaceImportThread != null) {
                if (m_workplaceImportThread.isAlive()) {
                    m_workplaceImportThread.kill();
                }
                m_workplaceImportThread = null;
                m_newLoggingOffset = 0;
                m_oldLoggingOffset = 0;
            }
        } catch (Exception e) {
            e.printStackTrace();
            m_errors.add(e.toString());
        }
    }

    /**
     * This method reads the properties from the htmlmsg.property file
     * and sets the HTML part properties with the matching values.<p>
     */
    public void initHtmlParts() {

        if (m_htmlProps != null) {
            // html already initialized
            return;
        }
        try {
            m_htmlProps = new Properties();
            m_htmlProps.load(getClass().getClassLoader().getResourceAsStream(HTML_MESSAGE_FILE));
        } catch (Exception e) {
            e.printStackTrace();
            m_errors.add(e.toString());
        }
    }

    /**
     * @see org.opencms.main.I_CmsShellCommands#initShellCmsObject(org.opencms.file.CmsObject, org.opencms.main.CmsShell)
     */
    public void initShellCmsObject(CmsObject cms, CmsShell shell) {

        m_cms = cms;
    }

    /**
     * Over simplistic helper to compare two strings to check radio buttons.
     * 
     * @param value1 the first value 
     * @param value2 the second value
     * @return "checked" if both values are equal, the empty String "" otherwise
     */
    public String isChecked(String value1, String value2) {

        if ((value1 == null) || (value2 == null)) {
            return "";
        }

        if (value1.trim().equalsIgnoreCase(value2.trim())) {
            return "checked";
        }

        return "";
    }

    /**
     * Returns true if this setup bean is correctly initialized.<p>
     * 
     * @return true if this setup bean is correctly initialized
     */
    public boolean isInitialized() {

        return m_extProperties != null;
    }

    /**
     * Returns js code with array definition for the available module dependencies.<p> 
     * 
     * @return js code
     */
    public String jsModuleDependencies() {

        List moduleNames = sortModules(getAvailableModules().values());

        StringBuffer jsCode = new StringBuffer(1024);
        jsCode.append("\t// an array holding the dependent modules for the n-th module\n");
        jsCode.append("\tvar moduleDependencies = new Array(");
        jsCode.append(moduleNames.size());
        jsCode.append(");\n");
        for (int i = 0; i < moduleNames.size(); i++) {
            String moduleName = (String)moduleNames.get(i);
            List dependencies = (List)getModuleDependencies().get(moduleName);
            jsCode.append("\tmoduleDependencies[" + i + "] = new Array(");
            if (dependencies != null) {
                for (int j = 0; j < dependencies.size(); j++) {
                    jsCode.append("\"" + dependencies.get(j) + "\"");
                    if (j < dependencies.size() - 1) {
                        jsCode.append(", ");
                    }
                }
            }
            jsCode.append(");\n");
        }
        jsCode.append("\n\n");
        return jsCode.toString();
    }

    /**
     * Returns js code with array definition for the available module names.<p> 
     * 
     * @return js code
     */
    public String jsModuleNames() {

        List moduleNames = sortModules(getAvailableModules().values());
        StringBuffer jsCode = new StringBuffer(1024);
        jsCode.append("\t// an array from 1...n holding the module package names\n");
        jsCode.append("\tvar modulePackageNames = new Array(");
        jsCode.append(moduleNames.size());
        jsCode.append(");\n");
        for (int i = 0; i < moduleNames.size(); i++) {
            String moduleName = (String)moduleNames.get(i);
            jsCode.append("\tmodulePackageNames[" + i + "] = \"" + moduleName + "\";\n");
        }
        jsCode.append("\n\n");
        return jsCode.toString();
    }

    /**
     * Loads the default OpenCms properties.<p>
     * 
     * @param file the file tp read the properties from
     * @return the initialized OpenCms properties
     * @throws IOException in case of IO errors 
     */
    public ExtendedProperties loadProperties(String file) throws IOException {

        return CmsPropertyUtils.loadProperties(file);
    }

    /**
     * Locks (i.e. disables) the setup wizard.<p>
     *
     */
    public void lockWizard() {

        setExtProperty("wizard.enabled", CmsStringUtil.FALSE);
    }

    /**
     * Prepares step 10 of the setup wizard.<p>
     */
    public void prepareStep10() {

        if (isInitialized()) {
            // lock the wizard for further use 
            lockWizard();
            // save Properties to file "opencms.properties" 
            saveProperties(getProperties(), CmsSystemInfo.FILE_PROPERTIES, false);
        }
    }

    /**
     * Prepares step 8 of the setup wizard.<p>
     * 
     * @return true if the workplace should be imported
     * 
     * @throws CmsXmlException if something goes wrong
     */
    public boolean prepareStep8() throws CmsXmlException {

        if (isInitialized()) {
            checkEthernetAddress();
            // backup the XML configuration
            backupConfiguration(
                CmsImportExportConfiguration.DEFAULT_XML_FILE_NAME,
                CmsImportExportConfiguration.DEFAULT_XML_FILE_NAME + CmsConfigurationManager.POSTFIX_ORI);
            backupConfiguration(
                CmsModuleConfiguration.DEFAULT_XML_FILE_NAME,
                CmsModuleConfiguration.DEFAULT_XML_FILE_NAME + CmsConfigurationManager.POSTFIX_ORI);
            backupConfiguration(
                CmsSearchConfiguration.DEFAULT_XML_FILE_NAME,
                CmsSearchConfiguration.DEFAULT_XML_FILE_NAME + CmsConfigurationManager.POSTFIX_ORI);
            backupConfiguration(
                CmsSystemConfiguration.DEFAULT_XML_FILE_NAME,
                CmsSystemConfiguration.DEFAULT_XML_FILE_NAME + CmsConfigurationManager.POSTFIX_ORI);
            backupConfiguration(CmsVfsConfiguration.DEFAULT_XML_FILE_NAME, CmsVfsConfiguration.DEFAULT_XML_FILE_NAME
                + CmsConfigurationManager.POSTFIX_ORI);
            backupConfiguration(
                CmsWorkplaceConfiguration.DEFAULT_XML_FILE_NAME,
                CmsWorkplaceConfiguration.DEFAULT_XML_FILE_NAME + CmsConfigurationManager.POSTFIX_ORI);
            backupConfiguration(
                CmsConfigurationManager.DEFAULT_XML_FILE_NAME,
                CmsConfigurationManager.DEFAULT_XML_FILE_NAME + CmsConfigurationManager.POSTFIX_ORI);
            // save Properties to file "opencms.properties" 
            saveProperties(getProperties(), CmsSystemInfo.FILE_PROPERTIES, true);

            CmsSetupTestResult testResult = new CmsSetupTestSimapi().execute(this);
            if (testResult.getResult().equals(I_CmsSetupTest.RESULT_FAILED)) {
                // "/opencms/vfs/resources/resourceloaders/loader[@class='org.opencms.loader.CmsImageLoader']/param[@name='image.scaling.enabled']";
                StringBuffer xp = new StringBuffer(256);
                xp.append("/").append(CmsConfigurationManager.N_ROOT);
                xp.append("/").append(CmsVfsConfiguration.N_VFS);
                xp.append("/").append(CmsVfsConfiguration.N_RESOURCES);
                xp.append("/").append(CmsVfsConfiguration.N_RESOURCELOADERS);
                xp.append("/").append(CmsVfsConfiguration.N_LOADER);
                xp.append("[@").append(I_CmsXmlConfiguration.A_CLASS);
                xp.append("='").append(CmsImageLoader.class.getName());
                xp.append("']/").append(I_CmsXmlConfiguration.N_PARAM);
                xp.append("[@").append(I_CmsXmlConfiguration.A_NAME);
                xp.append("='").append(CmsImageLoader.CONFIGURATION_SCALING_ENABLED).append("']");

                getXmlHelper().setValue(
                    CmsVfsConfiguration.DEFAULT_XML_FILE_NAME,
                    xp.toString(),
                    Boolean.FALSE.toString());
            }
            // /opencms/system/sites/workplace-server
            StringBuffer xp = new StringBuffer(256);
            xp.append("/").append(CmsConfigurationManager.N_ROOT);
            xp.append("/").append(CmsSystemConfiguration.N_SYSTEM);
            xp.append("/").append(CmsSystemConfiguration.N_SITES);
            xp.append("/").append(CmsSystemConfiguration.N_WORKPLACE_SERVER);

            getXmlHelper().setValue(CmsSystemConfiguration.DEFAULT_XML_FILE_NAME, xp.toString(), getWorkplaceSite());

            // /opencms/system/sites/site[@uri='/sites/default/']/@server
            xp = new StringBuffer(256);
            xp.append("/").append(CmsConfigurationManager.N_ROOT);
            xp.append("/").append(CmsSystemConfiguration.N_SYSTEM);
            xp.append("/").append(CmsSystemConfiguration.N_SITES);
            xp.append("/").append(I_CmsXmlConfiguration.N_SITE);
            xp.append("[@").append(I_CmsXmlConfiguration.A_URI);
            xp.append("='").append(CmsResource.VFS_FOLDER_SITES);
            xp.append("/default/']/@").append(CmsSystemConfiguration.A_SERVER);

            getXmlHelper().setValue(CmsSystemConfiguration.DEFAULT_XML_FILE_NAME, xp.toString(), getWorkplaceSite());

            getXmlHelper().writeAll();
        }
        return true;
    }

    /**
     * Prepares step 8b of the setup wizard.<p>
     */
    public void prepareStep8b() {

        if (!isInitialized()) {
            return;
        }

        if ((m_workplaceImportThread != null) && (m_workplaceImportThread.isFinished())) {
            // setup is already finished, just wait for client to collect final data
            return;
        }

        if (m_workplaceImportThread == null) {
            m_workplaceImportThread = new CmsSetupWorkplaceImportThread(this);
        }

        if (!m_workplaceImportThread.isAlive()) {
            m_workplaceImportThread.start();
        }
    }

    /**
     * Generates the output for step 8b of the setup wizard.<p>
     * 
     * @param out the JSP print stream
     * @throws IOException in case errors occur while writing to "out"
     */
    public void prepareStep8bOutput(JspWriter out) throws IOException {

        m_oldLoggingOffset = m_newLoggingOffset;
        m_newLoggingOffset = m_workplaceImportThread.getLoggingThread().getMessages().size();
        if (isInitialized()) {
            for (int i = m_oldLoggingOffset; i < m_newLoggingOffset; i++) {
                String str = m_workplaceImportThread.getLoggingThread().getMessages().get(i).toString();
                str = CmsEncoder.escapeWBlanks(str, CmsEncoder.ENCODING_UTF_8);
                out.println("output[" + (i - m_oldLoggingOffset) + "] = \"" + str + "\";");
            }
        } else {
            out.println("output[0] = 'ERROR';");
        }

        boolean threadFinished = m_workplaceImportThread.isFinished();
        boolean allWritten = m_oldLoggingOffset >= m_workplaceImportThread.getLoggingThread().getMessages().size();

        out.println("function initThread() {");
        if (isInitialized()) {
            out.print("send();");
            if (threadFinished && allWritten) {
                out.println("setTimeout('top.display.finish()', 1000);");
            } else {
                int timeout = 5000;
                if (getWorkplaceImportThread().getLoggingThread().getMessages().size() < 20) {
                    timeout = 2000;
                }
                out.println("setTimeout('location.reload()', " + timeout + ");");
            }
        }
        out.println("}");
    }

    /**
     *  Saves properties to specified file.<p>
     * 
     *  @param properties the properties to be saved
     *  @param file the file to save the properties to
     *  @param backup if true, create a backupfile
     */
    public void saveProperties(ExtendedProperties properties, String file, boolean backup) {

⌨️ 快捷键说明

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