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

📄 msgdb.java~171~

📁 云网论坛CWBBS 源码,内容丰富,学习,参考,教学的好资料,具体见内说明,
💻 JAVA~171~
📖 第 1 页 / 共 5 页
字号:
            blog = true;
        else {
            if (boardcode.equals(Leaf.CODE_BLOG))
                blog = true;
            else
                blog = false;
        }
        if (blog)
            blogUserDir = TheBean.getFieldValue("blogUserDir");
        plugin2Code = StrUtil.getNullStr(TheBean.getFieldValue("plugin2Code")).trim();
        pluginCode = StrUtil.getNullStr(TheBean.getFieldValue("pluginCode")).trim();
        if (!errMsg.equals("")) {
            throw new ErrMsgException(errMsg);
        }
        return true;
    }

    /**
     * 发新贴,适用于普通和ubb方式
     * @param application ServletContext
     * @param request HttpServletRequest
     * @param name String
     * @param TheBean FileUpload
     * @return boolean
     * @throws ErrMsgException
     * @throws ResKeyException
     */
    public boolean AddNew(ServletContext application,
                          HttpServletRequest request,
                          String name, FileUpload TheBean) throws
            ErrMsgException, ResKeyException {
        this.name = name;
        try {
            CheckTopic(request, TheBean);
        } catch (ErrMsgException e) {
            throw e;
        }
        rootpath = request.getContextPath();
        // 投票处理
        String isvote = TheBean.getFieldValue("isvote");
        String[] voptions = null;
        if (isvote != null && isvote.equals("1")) {
            String voteoption = TheBean.getFieldValue("vote").trim();
            if (!voteoption.equals("")) {
                voptions = voteoption.split("\n");
            }
            if (voteoption.indexOf("|") != -1)
                throw new ErrMsgException(LoadString(request, "err_vote_option")); // "投票选项中不能包含|");
        }

        String sql = "";

        int length = 0;
        if (title != null)
            length = title.length();
        if (length < MIN_TOPIC_LEN)
            throw new ErrMsgException(LoadString(request, "err_too_short_title") + MIN_TOPIC_LEN); // "您输入的主题内容太短了,最短不能少于" + MIN_TOPIC_LEN);
        if (length > MAX_TOPIC_LEN)
            throw new ErrMsgException(LoadString(request, "err_too_large_title") + MAX_TOPIC_LEN); // "您输入的主题内容太长了,最长不能超过" + MAX_TOPIC_LEN);
        if (content != null)
            length = content.length();
        if (length < MIN_CONTENT_LEN)
            throw new ErrMsgException(LoadString(request, "err_too_short_content") + MIN_CONTENT_LEN);
        if (length > MAX_CONTENT_LEN)
            throw new ErrMsgException(LoadString(request, "err_too_large_content") + MAX_CONTENT_LEN);

        id = SequenceMgr.nextID();
        int intIsBlog = blog ? 1 : 0;

        FileInfo fi = null;
        Vector v = TheBean.getFiles();
        int size = v.size();

        String[] fileNameAry = null;
        if (size > 0) {
            fi = (FileInfo) v.get(0); // 取得第一个附件
            // 为每个附件生成文件名
            fileNameAry = new String[size];
            for (int i=0; i<size; i++) {
                fileNameAry[i] = FileUpload.getRandName() + "." + ((FileInfo)v.get(i)).getExt();
            }
        }

        String virtualpath = "";

        int msgType = 0;
        String voteresult = "", votestr = "";

        picturename = "";
        if (ret == FileUpload.RET_SUCCESS && fi!=null) {
            extName = fi.getExt();
            Calendar cal = Calendar.getInstance();
            String year = "" + (cal.get(cal.YEAR));
            String month = "" + (cal.get(cal.MONTH) + 1);
            String filepath = Global.getRealPath() + "forum/upfile/" +
                              year + "/" + month +
                              "/";
            File f = new File(filepath);
            if (!f.isDirectory()) {
                f.mkdirs();
            }

            virtualpath = "upfile/" + year +
                                 "/" +
                                 month;
            TheBean.setSavePath(filepath); // 设置保存的目录

            picturename = fileNameAry[0];
            picturename = virtualpath + "/" + picturename;

            Iterator ir = v.iterator();
            int k = 0;
            while (ir.hasNext()) {
                fi = (FileInfo)ir.next();
                extName = fi.getExt();

                String ubbtype = "";
                if (extName.equalsIgnoreCase("gif") ||
                    extName.equalsIgnoreCase("jpg") ||
                    extName.equalsIgnoreCase("png") || extName.equalsIgnoreCase("bmp"))
                    ubbtype = "img";
                else if (extName.equalsIgnoreCase("swf"))
                    ubbtype = "flash";
                else
                    ubbtype = "URL";
                if (isWebedit == WEBEDIT_UBB) {
                    if (ubbtype.equals("img"))
                        content = "\n[" + ubbtype + "]" + rootpath + "/forum/" +
                                  virtualpath + "/" +
                                  fileNameAry[k] + "[/" + ubbtype + "]\n" +
                                  content;
                    else if (ubbtype.equals("flash"))
                        content = "\n[" + ubbtype + "]" + rootpath + "/forum/" +
                                  virtualpath + "/" +
                                  fileNameAry[k] + "[/" +
                                  ubbtype + "]\n" + content;
                } else {
                    if (ubbtype.equals("img"))
                        // content = "<BR><img src='" + rootpath + "/forum/" +
                        //           virtualpath + "/" +
                        //           picturename + "'><BR>" + content;
                        content = "<BR><a onfocus=this.blur() href=\"" + rootpath + "/forum/" + virtualpath + "/" + fileNameAry[k] + "\" target=_blank><IMG SRC=\"" + rootpath + "/forum/" + virtualpath + "/" + fileNameAry[k] + "\" border=0 alt=" + SkinUtil.LoadString(request, "res.cn.js.fan.util.StrUtil", "click_open_win") + " onmousewheel='return zoomimg(this)' onload=\"javascript:if(this.width>screen.width-333)this.width=screen.width-333\"></a><BR>" + content;
                    else if (ubbtype.equals("flash"))
                        content = "\n[" + ubbtype + "]" + rootpath + "/forum/" +
                                  virtualpath + "/" +
                                  fileNameAry[k] + "[/" +
                                  ubbtype + "]\n" + content;
                }
                k++;
            }

            if (voptions != null) { // 投票处理
                msgType = 1;
                int len = voptions.length;
                for (k = 0; k < len; k++) {
                    if (voteresult.equals("")) {
                        voteresult = "0";
                        votestr = voptions[k];
                    } else {
                        voteresult += "|" + "0";
                        votestr += "|" + voptions[k];
                    }
                }
            }
        } else {
            if (voptions != null) {
                msgType = 1;
                int len = voptions.length;
                for (int k = 0; k < len; k++) {
                    if (voteresult.equals("")) {
                        voteresult = "0";
                        votestr = voptions[k];
                    } else {
                        voteresult += "|" + "0";
                        votestr += "|" + voptions[k];
                    }
                }
            }
        }

        boolean re = false;

        Conn conn = new Conn(connname);
        try {
            conn.beginTrans();
            // 插入thread,thread仅用来排序、索引、列表,所以无需进行对象的缓存,只有列表的缓存
            String insertThreadSql = "insert into sq_thread (id,boardcode,msg_level,iselite,lydate,redate,name,blogUserDir,isBlog) values (?,?,?,?,?,?,?,?,?)";
            PreparedStatement ps = conn.prepareStatement(insertThreadSql);
            ps.setLong(1, id);
            ps.setString(2, boardcode);
            ps.setInt(3, level);
            ps.setInt(4, isElite);
            ps.setString(5, "" + System.currentTimeMillis());
            ps.setString(6, "" + System.currentTimeMillis());
            ps.setString(7, name);
            ps.setString(8, blogUserDir);
            ps.setInt(9, blog?1:0);
            conn.executePreUpdate();

            if (ps!=null) {
                ps.close();
                ps = null;
            }

            // 需使用preparestatement,比如在oracel中sql字符串的长度是有限制的 20060909
            sql = "insert into sq_message (id,rootid,boardcode,name,title,content,length,expression,lydate,ip,filename,extname,MSG_TYPE,voteoption,voteresult,show_ubbcode,show_smile,iswebedit,redate,colorExpire,boldExpire,isBlog,blogUserDir,plugin2Code,email_notify,msg_kind,pluginCode) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            ps = conn.prepareStatement(sql);
            ps.setLong(1, id);
            ps.setLong(2, id);
            ps.setString(3, boardcode);
            ps.setString(4, name);
            ps.setString(5, title);
            ps.setString(6, content);
            ps.setInt(7, length);
            ps.setInt(8, expression);
            ps.setString(9, "" + System.currentTimeMillis());
            ps.setString(10, ip);
            ps.setString(11, picturename);
            ps.setString(12, extName);
            ps.setInt(13, msgType);
            ps.setString(14, votestr);
            ps.setString(15, voteresult);
            ps.setInt(16, show_ubbcode);
            ps.setInt(17, show_smile);
            ps.setInt(18, isWebedit);
            ps.setString(19, "" + System.currentTimeMillis());
            ps.setString(20, "" + System.currentTimeMillis());
            ps.setString(21, "" + System.currentTimeMillis());
            ps.setInt(22, intIsBlog);
            ps.setString(23, blogUserDir);
            ps.setString(24, plugin2Code);
            ps.setInt(25, email_notify);
            ps.setString(26, kind);
            ps.setString(27, pluginCode);
            conn.executePreUpdate();

            if (ps!=null) {
                ps.close();
                ps = null;
            }

            // 保存上传的图片
            if (ret == FileUpload.RET_SUCCESS && fi != null) {
                // fi.write(TheBean.getSavePath(), picturename);
                Iterator ir = v.iterator();
                // 将附件保存至数据库
                int orders = 1;
                int i = 0;
                while (ir.hasNext()) {
                    fi = (FileInfo) ir.next();
                    fi.write(TheBean.getSavePath(), fileNameAry[i]);
                    String fpath = TheBean.getSavePath() + fi.getDiskName();
                    long attachId = SequenceMgr.nextID(SequenceMgr.SQ_MESSAGE_ATTACH);
                    sql =
                            "insert into sq_message_attach (id,fullpath,msgId,name,diskname,visualpath,orders,UPLOAD_DATE,FILE_SIZE,USER_NAME) values (" +
                            attachId + "," +
                            StrUtil.sqlstr(fpath) + "," + id + "," +
                            StrUtil.sqlstr(fi.getName()) + "," +
                            StrUtil.sqlstr(fi.getDiskName()) + "," +
                            StrUtil.sqlstr(virtualpath) + "," + orders +
                            "," + StrUtil.sqlstr("" + System.currentTimeMillis()) + "," + fi.getSize() + "," + StrUtil.sqlstr(name) + ")";
                    conn.executeUpdate(sql);
                    orders++;
                    i++;
                }
                if (i>0) {
                    // 加分
                    ScoreMgr sm = new ScoreMgr();
                    Vector vatt = sm.getAllScore();
                    Iterator iratt = vatt.iterator();
                    while (iratt.hasNext()) {
                        ScoreUnit su = (ScoreUnit) iratt.next();
                        IPluginScore ips = su.getScore();
                        if (ips != null)
                            ips.onAddAttachment(name, i);
                    }
                }

                UserPrivDb upd = new UserPrivDb();
                upd = upd.getUserPrivDb(name);
                upd.addAttachTodayUploadCount(i);
            }

            conn.commit();

            re = true;

            // 将msgId与上传的临时图片文件相关联
            String[] tmpAttachIds = TheBean.getFieldValues("tmpAttachId");
            if (tmpAttachIds != null) {
                int len = tmpAttachIds.length;
                for (int k = 0; k < len; k++) {
                    Attachment att = new Attachment(Long.parseLong(tmpAttachIds[
                            k]));
                    att.setMsgId(id);
                    att.save();
                }
                // 加分
                ScoreMgr sm = new ScoreMgr();
                Vector vatt = sm.getAllScore();
                Iterator iratt = vatt.iterator();
                while (iratt.hasNext()) {
                    ScoreUnit su = (ScoreUnit) iratt.next();
                    IPluginScore ips = su.getScore();

⌨️ 快捷键说明

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