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

📄 mvnforumconfig.java

📁 java servlet著名论坛源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */
    private static int MAX_FAVORITE_THREAD = 128;
    public static int getMaxFavoriteThread() {
        return MAX_FAVORITE_THREAD;
    }

    private static int HOT_TOPIC_THRESHOLD = 10;
    public static int getHotTopicThreshold() {
        return HOT_TOPIC_THRESHOLD;
    }

    private static int MAX_POSTS_PER_HOUR = 20;
    public static int getMaxPostsPerHour() {
        return MAX_POSTS_PER_HOUR;
    }

    private static int MAX_MEMBERS_PER_HOUR = 2;
    public static int getMaxMembersPerHour() {
        return MAX_MEMBERS_PER_HOUR;
    }

    private static int MAX_LOGINS_PER_HOUR = 5;
    public static int getMaxLoginsPerHour() {
        return MAX_LOGINS_PER_HOUR;
    }

    /** Do we allow storing backup files on the server? Currently not used. */
    static boolean ENABLE_BACKUP_ON_SERVER = true;
    public static final String BACKUP_FILE_PREFIX = "mvnForum-";
    public static final String BACKUP_FILE_MainXmlFileNameInZip = "IMPORT.xml";
    public static final String BACKUP_FILE_AvatarsDirNameInZip = "AVATARS/"; //must end with '/'
    public static final String BACKUP_FILE_AttachsDirNameInZip = "ATTACHMENTS/"; //must end with '/'

    /**
     * Maximum size of the import file (in bytes) we will allow to be uploaded
     * to server before processing.
     */
    private static int MAX_IMPORT_SIZE = 4096000;
    /**
     * Maximum size of the import file (in bytes) we will allow to be uploaded
     * to server before processing.
     */
    public static int getMaxImportSize() {
        return MAX_IMPORT_SIZE;
    }

    /**
     * Type of import/export file: mvnForum XML.
     * Import only database info, no attachments, message folders, avatars, ...
     */
    public static final int IMPORTEXPORT_TYPE_MVN_XML  = 0;

    /**
     * Type of import file: mvnForum ZIP.
     * Also import attachments, avatars, message folders
     */
    public static final int IMPORTEXPORT_TYPE_MVN_ZIP  = 1;

    /**
     * Type of import file: Jive XML.
     * Using <code>http://www.jivesoftware.com/jive.dtd</code>, xmlversion="1.0".
     */
    public static final int IMPORTEXPORT_TYPE_JIVE_XML = 2;

    /**
     * Output all messages, including errors, important messages and
     * informational/status messages. This constant is used for specifing
     * the level of output in various processess throughout the application.
     */
    public static final int MESSAGE_LEVEL_ALL_MESSAGES       = 0;

    /**
     * Output only error messages and important messages (no
     * informational/status messages). This constant is used for specifing
     * the level of output in various processess throughout the application.
     */
    public static final int MESSAGE_LEVEL_IMPORTANT_MESSAGES = 1;

    /**
     * Output only error messages (no important messages, no
     * informational/status messages). This constant is used for specifing
     * the level of output in various processess throughout the application.
     */
    public static final int MESSAGE_LEVEL_ONLY_ERRORS        = 2;

    public final static int SESSION_DURATION    = 30 * DateUtil.MINUTE;// SHOULD NOT less than 15 minutes

    //public static final boolean DEFAULT_MESSAGE_ENABLE  = true;
    //public static final boolean DEFAULT_MEMBER_ENABLE   = true;

    /**
     * Configurable number of days that a user can edit a post
     */
    private static int MAX_EDIT_DAYS   = 7;
    public static int getMaxEditDays() {
        return MAX_EDIT_DAYS;
    }

    /**
     * Configurable number of days that a user can attach file to a post
     */
    private static int MAX_ATTACH_DAYS = 1;
    public static int getMaxAttachDays() {
        return MAX_ATTACH_DAYS;
    }

    /**
     * Configurable number of days that a user can delete a post
     */
    private static int MAX_DELETE_DAYS = 1;
    public static int getMaxDeleteDays() {
        return MAX_DELETE_DAYS;
    }

    /**
     * Default number of rows (of Guest user) shown per page
     */
    private static int ROWS_PER_PAGE = 10;
    public static int getRowsPerPage() {
        return ROWS_PER_PAGE;
    }

    /**
     * This is the number of rows returned when list threads for RSS
     */
    private static int ROWS_PER_RSS = 15;//RSS 0.91
    public static int getRowsPerRSS() {
        return ROWS_PER_RSS;
    }

    /**
     * This is the default value of watch option
     * @see com.mvnforum.db.WatchBean for the constant values
     */
    private static int DEFAULT_WATCH_OPTION = 0;
    public static int getDefaultWatchOption() {
        return DEFAULT_WATCH_OPTION;
    }

    private static int DEFAULT_MODERATION_OPTION = 0;
    public static int getDefaultModerationOption() {
        return DEFAULT_MODERATION_OPTION;
    }

    /**
     * This is the number of reply rows returned when addpost (reply to a topic)
     * /forum/addpost
     */
    public static final int ROWS_IN_LAST_REPLIES = 5;

    private static boolean parseBooleanValue(String propertyValue, boolean defaultValue) {
        String result = "true";
        try {
            result = propertyValue.trim();
            if ((result.equalsIgnoreCase("false")) || (result.equalsIgnoreCase("no"))) {
                return false;
            } else if ((result.equalsIgnoreCase("true")) || (result.equalsIgnoreCase("yes"))) {
                return true;
            } else {
                log.warn("Invalid boolean value in properties file. Should be \"true\", \"false\", \"yes\" or \"no\".");
                return defaultValue;
            }
        } catch (Exception e) {
            log.warn(e.getMessage());
            return defaultValue;
        }
    }

    private static int parseIntValue(String propertyValue, int defaultValue) {
        try {
            return Integer.parseInt(propertyValue.trim());
        } catch (Exception e) {
            log.warn(e.getMessage());
            return defaultValue;
        }
    }

    private static int parseIntSizeValue(String propertyValue, int defaultValue) {
        try {
            String temp = propertyValue.trim();
            if (temp.endsWith("B")) temp=temp.substring(0, temp.length()-1);
            switch (temp.charAt(temp.length()-1)) {
                case 'K': case 'k':
                    //examples (ending 'B' was cut before): "1K", "1KB", "1k", "1kB", "1 K", "1 KB", "1 k", "1 kB"
                    return 1024*Integer.parseInt( temp.substring(0, temp.length()-1).trim() );
                case 'M': case 'm':
                    //examples (ending 'B' was cut before): "1M", "1MB", "1m", "1mB", "1 M", "1 MB", "1 m", "1 mB"
                    return 1024*1024*Integer.parseInt( temp.substring(0, temp.length()-1).trim() );
                default:
                    //examples (ending 'B' was cut before): "1", "1B", "1 B"
                    return Integer.parseInt(temp.trim());
            }
        } catch (Exception e) {
            log.warn(e.getMessage());
            return defaultValue;
        }
    }

    static {
        try {
            String strPathName = FileUtil.getServletClassesPath();
            String configFilename = strPathName + OPTION_FILE_NAME;
            DOM4JConfiguration conf = new DOM4JConfiguration(new File(configFilename));

            MVNFORUM_HOME       = conf.getString("mvnforumconfig.mvnforum_home", "");
            setMVNForumHome(MVNFORUM_HOME);

            WEBMASTER_EMAIL     = conf.getString("mvnforumconfig.webmaster_email", "");

            LOGO_URL            = conf.getString("mvnforumconfig.logo_url", LOGO_URL);

            String supportedLocales = conf.getString("mvnforumconfig.supported_locales", "");
            SUPPORTED_LOCALE_NAMES = StringUtil.getStringArray(supportedLocales, ";");

            SUPPORTED_LOCALES = new Locale[SUPPORTED_LOCALE_NAMES.length];
            for (int i = 0; i < SUPPORTED_LOCALE_NAMES.length; i++) {
                String localeName = SUPPORTED_LOCALE_NAMES[i];
                SUPPORTED_LOCALES[i] = MyUtil.getLocale(localeName);
            }

            try {
                DEFAULT_LOCALE_NAME = conf.getString("mvnforumconfig.default_locale_name", "");
            } catch (Exception ex) {
                log.warn(ex.getMessage());
            }
            DEFAULT_LOCALE = MyUtil.getLocale(DEFAULT_LOCALE_NAME);

            try {
                DEFAULT_GUEST_NAME = conf.getString("mvnforumconfig.default_guest_name", DEFAULT_GUEST_NAME);
            } catch (Exception ex) {
                log.warn(ex.getMessage());
            }

            DISABLE_PASSWORDLESS_AUTH = conf.getBoolean("mvnforumconfig.disable_passwordless_auth", true);
            REQUIRE_ACTIVATION = conf.getBoolean("mvnforumconfig.require_activation", false);
            ENABLE_LOGIN_INFO_IN_COOKIE = conf.getBoolean("mvnforumconfig.enable_login_info_in_cookie", true);
            ENABLE_LOGIN_INFO_IN_SESSION = conf.getBoolean("mvnforumconfig.enable_login_info_in_session", true);
            ENABLE_LOGIN_INFO_IN_REALM = conf.getBoolean("mvnforumconfig.enable_login_info_in_realm", false);
            ENABLE_LOGIN_INFO_IN_CUSTOMIZATION = conf.getBoolean("mvnforumconfig.enable_login_info_in_customization", false);

            ENABLE_LOGIN = conf.getBoolean("mvnforumconfig.enable_login", true);
            ENABLE_NEW_MEMBER = conf.getBoolean("mvnforumconfig.enable_new_member", true);
            ENABLE_NEW_POST = conf.getBoolean("mvnforumconfig.enable_new_post", true);
            ENABLE_AVATAR = conf.getBoolean("mvnforumconfig.enable_avatar", true);
            ENABLE_EMOTICON = conf.getBoolean("mvnforumconfig.enable_emoticon", true);
            ENABLE_RSS = conf.getBoolean("mvnforumconfig.enable_rss", true);
            ENABLE_WATCH = conf.getBoolean("mvnforumconfig.enable_watch", true);
            ENABLE_ATTACHMENT = conf.getBoolean("mvnforumconfig.enable_attachment", true);
            ENABLE_CAPTCHA = conf.getBoolean("mvnforumconfig.enable_captcha", false);
            ENABLE_NEW_INDEX_PAGE = conf.getBoolean("mvnforumconfig.enable_new_index_page", true);

            MAX_ATTACHMENT_SIZE = parseIntSizeValue(conf.getString("mvnforumconfig.max_attachment_size"), 1024);
            if (MAX_ATTACHMENT_SIZE < 0) MAX_ATTACHMENT_SIZE = 0;

            MAX_FAVORITE_THREAD = conf.getInt("mvnforumconfig.max_favorite_thread", 128);
            if (MAX_FAVORITE_THREAD < 0) MAX_FAVORITE_THREAD = 0;

            MAX_EDIT_DAYS = conf.getInt("mvnforumconfig.max_edit_days", 7);
            if (MAX_EDIT_DAYS < 0) MAX_EDIT_DAYS = 0;

            MAX_ATTACH_DAYS = conf.getInt("mvnforumconfig.max_attach_days", 1);
            if (MAX_ATTACH_DAYS < 0) MAX_ATTACH_DAYS = 0;

            MAX_DELETE_DAYS = conf.getInt("mvnforumconfig.max_delete_days", 1);
            if (MAX_DELETE_DAYS < 0) MAX_DELETE_DAYS = 0;

            ROWS_PER_PAGE = conf.getInt("mvnforumconfig.rows_per_page", 10);
            if (ROWS_PER_PAGE < 5) ROWS_PER_PAGE = 5;

            ROWS_PER_RSS = conf.getInt("mvnforumconfig.rows_per_rss", 15);
            if (ROWS_PER_RSS < 5) ROWS_PER_RSS = 5;

            HOT_TOPIC_THRESHOLD = conf.getInt("mvnforumconfig.hot_topic_threshold", 10);
            if (HOT_TOPIC_THRESHOLD < 5) HOT_TOPIC_THRESHOLD = 5;

            MAX_POSTS_PER_HOUR = conf.getInt("mvnforumconfig.max_posts_per_hour", MAX_POSTS_PER_HOUR);
            if (MAX_POSTS_PER_HOUR < 0) MAX_POSTS_PER_HOUR = 0;

            MAX_MEMBERS_PER_HOUR = conf.getInt("mvnforumconfig.max_members_per_hour", MAX_MEMBERS_PER_HOUR);
            if (MAX_MEMBERS_PER_HOUR < 0) MAX_MEMBERS_PER_HOUR = 0;

            MAX_LOGINS_PER_HOUR = conf.getInt("mvnforumconfig.max_logins_per_hour", MAX_LOGINS_PER_HOUR);
            if (MAX_LOGINS_PER_HOUR < 0) MAX_LOGINS_PER_HOUR = 0;

            ENABLE_BACKUP_ON_SERVER = conf.getBoolean("mvnforumconfig.enable_backup_on_server", true);
            MAX_IMPORT_SIZE = parseIntSizeValue(conf.getString("mvnforumconfig.max_import_size", "4096000"), 4096000 );

            DEFAULT_WATCH_OPTION = conf.getInt("mvnforumconfig.default_watch_option", 0);
            if (DEFAULT_WATCH_OPTION < 0 || DEFAULT_WATCH_OPTION > 4) DEFAULT_WATCH_OPTION = 0;

            DEFAULT_MODERATION_OPTION = conf.getInt("mvnforumconfig.default_moderation_option", 0);
            if (DEFAULT_MODERATION_OPTION < 0 || DEFAULT_MODERATION_OPTION > 4) DEFAULT_MODERATION_OPTION = 0;

            // now check if Guest user is in database or not
            try {
                DAOFactory.getMemberDAO().getMember_forPublic(MVNForumConstant.MEMBER_ID_OF_GUEST);
                m_guestUserInDatabase = true;
            } catch (ObjectNotFoundException ex) {
                // dont have Guest user in database, just ignore
            } catch (Exception ex) {
                log.info("Error occured when get Guest user.", ex);
            }

            FloodControl.setOption(MVNForumGlobal.FLOOD_ID_NEW_MEMBER, MAX_MEMBERS_PER_HOUR);
            FloodControl.setOption(MVNForumGlobal.FLOOD_ID_NEW_POST, MAX_POSTS_PER_HOUR);
            FloodControl.setOption(MVNForumGlobal.FLOOD_ID_LOGIN, MAX_LOGINS_PER_HOUR);

            // Load FreeMarker configuration
            freeMarkerConfiguration = Configuration.getDefaultConfiguration();
            FileTemplateLoader templateLoader = new FileTemplateLoader(new File(MVNForumConfig.getTemplateDir()));
            freeMarkerConfiguration.setTemplateLoader(templateLoader);
        } catch (Exception e) {
            String message = "com.mvnforum.MVNForumConfig: Can't read the configuration file: '" + OPTION_FILE_NAME + "'. Make sure the file is in your CLASSPATH";
            log.error(message, e);
            m_shouldRun = false;
            m_reason = message;
        }
    }
}

⌨️ 快捷键说明

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