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

📄 chatconfig.java

📁 本平台是以web2.0为基本的标准
💻 JAVA
字号:
package com.afuer.chat;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Stores the config of the application.
 */
public final class ChatConfig {
    private static Log log = LogFactory.getLog(ChatConfig.class);

    private String id = "elchat.elchat";
    private String title = "Chat";
    private String dirtyTitle = "afuer 聊天室,多多关照!";
    private String adminParam = "admin";
    private boolean enableAdsenseContent = true;
    private boolean enableAdsenseSearch = true;
    private String commandPrefix = "";
    private String logo = "";
    private String messagePath = "/usr/local/elchat/";

    private boolean enableUrl = true;
    private boolean enableImage = true;
    private boolean enableUserEmotIcon = true;
    private boolean enableMsgEmotIcon = true;
    private boolean enableHtmlEscape = true;
    private int msgLength = 500;
    private int limit = 50;

    // runtime
    private boolean suspend;

    private static ChatConfig instance;

    static void init(String configFile) {
        FileInputStream is = null;
        try {
            is = new FileInputStream(configFile);
            Properties prop = new Properties();
            prop.load(is);
            instance = new ChatConfig(prop);
        }
        catch (Exception ex) {
            log.warn("Fail to load elchat.properties, use default setting", ex);
            instance = new ChatConfig();
        }
        finally {
            if (is != null) {
                try {
                    is.close();
                }
                catch (IOException ex) {
                    ;
                }
            }
        }
    }

    public static ChatConfig getInstance() {
        return instance;
    }

    private ChatConfig() {
        ;
    }

    private ChatConfig(Properties prop) {
        id = getConfigString(prop, "elchat.id", id);
        title = getConfigString(prop, "elchat.title", title);
        dirtyTitle = getConfigString(prop, "elchat.dirtytitle", dirtyTitle);
        adminParam = getConfigString(prop, "elchat.admin.param", adminParam);
        enableAdsenseContent = getConfigBool(prop, "elchat.adsense.content", enableAdsenseContent);
        enableAdsenseSearch = getConfigBool(prop, "elchat.adsense.search", enableAdsenseSearch);
        commandPrefix = getConfigString(prop, "elchat.command.prefix", commandPrefix);
        logo = getConfigString(prop, "elchat.logo", logo);
        messagePath = getConfigString(prop, "elchat.message.path", messagePath);
        enableUrl = getConfigBool(prop, "elchat.message.inlineurl", enableUrl);
        enableImage = getConfigBool(prop, "elchat.message.inlineimage", enableImage);
        enableUserEmotIcon = getConfigBool(prop, "elchat.message.useremoticon", enableUserEmotIcon);
        enableMsgEmotIcon = getConfigBool(prop, "elchat.message.emoticon", enableMsgEmotIcon);
        enableHtmlEscape = getConfigBool(prop, "elchat.message.htmlescape", enableHtmlEscape);
        msgLength = getConfigInt(prop, "elchat.message.maxlength", msgLength);
        limit = getConfigInt(prop, "elchat.message.limit", limit);
    }

    private boolean getConfigBool(Properties prop, String key, boolean defaultValue) {
        String value = prop.getProperty(key);
        if (value == null || value.length() == 0) {
            return defaultValue;
        }
        else {
            return "true".equals(value);
        }
    }

    private String getConfigString(Properties prop, String key, String defaultValue) {
        String value = prop.getProperty(key);
        if (value == null || value.length() == 0) {
            return defaultValue;
        }
        else {
            return value;
        }
    }

    private int getConfigInt(Properties prop, String key, int defaultValue) {
        String value = prop.getProperty(key);
        if (value == null || value.length() == 0) {
            return defaultValue;
        }
        else {
            try {
                return Integer.parseInt(value);
            }
            catch (NumberFormatException ex) {
                return defaultValue;
            }
        }
    }

    public String getAdminParam() {
        return adminParam;
    }

    public void setAdminParam(String adminParam) {
        this.adminParam = adminParam;
    }

    public String getCommandPrefix() {
        return commandPrefix;
    }

    public void setCommandPrefix(String commandPrefix) {
        this.commandPrefix = commandPrefix;
    }

    public String getDirtyTitle() {
        return dirtyTitle;
    }

    public void setDirtyTitle(String dirtyTitle) {
        this.dirtyTitle = dirtyTitle;
    }

    public boolean isEnableAdsenseContent() {
        return enableAdsenseContent;
    }

    public void setEnableAdsenseContent(boolean enableAdsenseContent) {
        this.enableAdsenseContent = enableAdsenseContent;
    }

    public boolean isEnableAdsenseSearch() {
        return enableAdsenseSearch;
    }

    public void setEnableAdsenseSearch(boolean enableAdsenseSearch) {
        this.enableAdsenseSearch = enableAdsenseSearch;
    }

    public boolean isEnableHtmlEscape() {
        return enableHtmlEscape;
    }

    public void setEnableHtmlEscape(boolean enableHtmlEscape) {
        this.enableHtmlEscape = enableHtmlEscape;
    }

    public boolean isEnableImage() {
        return enableImage;
    }

    public void setEnableImage(boolean enableImage) {
        this.enableImage = enableImage;
    }

    public boolean isEnableMsgEmotIcon() {
        return enableMsgEmotIcon;
    }

    public void setEnableMsgEmotIcon(boolean enableMsgEmotIcon) {
        this.enableMsgEmotIcon = enableMsgEmotIcon;
    }

    public boolean isEnableUrl() {
        return enableUrl;
    }

    public void setEnableUrl(boolean enableUrl) {
        this.enableUrl = enableUrl;
    }

    public boolean isEnableUserEmotIcon() {
        return enableUserEmotIcon;
    }

    public void setEnableUserEmotIcon(boolean enableUserEmotIcon) {
        this.enableUserEmotIcon = enableUserEmotIcon;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public String getLogo() {
        return logo;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public String getMessagePath() {
        return messagePath;
    }

    public void setMessagePath(String messagePath) {
        this.messagePath = messagePath;
    }

    public int getMsgLength() {
        return msgLength;
    }

    public void setMsgLength(int msgLength) {
        this.msgLength = msgLength;
    }

    public boolean isSuspend() {
        return suspend;
    }

    public void setSuspend(boolean suspend) {
        this.suspend = suspend;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

}

⌨️ 快捷键说明

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