?? cmssetupbean.java
字號:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/setup/CmsSetupBean.java,v $
* Date : $Date: 2006/07/20 11:06:50 $
* Version: $Revision: 1.48 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software GmbH, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.setup;
import org.opencms.configuration.CmsConfigurationException;
import org.opencms.configuration.CmsConfigurationManager;
import org.opencms.configuration.CmsImportExportConfiguration;
import org.opencms.configuration.CmsModuleConfiguration;
import org.opencms.configuration.CmsSearchConfiguration;
import org.opencms.configuration.CmsSystemConfiguration;
import org.opencms.configuration.CmsVfsConfiguration;
import org.opencms.configuration.CmsWorkplaceConfiguration;
import org.opencms.configuration.I_CmsXmlConfiguration;
import org.opencms.db.CmsDbPool;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.i18n.CmsEncoder;
import org.opencms.loader.CmsImageLoader;
import org.opencms.main.CmsLog;
import org.opencms.main.CmsRuntimeException;
import org.opencms.main.CmsSystemInfo;
import org.opencms.main.I_CmsShellCommands;
import org.opencms.main.Messages;
import org.opencms.main.OpenCms;
import org.opencms.main.OpenCmsServlet;
import org.opencms.module.CmsModule;
import org.opencms.module.CmsModuleManager;
import org.opencms.report.CmsShellReport;
import org.opencms.setup.comptest.CmsSetupTestResult;
import org.opencms.setup.comptest.CmsSetupTestSimapi;
import org.opencms.setup.comptest.I_CmsSetupTest;
import org.opencms.setup.xml.CmsSetupXmlHelper;
import org.opencms.util.CmsFileUtil;
import org.opencms.util.CmsPropertyUtils;
import org.opencms.util.CmsStringUtil;
import org.opencms.util.CmsUUID;
import org.opencms.xml.CmsXmlException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Vector;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import org.apache.commons.collections.ExtendedProperties;
/**
* A java bean as a controller for the OpenCms setup wizard.<p>
*
* It is not allowed to customize this bean with methods for a specific database server setup!<p>
*
* Database server specific settings should be set/read using get/setDbProperty, as for example like:
*
* <pre>
* setDbProperty("oracle.defaultTablespace", value);
* </pre>
* <p>
*
* @author Thomas Weckert
* @author Carsten Weinholz
* @author Alexander Kandzior
* @author Michael Moossen
*
* @version $Revision: 1.48 $
*
* @since 6.0.0
*/
public class CmsSetupBean extends Object implements Cloneable, I_CmsShellCommands {
/** Folder constant name.<p> */
public static final String FOLDER_BACKUP = "backup" + File.separatorChar;
/** Folder constant name.<p> */
public static final String FOLDER_DATABASE = "database" + File.separatorChar;
/** Folder constant name.<p> */
public static final String FOLDER_LIB = "lib" + File.separatorChar;
/** Folder constant name.<p> */
public static final String FOLDER_SETUP = "setup" + File.separatorChar;
/** Folder constant name.<p> */
public static final String FOLDER_WEBINF = "WEB-INF" + File.separatorChar;
/** DB provider constant. */
public static final String GENERIC_PROVIDER = "generic";
/** Name of the property file containing HTML fragments for setup wizard and error dialog. */
public static final String HTML_MESSAGE_FILE = "org/opencms/setup/htmlmsg.properties";
/** DB provider constant for maxdb. */
public static final String MAXDB_PROVIDER = "maxdb";
/** DB provider constant for mysql. */
public static final String MYSQL_PROVIDER = "mysql";
/** DB provider constant for oracle. */
public static final String ORACLE_PROVIDER = "oracle";
/** DB provider constant for postgresql. */
public static final String POSTGRESQL_PROVIDER = "postgresql";
/** Required files per database server setup. */
public static final String[] REQUIRED_DB_SETUP_FILES = {
"step_4_database_setup.jsp",
"database.properties",
"create_db.sql",
"create_tables.sql",
"drop_db.sql",
"drop_tables.sql"};
/** Contains HTML fragments for the output in the JSP pages of the setup wizard. */
private static Properties m_htmlProps;
/** A map with all available modules. */
protected Map m_availableModules;
/** A CmsObject to execute shell commands. */
protected CmsObject m_cms;
/** A list with the package names of the modules to be installed .*/
protected List m_installModules;
/** Location for log file. */
protected String m_logFile = FOLDER_WEBINF + CmsLog.FOLDER_LOGS + "setup.log";
/** Location for logs relative to the webapp folder. */
protected String m_logsFolder = FOLDER_WEBINF + CmsLog.FOLDER_LOGS;
/** A map with lists of dependent module package names keyed by module package names. */
protected Map m_moduleDependencies;
/** A map with all available modules filenames. */
protected Map m_moduleFilenames;
/** Location for module archives relative to the webapp folder. */
protected String m_modulesFolder = FOLDER_WEBINF + CmsSystemInfo.FOLDER_PACKAGES + CmsSystemInfo.FOLDER_MODULES;
/** The new logging offset in the workplace import thread. */
protected int m_newLoggingOffset;
/** The lod logging offset in the workplace import thread. */
protected int m_oldLoggingOffset;
/** The absolute path to the home directory of the OpenCms webapp. */
protected String m_webAppRfsPath;
/** The absolute path to the config sub directory of the OpenCms web application. */
private String m_configRfsPath;
/** Key of the selected database server (e.g. "mysql", "generic" or "oracle") */
private String m_databaseKey;
/** List of keys of all available database server setups (e.g. "mysql", "generic" or "oracle") */
private List m_databaseKeys;
/** Map of database setup properties of all available database server setups keyed by their database keys. */
private Map m_databaseProperties;
/** Password used for the JDBC connection when the OpenCms database is created. */
private String m_dbCreatePwd;
/** The name of the default web application (in web.xml). */
private String m_defaultWebApplication;
/** Contains the error messages to be displayed in the setup wizard. */
private List m_errors;
/** Contains the properties of "opencms.properties". */
private ExtendedProperties m_extProperties;
/** The Database Provider used in setup. */
private String m_provider;
/** A map with tokens ${...} to be replaced in SQL scripts. */
private Map m_replacer;
/** The initial servlet configuration. */
private ServletConfig m_servletConfig;
/** The servlet mapping (in web.xml). */
private String m_servletMapping;
/** List of sorted keys by ranking of all available database server setups (e.g. "mysql", "generic" or "oracle") */
private List m_sortedDatabaseKeys;
/** The workplace import thread. */
private CmsSetupWorkplaceImportThread m_workplaceImportThread;
/** Xml read/write helper object. */
private CmsSetupXmlHelper m_xmlHelper;
/**
* Default constructor.<p>
*/
public CmsSetupBean() {
initHtmlParts();
}
/**
* Restores the opencms.xml either to or from a backup file, depending
* whether the setup wizard is executed the first time (the backup
* does not exist) or not (the backup exists).
*
* @param filename something like e.g. "opencms.xml"
* @param originalFilename the configurations real file name, e.g. "opencms.xml.ori"
*/
public void backupConfiguration(String filename, String originalFilename) {
// ensure backup folder exists
File backupFolder = new File(m_configRfsPath + FOLDER_BACKUP);
if (!backupFolder.exists()) {
backupFolder.mkdirs();
}
// copy file to (or from) backup folder
originalFilename = FOLDER_BACKUP + originalFilename;
File file = new File(m_configRfsPath + originalFilename);
if (file.exists()) {
copyFile(originalFilename, filename);
} else {
copyFile(filename, originalFilename);
}
}
/**
* Checks the ethernet address value and generates a dummy address, if necessary.<p> *
*/
public void checkEthernetAddress() {
// check the ethernet address in order to generate a random address, if not available
if (CmsStringUtil.isEmpty(getEthernetAddress())) {
setEthernetAddress(CmsUUID.getDummyEthernetAddress());
}
}
/**
* Copies a given file.<p>
*
* @param source the source file
* @param target the destination file
*/
public void copyFile(String source, String target) {
try {
CmsFileUtil.copy(m_configRfsPath + source, m_configRfsPath + target);
} catch (IOException e) {
m_errors.add("Could not copy " + source + " to " + target + " \n");
m_errors.add(e.toString() + "\n");
}
}
/**
* Returns html code to display an error.<p>
*
* @param pathPrefix to adjust the path
*
* @return html code
*/
public String displayError(String pathPrefix) {
if (pathPrefix == null) {
pathPrefix = "";
}
StringBuffer html = new StringBuffer(512);
html.append("<table border='0' cellpadding='5' cellspacing='0' style='width: 100%; height: 100%;'>");
html.append("\t<tr>");
html.append("\t\t<td style='vertical-align: middle; height: 100%;'>");
html.append(getHtmlPart("C_BLOCK_START", "Error"));
html.append("\t\t\t<table border='0' cellpadding='0' cellspacing='0' style='width: 100%;'>");
html.append("\t\t\t\t<tr>");
html.append("\t\t\t\t\t<td><img src='").append(pathPrefix).append("resources/error.png' border='0'></td>");
html.append("\t\t\t\t\t<td> </td>");
html.append("\t\t\t\t\t<td style='width: 100%;'>");
html.append("\t\t\t\t\t\tThe Alkacon OpenCms setup wizard has not been started correctly!<br>");
html.append("\t\t\t\t\t\tPlease click <a href='").append(pathPrefix);
html.append("index.jsp'>here</a> to restart the wizard.");
html.append("\t\t\t\t\t</td>");
html.append("\t\t\t\t</tr>");
html.append("\t\t\t</table>");
html.append(getHtmlPart("C_BLOCK_END"));
html.append("\t\t</td>");
html.append("\t</tr>");
html.append("</table>");
return html.toString();
}
/**
* Returns a map with all available modules.<p>
*
* The map contains maps keyed by module package names. Each of these maps contains various
* information about the module such as the module name, version, description, and a list of
* it's dependencies. You should refer to the source code of this method to understand the data
* structure of the map returned by this method!<p>
*
* @return a map with all available modules
*/
public Map getAvailableModules() {
if (m_availableModules == null || m_availableModules.isEmpty()) {
m_availableModules = new HashMap();
m_moduleDependencies = new HashMap();
m_moduleFilenames = new HashMap();
try {
Map modules = CmsModuleManager.getAllModulesFromPath(getModuleFolder());
Iterator itMods = modules.keySet().iterator();
while (itMods.hasNext()) {
CmsModule module = (CmsModule)itMods.next();
// put the module information into a map keyed by the module packages names
m_availableModules.put(module.getName(), module);
m_moduleFilenames.put(module.getName(), modules.get(module));
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -