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

📄 msgdb.java~170~

📁 云网论坛CWBBS 源码,内容丰富,学习,参考,教学的好资料,具体见内说明,
💻 JAVA~170~
📖 第 1 页 / 共 5 页
字号:
package com.redmoon.forum;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2002
 * Company:
 * @author
 * @version 1.0
 */
import java.io.File;
import java.io.IOException;
import java.sql.*;
import java.sql.Date;
import java.util.*;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import cn.js.fan.cache.jcs.RMCache;
import cn.js.fan.db.*;
import cn.js.fan.mail.SendMail;
import cn.js.fan.security.SecurityUtil;
import cn.js.fan.util.*;
import cn.js.fan.web.Global;
import cn.js.fan.web.SkinUtil;
import com.redmoon.blog.UserConfigDb;
import com.redmoon.blog.UserDirDb;
import com.redmoon.forum.person.UserDb;
import com.redmoon.forum.plugin.*;
import com.redmoon.forum.plugin.base.IPluginMsgAction;
import com.redmoon.forum.plugin.base.IPluginScore;
import com.redmoon.kit.util.FileInfo;
import com.redmoon.kit.util.FileUpload;
import org.apache.log4j.Logger;
import com.redmoon.forum.message.MessageDb;
import com.redmoon.forum.person.UserPrivDb;

public class MsgDb implements java.io.Serializable {
    // public: connection parameters
    public static int LEVEL_TOP_BOARD = 100;
    public static int LEVEL_TOP_FORUM = 200;
    public static int LEVEL_NONE = 0;

    public static int WEBEDIT_UBB = 0;
    public static int WEBEDIT_REDMOON = 1;
    public static int WEBEDIT_NORMAL = 2;

    public static int MIN_CONTENT_LEN = 10;
    private String plugin2Code;
    public static int MAX_CONTENT_LEN = 3000;
    public static int MAX_CONTENT_LEN_WE = 20000;
    public static int MAX_TOPIC_LEN = 100;
    public static int MIN_TOPIC_LEN = 1;

    public static final int TYPE_MSG = 0;
    public static final int TYPE_VOTE = 1;

    static {
        initParam();
    }

    String connname = Global.defaultDB;

    // 序列化时,类的所有数据成员应可序列化除了声明为transient或static的成员。
    // 将变量声明为transient告诉JVM我们会负责将变元序列化。
    // 将数据成员声明为transient后,序列化过程就无法将其加进对象字节流中,
    // transient Logger Logger = Logger.getLogger(MsgDb.class.getName());

    int ret = 1;
    String boardcode = null, name, pwd,
                       title = "", content = "", picturename, ip;
    int show_smile = 1, show_ubbcode = 1, email_notify = 0;
    long rootid = -1;
    long id;
    int layer;
    java.util.Date addDate;
    int orders;

    int expression = 1;
    String fileName = "", filenm="";
    String rootpath;
    long replyid;

    boolean isInfoGeted = false;
    int DefaultFileSize = 200;
    int isWebedit = 0;

    public MsgDb() {
        init();
    }

    public MsgDb(long id) {
        init();
        loadFromDb(id);
    }

    public static void initParam() {
        com.redmoon.forum.Config cfg = new com.redmoon.forum.Config();
        MIN_TOPIC_LEN = cfg.getIntProperty("forum.msgTitleLengthMin");
        MAX_TOPIC_LEN = cfg.getIntProperty("forum.msgTitleLengthMax");
        MIN_CONTENT_LEN = cfg.getIntProperty("forum.msgLengthMin");
        MAX_CONTENT_LEN = cfg.getIntProperty("forum.msgLengthMax");

        MAX_CONTENT_LEN_WE = MAX_CONTENT_LEN;
    }

    public void init() {
    }

    protected void finalize() throws Throwable {
        super.finalize();
    }

    public String getFileName() {
        return fileName;
    }

    private int recount;

    public String getboardcode() {
        return boardcode;
    }

    /**
     * 取得当前处理的boardcode,用于oscache刷新缓存,oscache已放弃,主要是其原理适合于页面的缓存,但对于对象的缓存不是很方便
     * @return String
     */
    public String getCurBoardCode() {
        return boardcode;
    }

    /**@task:需优化
     * 取得year年month月中每天的日志数
     * @param year int
     * @param month int First month begin with 1
     * @return int[] First day begin with 1
     */
    public int[] getBlogMsgDayCount(String userName, int year, int month) {
        // System.out.println("month=" + month);
        // 取得year-month这个月的天数
        int dayCount = DateUtil.getDayCount(year, month-1);
        // System.out.println("day=" + dayCount);
        int[] ary = new int[dayCount + 1];
        for (int i = 1; i <= dayCount; i++) {
            ary[i] = 0;
        }

        Calendar calStart = Calendar.getInstance();
        calStart.set(year, month-1, 1);
        String start = "" + calStart.getTimeInMillis();
        Calendar calEnd = Calendar.getInstance();
        calEnd.set(year, month-1, dayCount, 24, 60);
        String end = "" + calEnd.getTimeInMillis();

        String sql = "select lydate from sq_thread where name=? and isBlog=1 and lydate>? and lydate<? order by lydate asc";
        Conn conn = new Conn(connname);
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, userName);
            pstmt.setString(2, start);
            pstmt.setString(3, end);
            rs = conn.executePreQuery();
            Calendar cal = Calendar.getInstance();
            while (rs.next()) {
                java.util.Date d = DateUtil.parse(rs.getString(1));
                cal.setTime(d);
                ary[cal.get(cal.DAY_OF_MONTH)] ++;
            }
        } catch (SQLException e) {
            Logger.getLogger(MsgDb.class.getName()).error("getBlogMsgDayCount:" + e.getMessage());
        } finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (Exception e) {}
                rs = null;
            }
            if (pstmt != null) {
                try {
                    pstmt.close();
                } catch (Exception e) {}
                pstmt = null;
            }
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
        return ary;
    }

    /**
     * 取得y年m月d日的用户日志
     * @param userName String
     * @param y int
     * @param m int
     * @param d int
     * @return Vector
     */
    public Vector getBlogDayList(String userName, int y, int m, int d) {
        String sql = "select id from sq_thread where name=? and isBlog=1 and lydate>? and lydate<? order by lydate asc";
        Calendar calStart = Calendar.getInstance();
        calStart.set(y, m-1, d, 0, 0, 0);
        String start = "" + calStart.getTimeInMillis();
        Calendar calEnd = Calendar.getInstance();
        calEnd.set(y, m-1, d, 23, 59, 59);
        String end = "" + calEnd.getTimeInMillis();

        PreparedStatement pstmt = null;
        ResultSet rs = null;
        Vector v = new Vector();
        Conn conn = new Conn(connname);
        try {
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, userName);
            pstmt.setString(2, start);
            pstmt.setString(3, end);
            // url,title,image,userName,sort,kind
            rs = conn.executePreQuery();
            Calendar cal = Calendar.getInstance();
            while (rs.next()) {
                MsgDb md = getMsgDb(rs.getLong(1));
                v.addElement(md);
            }
        } catch (SQLException e) {
            Logger.getLogger(MsgDb.class.getName()).error("getBlogDayList:" + e.getMessage());
        } finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (Exception e) {}
                rs = null;
            }
            if (pstmt != null) {
                try {
                    pstmt.close();
                } catch (Exception e) {}
                pstmt = null;
            }
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
        return v;
    }

    public String LoadString(HttpServletRequest request, String key) {
        return SkinUtil.LoadString(request, "res.forum.MsgDb", key);
    }

    public boolean CheckTopic(HttpServletRequest req, FileUpload TheBean) throws ErrMsgException {
        if (ret == FileUpload.RET_TOOLARGESINGLE) {
            throw new ErrMsgException(LoadString(req, "err_too_large")); // "您上传的文件太大!");
        }
        if (ret == FileUpload.RET_INVALIDEXT) {
            throw new ErrMsgException(TheBean.getErrMessage(req));
        }

        String errMsg = "";

        title = TheBean.getFieldValue("topic");
        if (title == null || title.trim().equals(""))
            errMsg += LoadString(req, "err_need_title"); // 请输入主题;
        boardcode = TheBean.getFieldValue("boardcode");
        if (boardcode == null || boardcode.trim().equals(""))
            errMsg += LoadString(req, "err_need_board"); // 请选择论坛;
        content = TheBean.getFieldValue("Content");
        String sIsWebedit = TheBean.getFieldValue("isWebedit");
        if (sIsWebedit==null || sIsWebedit.equals(""))
            isWebedit = WEBEDIT_UBB;
        else
            isWebedit = WEBEDIT_NORMAL;

        // 过滤title与content
        ForumDb fd = new ForumDb();
        fd = fd.getForumDb();
        fd.FilterMsg(req, title);
        fd.FilterMsg(req, content);

        // Logger.getLogger(MsgDb.class.getName()).error("content=" + content);
        expression = Integer.parseInt(TheBean.getFieldValue("expression"));
        ip = req.getRemoteAddr();

        String strshow_smile = TheBean.getFieldValue("show_smile");
        if (strshow_smile == null || strshow_smile.equals(""))
            show_smile = 1;
        else
            show_smile = Integer.parseInt(strshow_smile);
        String strshow_ubbcode = TheBean.getFieldValue("show_ubbcode");
        if (strshow_ubbcode == null || strshow_ubbcode.equals(""))
            show_ubbcode = 1;
        else
            show_ubbcode = Integer.parseInt(strshow_ubbcode);
        String stremail_notify = TheBean.getFieldValue("email_notify");
        if (stremail_notify == null || stremail_notify.equals(""))
            email_notify = 0;
        else
            email_notify = Integer.parseInt(stremail_notify);
        String strIsBlog = StrUtil.getNullStr(TheBean.getFieldValue("isBlog"));
        if (strIsBlog.equals("1"))

⌨️ 快捷键说明

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