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

📄 forumpropertiesmanager.java

📁 一个用jsp写的完整的论坛源代码
💻 JAVA
字号:
package com.bcxy.bbs.forum;

/**
 * Title:
 * Description:
 * Copyright:
 * Company: www.liyunet.com
 * 
 * @author lishujiang	
 * @version 1.0
 */

import java.util.Hashtable;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

import com.bcxy.bbs.util.BBSConst;
import com.bcxy.bbs.util.ParamUtil;
import com.bcxy.db.JdbcWrapper;

public class ForumPropertiesManager {

	private static Logger log = Logger.getLogger(ForumPropertiesManager.class);

	private static ForumPropertiesManager manager = null;

	private static Hashtable forumHash = new Hashtable();

	/**
	 * 重新读取配置信息
	 *
	 */
	public static void resetManager() {
		manager = null;
	}

	/**
	 * 根据变量名称取得配置值
	 * 
	 * @param name
	 * @param def
	 * @return
	 */
	public static String getString(String name, String def) {
		try {
			if ("".equals(getString(name))) {
				return def;
			} else {
				return getString(name);
			}
		} catch (Exception e) {
			return def;
		}
	}

	public static String getString(String name) throws Exception {
		if (manager == null) {
			synchronized (ForumPropertiesManager.class) {
				if (manager == null) {
					manager = new ForumPropertiesManager();
				}
			}
		}
		return manager.getStr(name);
	}

	public int getInt(String name, int def) {
		try {
			return Integer.parseInt(getString(name));
		} catch (Exception e) {
			return def;
		}
	}

	public int getInt(String name){
		return getInt(name, 0);
	}
	
	/**
	 * 初始化配置信息
	 *
	 */
	public ForumPropertiesManager() {
		JdbcWrapper jw = new JdbcWrapper();
		try {
			jw.executeQuery("select * from " + BBSConst.TABLE_CONFIG + "");
			if (jw.next()) {
				String[] rsmd = jw.getColumnName();
				for (int i = 0; i < rsmd.length; i++) {
					String col = jw.get(i + 1);
					// 将字段名称转换为大写
					forumHash.put(((String) rsmd[i]).toUpperCase(), col);
				}
			} else {
				throw new Exception("数据库配置表[" + BBSConst.TABLE_CONFIG + "]无数据");
			}
		} catch (Exception e) {
			log.error("初始化系统配置出错", e);
		} finally {
			jw.close();
		}
	}

	private String getStr(String name) throws Exception {
		if (forumHash.isEmpty()) {
			throw new Exception("未初始化系统配置参数,您确定系统配置表[" + BBSConst.TABLE_CONFIG
					+ "]是否正常");
		}
		if (forumHash.containsKey(name.toUpperCase())) {
			return (String) forumHash.get(name.toUpperCase());
		} else {
			log.warn("系统配置表中[" + name.toUpperCase() + "]的值不存在");
			return "";
		}
	}

	public Hashtable getHashtable() {
		return forumHash;
	}

