📄 mvnforumconfig.java
字号:
/*
* $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/MVNForumConfig.java,v 1.97 2006/04/14 17:05:25 minhnn Exp $
* $Author: minhnn $
* $Revision: 1.97 $
* $Date: 2006/04/14 17:05:25 $
*
* ====================================================================
*
* Copyright (C) 2002-2006 by MyVietnam.net
*
* All copyright notices regarding mvnForum MUST remain
* intact in the scripts and in the outputted HTML.
* The "powered by" text/logo with a link back to
* http://www.mvnForum.com and http://www.MyVietnam.net in
* the footer of the pages MUST remain visible when the pages
* are viewed on the internet or intranet.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Support can be obtained from support forums at:
* http://www.mvnForum.com/mvnforum/index
*
* Correspondence and Marketing Questions can be sent to:
* info at MyVietnam net
*
* @author: Minh Nguyen
* @author: Mai Nguyen
* @author: Igor Manic
*/
package com.mvnforum;
import java.io.*;
import java.util.Locale;
import com.mvnforum.db.DAOFactory;
import freemarker.cache.FileTemplateLoader;
import freemarker.template.Configuration;
import net.myvietnam.mvncore.configuration.DOM4JConfiguration;
import net.myvietnam.mvncore.db.DBUtils;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.info.DatabaseInfo;
import net.myvietnam.mvncore.security.FloodControl;
import net.myvietnam.mvncore.util.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
public final class MVNForumConfig {
private static Log log = LogFactory.getLog(MVNForumConfig.class);
private MVNForumConfig() {
}
private static final String OPTION_FILE_NAME = "mvnforum.xml";
private static boolean m_shouldRun = true;
public static boolean isShouldRun() {
return m_shouldRun;
}
private static String m_reason = "Normal System";
public static String getReason() {
return m_reason;
}
private static boolean m_showUserArea = true;
public static boolean getShouldShowUserArea() {
return m_showUserArea;
}
public static void setShouldShowUserArea(boolean showUserArea) {
m_showUserArea = showUserArea;
}
/**
* This method could be use to stop run the forum in some condition.
* Some use could be a page that immediately stop the forum for security.
* Other usage is to check to run on some environment such as Servlet 2.3 or later
*
* @param shouldRun boolean the new shouldRun
* @param reason String the reason of the action, this reason will
* be shown in the error page
*/
public static void setShouldRun(boolean shouldRun, String reason) {
m_shouldRun = shouldRun;
m_reason = reason;
}
private static boolean m_guestUserInDatabase = false;
public static boolean isGuestUserInDatabase() {
return m_guestUserInDatabase;
}
private static String tempDir = "";
private static String searchPostIndexDir = "";
private static String searchCompanyIndexDir = "";
private static String searchMemberIndexDir = "";
private static String attachmentDir = "";
private static String pmAttachmentDir = "";
private static String backupDir = "";
private static String templateDir = "";
private static String logDir = "";
private static String avatarDir = "";
private static String LOG_FILE= "";
private static void setMVNForumHome(String home) {
// now check the read/write permission by writing a temp file
try {
// always create a dir, if the dir already exitsted, nothing happen
FileUtil.createDirs(home, true);
String tempFilename = home + File.separatorChar + "mvnforum_tempfile.tmp";
File tempFile = new File(tempFilename);
if (log.isDebugEnabled()) {
log.debug("Temp file = " + tempFilename);
log.debug("Absolute filename of temp file = " + tempFile.getAbsolutePath());
}
FileOutputStream fos = new FileOutputStream(tempFilename);
fos.write(tempFilename.getBytes());
fos.close();
tempFile.delete();
// now create the dirs if not exitst
tempDir = MVNFORUM_HOME + File.separatorChar + "temp";
FileUtil.createDirs(tempDir, true);
searchPostIndexDir = MVNFORUM_HOME + File.separatorChar + "search" + File.separatorChar + "post";
FileUtil.createDirs(searchPostIndexDir, true);
searchCompanyIndexDir = MVNFORUM_HOME + File.separatorChar + "search" + File.separatorChar + "company";
FileUtil.createDirs(searchCompanyIndexDir, true);
searchMemberIndexDir = MVNFORUM_HOME + File.separatorChar + "search" + File.separatorChar + "member";
FileUtil.createDirs(searchMemberIndexDir, true);
attachmentDir = MVNFORUM_HOME + File.separatorChar + "attachment";
FileUtil.createDirs(attachmentDir, true);
pmAttachmentDir = MVNFORUM_HOME + File.separatorChar + "pm_attachment";
FileUtil.createDirs(pmAttachmentDir, true);
backupDir = MVNFORUM_HOME + File.separatorChar + "backup";
FileUtil.createDirs(backupDir, true);
// this dir is created as a recommended folder to store the log files
logDir = MVNFORUM_HOME + File.separatorChar + "log";
FileUtil.createDirs(logDir, true);
avatarDir = MVNFORUM_HOME + File.separatorChar + "memberavatars";
FileUtil.createDirs(avatarDir, true);
// this dir is created as a recommended folder to store the template files
templateDir = MVNFORUM_HOME + File.separatorChar + "template";
FileUtil.createDirs(templateDir, true);
// now check the database
DatabaseInfo databaseInfo = new DatabaseInfo();
if (databaseInfo.getErrorMessage() != null) {
log.fatal("Cannot get database connection. Please correct it first.");
m_shouldRun = false;
m_reason = "Check your database configuration. Detail : " + databaseInfo.getErrorMessage();
} else if (DAOFactory.getMemberDAO().getNumberOfMembers() == 0) { // check if no member
log.fatal("There are no members in database. Please correct it first.");
m_shouldRun = false;
m_reason = "There are no members in database.";
} else if (databaseInfo.getDatabaseUrl().toLowerCase().startsWith("jdbc:odbc:")) {
log.fatal("Does not support JDBC/ODBC driver. Please use other drivers.");
m_shouldRun = false;
m_reason = "Does not support JDBC/ODBC driver. Please use other drivers.";
}
// call this method will print the database type to logger with level INFO
DBUtils.getDatabaseType();
} catch (IOException ex) {
log.fatal("Cannot setup the mvnForumHome folder. Please correct it first.", ex);
m_shouldRun = false;
m_reason = "Check your mvnForumHome. Detail : " + ex.getMessage();
} catch (DatabaseException dbe) {
log.fatal("Error while access database. Please correct it first.", dbe);
m_shouldRun = false;
m_reason = "Error while access database. Detail : " + dbe.getMessage();
} catch (AssertionException ae) {
// should never happen, maybe in the future we should remove the Assertion in getNumberOfBeans
log.fatal("Assertion error. Please correct it first.", ae);
m_shouldRun = false;
m_reason = "Assertion error. Detail : " + ae.getMessage();
}
}
private static Configuration freeMarkerConfiguration;
public static Configuration getFreeMarkerConfiguration() {
return freeMarkerConfiguration;
}
private static String MVNFORUM_HOME = "mvnForumHome";
public static String getMVNForumHome() {
return MVNFORUM_HOME;
}
public static String getTempDir() {
return tempDir;
}
public static int getSearchPostIndexType() {
return MVNForumGlobal.SEARCH_INDEX_TYPE_DISK;
//return MVNForumGlobal.SEARCH_INDEX_TYPE_DATABASE;
}
public static String getSearchPostIndexDirName() {
if (getSearchPostIndexType() != MVNForumGlobal.SEARCH_INDEX_TYPE_DISK) {
throw new IllegalStateException("Cannot get search index dir name because type is not disk.");
}
return searchPostIndexDir;
}
public static Directory getSearchPostIndexDir(boolean create) throws IOException {
return FSDirectory.getDirectory(searchPostIndexDir, create);
}
public static Directory getSearchPostIndexDir() throws IOException {
return FSDirectory.getDirectory(searchPostIndexDir, false);
}
public static int getSearchMemberIndexType() {
return MVNForumGlobal.SEARCH_INDEX_TYPE_DISK;
//return MVNForumGlobal.SEARCH_INDEX_TYPE_DATABASE;
}
public static String getSearchMemberIndexDirName() {
if (getSearchMemberIndexType() != MVNForumGlobal.SEARCH_INDEX_TYPE_DISK) {
throw new IllegalStateException("Cannot get search index dir name because type is not disk.");
}
return searchMemberIndexDir;
}
public static Directory getSearchMemberIndexDir(boolean create) throws IOException {
return FSDirectory.getDirectory(searchMemberIndexDir, create);
}
public static Directory getSearchMemberIndexDir() throws IOException {
return FSDirectory.getDirectory(searchMemberIndexDir, false);
}
public static int getSearchCompanyIndexType() {
return MVNForumGlobal.SEARCH_INDEX_TYPE_DISK;
//return MVNForumGlobal.SEARCH_INDEX_TYPE_DATABASE;
}
public static String getSearchCompanyIndexDirName() {
if (getSearchCompanyIndexType() != MVNForumGlobal.SEARCH_INDEX_TYPE_DISK) {
throw new IllegalStateException("Cannot get search index dir name because type is not disk.");
}
return searchCompanyIndexDir;
}
public static Directory getSearchCompanyIndexDir(boolean create) throws IOException {
return FSDirectory.getDirectory(searchCompanyIndexDir, create);
}
public static Directory getSearchCompanyIndexDir() throws IOException {
return FSDirectory.getDirectory(searchCompanyIndexDir, false);
}
public static String getAttachmentDir() {
return attachmentDir;
}
public static String getPmAttachmentDir() {
return pmAttachmentDir;
}
public static String getTemplateDir() {
return templateDir;
}
public static String getBackupDir() {
return backupDir;
}
public static String getLogDir() {
return logDir;
}
public static String getLogFile() {
return LOG_FILE;
}
public static String getAvatarDir() {
return avatarDir;
}
private static String REDIRECT_LOGIN_URL = "/login";
public static String getRedirectLoginURL() {
return REDIRECT_LOGIN_URL;
}
private static String WEBMASTER_EMAIL = "josdnvip@163.com";
public static String getWebMasterEmail() {
return WEBMASTER_EMAIL;
}
private static String LOGO_URL = "http://www.mvnForum.com";
public static String getLogoUrl() {
return LOGO_URL;
}
private static String[] SUPPORTED_LOCALE_NAMES = new String[0];
private static Locale[] SUPPORTED_LOCALES = new Locale[0];
public static String[] getSupportedLocaleNames() {
return SUPPORTED_LOCALE_NAMES;
}
public static Locale[] getSupportedLocales() {
return SUPPORTED_LOCALES;
}
private static String DEFAULT_LOCALE_NAME = "en";
private static Locale DEFAULT_LOCALE = null;
public static String getDefaultLocaleName() {
return DEFAULT_LOCALE_NAME;
}
public static Locale getDefaultLocale() {
return DEFAULT_LOCALE;
}
private static String LOCALE_PARAMETER_NAME = "lang";
public static String getLocaleParameterName() {
return LOCALE_PARAMETER_NAME;
}
/**
* Default username of a virtual Guest user. Will be overriden with the data
* from the database, if it exists (for the Guest user).
* Admin can give him a name he wants, like "Guest", "Anonymous", "Surfer",
* or even use a language different than English.
*/
private static String DEFAULT_GUEST_NAME = "Guest";
public static String getDefaultGuestName() {
return DEFAULT_GUEST_NAME;
}
private static double DEFAULT_GUEST_TIMEZONE = 0;
public static double getDefaultGuestTimeZone() {
return DEFAULT_GUEST_TIMEZONE;
}
private static boolean ENABLE_PORTLET = false;
public static boolean getEnablePortlet() {
return ENABLE_PORTLET;
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -