global.java

来自「cwbbs 云网论坛源码」· Java 代码 · 共 370 行

JAVA
370
字号
package cn.js.fan.web;import java.util.*;import cn.js.fan.cache.jcs.*;import cn.js.fan.kernel.*;import cn.js.fan.util.*;import org.apache.log4j.*;public final class Global {    static Logger logger = Logger.getLogger(Global.class.getName());    public static String author;    public static String AppName;    public static String server;    public static String port;    public static String virtualPath;    public static String defaultDB;     public static String AppRealName;    public static long MaxSize = 1024000;     public static int FileSize = 1024000;     public static String INTERNET_FLAG_SECURE = "secure";    public static boolean requestSupportCN = false;    public static String internetFlag;    static HashMap dbinfos = new HashMap();    public static boolean localeSpecified = false;     public static boolean isSubDomainSupported = false;    public static boolean isTransactionSupported = true;    public static boolean isGZIPEnabled = true;    public static Global global = null;    private static boolean debug = false;    static {        global = new Global();        global.init();    }    public Global() {    }    public static void init() {        Config config = new Config();        if (debug)            System.out.println("Global.java init " + config);        author = config.getProperty("Application.author");        AppRealName = config.getProperty("Application.name");        AppName = AppRealName + " - Powered by CWBBS";        server = config.getProperty("Application.server");        port = config.getProperty("Application.port");        virtualPath = StrUtil.getNullString(config.getProperty("Application.virtualPath"));        String strMaxSize = StrUtil.getNullString(config.getProperty("Application.WebEdit.MaxSize"));         if (StrUtil.isNumeric(strMaxSize))            MaxSize = Long.parseLong(strMaxSize);                String strmaxUploadingFileCount = StrUtil.getNullString(config.getProperty("Application.WebEdit.maxUploadingFileCount"));        if (StrUtil.isNumeric(strmaxUploadingFileCount))            maxUploadingFileCount = Integer.parseInt(strmaxUploadingFileCount);        String strFileSize = StrUtil.getNullString(config.getProperty("Application.FileSize"));         if (StrUtil.isNumeric(strFileSize))            FileSize = Integer.parseInt(strFileSize);        smtpServer = StrUtil.getNullString(config.getProperty("Application.smtpServer"));        String sPort = config.getProperty("Application.smtpPort");        if (StrUtil.isNumeric(sPort))            smtpPort = Integer.parseInt(sPort);        smtpUser = StrUtil.getNullString(config.getProperty("Application.smtpUser"));        smtpPwd = StrUtil.getNullString(config.getProperty("Application.smtpPwd"));        realPath = config.getProperty("Application.realPath");        if (realPath.lastIndexOf("/")!=realPath.length()-1)            realPath += "/";        email = StrUtil.getNullString(config.getProperty("Application.email"));        internetFlag = StrUtil.getNullString(config.getProperty("Application.internetFlag"));        desc = StrUtil.getNullStr(config.getProperty("Application.desc"));        copyright = StrUtil.getNullStr(config.getProperty("Application.copyright"));        icp = StrUtil.getNullStr(config.getProperty("Application.icp"));        contact = StrUtil.getNullStr(config.getProperty("Application.contact"));        version = StrUtil.getNullStr(config.getProperty("Application.version"));        title = StrUtil.getNullStr(config.getProperty("Application.title"));        String strIsRequestSupportCN = StrUtil.getNullStr(config.getProperty("Application.isRequestSupportCN"));        if (strIsRequestSupportCN==null)            System.out.println("Error:Global Application.isRequestSupportCN is not found.");        requestSupportCN = strIsRequestSupportCN.equals("true");        String lang = StrUtil.getNullStr(config.getProperty("i18n.lang"));        String country = StrUtil.getNullStr(config.getProperty("i18n.country"));        String strTimeZone = StrUtil.getNullStr(config.getProperty("i18n.timeZone"));        String strIsSpecified = StrUtil.getNullStr(config.getProperty("i18n.isSpecified"));        if (strIsSpecified==null)            System.out.println("Error:Global i18n.isSpecified is not found.");        localeSpecified = strIsSpecified.equals("true");        locale = new Locale(lang, country);        timeZone = TimeZone.getTimeZone(strTimeZone);        if (debug) {            System.out.println("Global.java: timeZone=" + strTimeZone + " zoneID=" + timeZone.getID() + " lang=" + lang + " country=" + country);            System.out.println("Global.java init AppName=" + AppName);        }        String strUseCache = config.getProperty("Application.useCache");        if (strUseCache==null)            System.out.println("Error:Global Application.useCache is not found.");        useCache = strUseCache.equals("true");        String strIsSubDomainSupported = config.getProperty("Application.isSubDomainSupported");        if (strIsSubDomainSupported==null)            System.out.println(Global.class + " Error:Global Application.isSubDomainSupported is not found.");        isSubDomainSupported = strIsSubDomainSupported.equals("true");        String strIsTransactionSupported = config.getProperty("Application.isTransactionSupported");        if (strIsTransactionSupported==null)            System.out.println(Global.class + " Error:Global Application.isTransactionSupported is not found.");        isTransactionSupported = strIsTransactionSupported.equals("true");        String strIsGZIPEnabled = config.getProperty("Application.isGZIPEnabled");        if (strIsGZIPEnabled==null)            System.out.println(Global.class + " Error:Global Application.isGZIPEnabled is not found.");        isGZIPEnabled = strIsGZIPEnabled.equals("true");        dbinfos.clear();        Vector v = config.getDBInfos();        Iterator ir = v.iterator();        while (ir.hasNext()) {            DBInfo di = (DBInfo) ir.next();            if (di.isDefault) {                defaultDB = di.name;                            }            dbinfos.put(di.name, di);        }        String strIsCluster = config.getProperty("Application.isCluster");        if (strIsCluster==null)            System.out.println(Global.class + " Error:Global Application.isCluster is not found.");        else            cluster = strIsCluster.equals("true");                Scheduler.initInstance(1000);         if (debug)            System.out.println("Global.java: Scheduler initInstance end");                config.initScheduler();        if (debug)            System.out.println("Global.java: initScheduler end");                CacheTimer.initInstance();        if (debug)            System.out.println("Global.java: init end");    }    public static DBInfo getDBInfo(String key) {        return (DBInfo)dbinfos.get(key);    }    public static void setDefaultDB(String db) {        defaultDB = db;    }    public void setSmtpServer(String smtpServer) {        this.smtpServer = smtpServer;    }    public void setSmtpPort(int smtpPort) {        this.smtpPort = smtpPort;    }    public void setSmtpUser(String smtpUser) {        this.smtpUser = smtpUser;    }    public void setSmtpPwd(String smtpPwd) {        this.smtpPwd = smtpPwd;    }    public void setRealPath(String realPath) {        this.realPath = realPath;    }    public void setEmail(String email) {        this.email = email;    }    public void setMaxUploadingFileCount(int maxUploadingFileCount) {        this.maxUploadingFileCount = maxUploadingFileCount;    }    public void setTitle(String title) {        this.title = title;    }    public void setRequestSupportCN(boolean requestSupportCN) {        this.requestSupportCN = requestSupportCN;    }    public void setLocaleSpecified(boolean localeSpecified) {        this.localeSpecified = localeSpecified;    }    public void setUseCache(boolean useCache) {        this.useCache = useCache;    }    public void setCluster(boolean cluster) {        this.cluster = cluster;    }        public static String getRootPath() {        if (virtualPath.equals(""))            return "";        else            return "/" + virtualPath;            }        public static String getFullRootPath() {        if (!virtualPath.equals("")) {            if (Global.port.equals("80"))                return "http://" + Global.server + "/" +                        Global.virtualPath;             else                return "http://" + Global.server + ":" + Global.port + "/" +                        Global.virtualPath;         } else {            if (Global.port.equals("80"))                return "http://" + Global.server;            else                return "http://" + Global.server + ":" + Global.port;         }    }    public static String getSmtpServer() {        return smtpServer;    }    public static int getSmtpPort() {        return smtpPort;    }    public static String getSmtpUser() {        return smtpUser;    }    public static String getSmtpPwd() {        return smtpPwd;    }    public static String getRealPath() {        return realPath;    }    public static String getEmail() {        return email;    }    public static int getMaxUploadingFileCount() {        return maxUploadingFileCount;    }    public static String getInternetFlag() {        return internetFlag;    }    public static String getDesc() {        return desc;    }    public static String getCopyright() {        return copyright;    }    public static String getIcp() {        return icp;    }    public static String getContact() {        return contact;    }    public static String getVersion() {        return version;    }    public static String getTitle() {        return title;    }    public static Locale getLocale() {        return locale;    }    public static TimeZone getTimeZone() {        return timeZone;    }    public boolean isRequestSupportCN() {        return requestSupportCN;    }    public boolean isLocaleSpecified() {        return localeSpecified;    }    public boolean isUseCache() {        return useCache;    }    public static boolean isCluster() {        return cluster;    }    public static synchronized Global getInstance() {        return global;    }    public static String smtpServer;    public static int smtpPort;    public static String smtpUser;    public static String smtpPwd;    public static String realPath;    public static String email;    public static int maxUploadingFileCount;    public static String desc;    public static String copyright;    public static String icp;    public static String contact;    public static String version;    public static String title;    public static Locale locale;    public static TimeZone timeZone;        public static boolean useCache = true;    private static boolean cluster = false;}

⌨️ 快捷键说明

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