	/**
	 * 保存变量信息
	 * 
	 * @param request
	 * @throws Exception
	 */
	public static void saveGrade(HttpServletRequest request) throws Exception {
		int wealthReg, wealthLogin, wealthAnnounce, wealthReAnnounce, wealthDel;
		int epReg, epLogin, epAnnounce, epReAnnounce, epDel;
		int cpReg, cpLogin, cpAnnounce, cpReAnnounce, cpDel;
		try {
			wealthReg = ParamUtil.getInt(request, "wealthReg");
			wealthLogin = ParamUtil.getInt(request, "wealthLogin");
			wealthAnnounce = ParamUtil.getInt(request, "wealthAnnounce");
			wealthReAnnounce = ParamUtil.getInt(request, "wealthReAnnounce");
			wealthDel = ParamUtil.getInt(request, "wealthDel");

			epReg = ParamUtil.getInt(request, "epReg");
			epLogin = ParamUtil.getInt(request, "epLogin");
			epAnnounce = ParamUtil.getInt(request, "epAnnounce");
			epReAnnounce = ParamUtil.getInt(request, "epReAnnounce");
			epDel = ParamUtil.getInt(request, "epDel");

			cpReg = ParamUtil.getInt(request, "cpReg");
			cpLogin = ParamUtil.getInt(request, "cpLogin");
			cpAnnounce = ParamUtil.getInt(request, "cpAnnounce");
			cpReAnnounce = ParamUtil.getInt(request, "cpReAnnounce");
			cpDel = ParamUtil.getInt(request, "cpDel");
		} catch (Exception e) {
			log.error("输入论坛变量必须为数字", e);
			throw new Exception("请您输入的为数字!");
		}
		String sql = "update " + BBSConst.TABLE_CONFIG + " set " + "wealthReg="
				+ wealthReg + ",wealthLogin=" + wealthLogin
				+ ",wealthAnnounce=" + wealthAnnounce + ",wealthDel="
				+ wealthDel + ",wealthReAnnounce=" + wealthReAnnounce
				+ ",epReg=" + epReg + ",epLogin=" + epLogin + ",epAnnounce="
				+ epAnnounce + ",epDel=" + epDel + ",epReAnnounce="
				+ epReAnnounce + ",cpReg=" + cpReg + ",cpLogin=" + cpLogin
				+ ",cpAnnounce=" + cpAnnounce + ",cpDel=" + cpDel
				+ ",cpReAnnounce=" + cpReAnnounce;
		JdbcWrapper jw = new JdbcWrapper();
		try {
			jw.executeUpdate(sql);
		} catch (Exception e) {
			log.error("论坛变量设置出错", e);
			throw new Exception("论坛变量设置出错,请检查输入是否正确!");
		} finally {
			jw.close();
		}
		ForumPropertiesManager.resetManager();
	}

	/**
	 * 保存配置变量信息
	 * 
	 * @param request
	 * @throws Exception
	 */
	public static void saveConst(HttpServletRequest request) throws Exception {

		String forumName = ParamUtil.getString(request, "forumName");
		if (forumName == null || "".equals(forumName.trim()))
			throw new Exception("请您输入论坛的名称!");
		String forumURL = ParamUtil.getString(request, "forumURL");
		if (forumURL == null || "".equals(forumURL.trim()))
			throw new Exception("请您输入论坛的连接地址!");
		String companyName = ParamUtil.getString(request, "companyName");
		if (companyName == null || "".equals(companyName.trim()))
			throw new Exception("请您输入主页的名称!");
		String hostURL = ParamUtil.getString(request, "hostURL");
		if (hostURL == null || "".equals(hostURL.trim()))
			throw new Exception("请您输入主页的地址!~");
		String SMTPServer = ParamUtil.getString(request, "SMTPServer");
		if (SMTPServer == null || "".equals(SMTPServer.trim()))
			throw new Exception("请您输入邮件服务器的地址!");
		String systemEmail = ParamUtil.getString(request, "systemEmail");
		if (systemEmail == null || "".equals(systemEmail.trim()))
			throw new Exception("请您填写邮件的发送人地址");
		int timeAdjust = ParamUtil.getInt(request, "timeAdjust", 0);
		int scriptTimeOut = ParamUtil.getInt(request, "scriptTimeOut", 300);
		String logo = ParamUtil.getString(request, "forumLogo");
		if (logo == null || "".equals(logo.trim()))
			throw new Exception("请您填写论坛的logo地址!");
		String picURL = ParamUtil.getString(request, "picURL");
		if (picURL == null || "".equals(picURL.trim()))
			throw new Exception("请您填写论坛图片的目录!");
		String faceURL = ParamUtil.getString(request, "faceURL");
		if (faceURL == null || "".equals(faceURL.trim()))
			throw new Exception("请您填写论坛的表情目录!");

		int emailFlag = ParamUtil.getInt(request, "emailFlag", 0);
		int uploadPic = ParamUtil.getInt(request, "uploadPic", 0);
		int ipFlag = ParamUtil.getInt(request, "ipFlag", 0);
		int fromFlag = ParamUtil.getInt(request, "fromFlag", 0);
		int titleFlag = ParamUtil.getInt(request, "titleFlag", 0); // 用户头衔
		int uploadFlag = ParamUtil.getInt(request, "uploadFlag", 0);
		int guestUser = ParamUtil.getInt(request, "guestUser", 0);
		String openMSG = ParamUtil.getString(request, "openMSG", "");
		String announceMaxBytes = ParamUtil.getString(request,
				"announceMaxBytes", "");
		String maxAnnouncePerPage = ParamUtil.getString(request,
				"maxAnnouncePerPage", "");
		String maxTitleList = ParamUtil.getString(request, "maxTitleList", "");
		String tableBackColor = ParamUtil.getString(request, "tableBackColor");
		String aTableBackColor = ParamUtil
				.getString(request, "aTableBackColor");
		String tableTitleColor = ParamUtil
				.getString(request, "tableTitleColor");
		String aTableTitleColor = ParamUtil.getString(request,
				"aTableTitleColor");
		String tableFontColor = ParamUtil.getString(request, "tableFontColor");
		String tableContentColor = ParamUtil.getString(request,
				"tableContentColor");
		String alertFontColor = ParamUtil.getString(request, "alertFontColor");
		String contentTitle = ParamUtil.getString(request, "contentTitle");
		String tableBodyColor = ParamUtil.getString(request, "tableBodyColor");
		String aTableBodyColor = ParamUtil
				.getString(request, "aTableBodyColor");
		String bodyBgImage = ParamUtil.getString(request, "bodyBgImage", "");
		String ads1 = ParamUtil.getString(request, "ads1", "");
		String ads2 = ParamUtil.getString(request, "ads2", "");
		String copyRight = ParamUtil.getString(request, "copyRight", "");
		String version = ParamUtil.getString(request, "version", "");
		String regMsg = ParamUtil.getString(request, "regmsg", "");
		String tableWidth = ParamUtil.getString(request, "tableWidth", "98%");
		//
		JdbcWrapper jw = new JdbcWrapper();
		try {
			String sql = "update "
					+ BBSConst.TABLE_CONFIG
					+ " set forumName=?,forumURL=?,companyName=?,hostURL=?,SMTPServer=?"
					+ ",systemEmail=?,timeAdjust='"
					+ timeAdjust
					+ "',scriptTimeOut='"
					+ scriptTimeOut
					+ "',logo=?"
					+ ",picURL=?,faceURL=?,emailFlag="
					+ emailFlag
					+ ",uploadPic="
					+ uploadPic
					+ ",ipFlag="
					+ ipFlag
					+ ",fromFlag="
					+ fromFlag
					+ ",uploadFlag="
					+ uploadFlag
					+ ",guestUser="
					+ guestUser
					+ ",openMSG='"
					+ openMSG
					+ "',maxAnnouncePerPage='"
					+ maxAnnouncePerPage
					+ "',announceMaxBytes='"
					+ announceMaxBytes
					+ "',maxAnnouncePerPage='"
					+ maxAnnouncePerPage
					+ "',maxTitleList='"
					+ maxTitleList
					+ "',tableBackColor='"
					+ tableBackColor
					+ "',aTableBackColor='"
					+ aTableBackColor
					+ "',tableTitleColor='"
					+ tableTitleColor
					+ "',aTableTitleColor='"
					+ aTableTitleColor
					+ "',tableFontColor='"
					+ tableFontColor
					+ "', tableContentColor='"
					+ tableContentColor
					+ "',alertFontColor='"
					+ alertFontColor
					+ "', contentTitle='"
					+ contentTitle
					+ "',tableBodyColor='"
					+ tableBodyColor
					+ "', aTableBodyColor='"
					+ aTableBodyColor
					+ "',ads1=?"
					+ ", ads2=?,copyRight=?, version=?, bodyBgImage=?, TitleFlag=?, RegMsg=?, tableWidth=?";

			jw.prepareStatement(sql);
			int i = 1;
			jw.setString(i++, forumName);
			jw.setString(i++, forumURL);
			jw.setString(i++, companyName);
			jw.setString(i++, hostURL);
			jw.setString(i++, SMTPServer);
			jw.setString(i++, systemEmail);
			jw.setString(i++, logo);
			jw.setString(i++, picURL);
			jw.setString(i++, faceURL);
			jw.setString(i++, ads1);
			jw.setString(i++, ads2);
			jw.setString(i++, copyRight);
			jw.setString(i++, version);
			jw.setString(i++, bodyBgImage);
			jw.setInt(i++, titleFlag);
			jw.setString(i++, regMsg);
			jw.setString(i++, tableWidth);
			jw.executeUpdate();
		} catch (Exception e) {
			log.error("论坛信息设置出错", e);
			throw new Exception("设置出错,请检查输入是否正确!");
		} finally {
			jw.close();
		}
		resetManager();
	}
}

⌨️ 快捷键说明

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