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

📄 document.java

📁 云网论坛CWBBS 源码,内容丰富,学习,参考,教学的好资料,具体见内说明,
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                return dc.getContent();
            else {
                PluginMgr pm = new PluginMgr();
                PluginUnit pu = pm.getPluginUnit(pluginCode);
                IPluginRender ipr = pu.getUI(request).getRender();
                return ipr.RenderContent(request, dc);
            }
        } else
            return null;
    }

    public DocContent getDocContent(int pageNum) {
        DocContent dc = new DocContent();
        return dc.getDocContent(id, pageNum);
    }

    public boolean isCanComment() {
        return canComment;
    }

    public String getDirCode() {
        return class1;
    }

    public synchronized boolean UpdateWithoutFile(ServletContext application, CMSMultiFileUploadBean mfu) throws
            ErrMsgException {
        // 取得表单中域的信息
        String dir_code = StrUtil.getNullStr(mfu.getFieldValue("dir_code"));
        author = StrUtil.getNullString(mfu.getFieldValue("author"));
        title = StrUtil.getNullString(mfu.getFieldValue("title"));
        // logger.info("FilePath=" + FilePath);
        String strCanComment = StrUtil.getNullStr(mfu.getFieldValue(
                "canComment"));
        if (strCanComment.equals(""))
            canComment = false;
        else if (strCanComment.equals("1"))
            canComment = true;
        String strIsHome = StrUtil.getNullString(mfu.getFieldValue("isHome"));
        if (strIsHome.equals(""))
            isHome = false;
        else if (strIsHome.equals("false"))
            isHome = false;
        else if (strIsHome.equals("true"))
            isHome = true;
        else
            isHome = false;
        String strexamine = mfu.getFieldValue("examine");
        int oldexamine = examine;
        examine = Integer.parseInt(strexamine);
        String strisnew = StrUtil.getNullStr(mfu.getFieldValue("isNew"));
        if (StrUtil.isNumeric(strisnew))
            isNew = Integer.parseInt(strisnew);
        else
            isNew = 0;

        keywords = StrUtil.getNullStr(mfu.getFieldValue("keywords"));
        String strisRelateShow = StrUtil.getNullStr(mfu.getFieldValue("isRelateShow"));
        int intisRelateShow = 0;
        if (StrUtil.isNumeric(strisRelateShow)) {
            intisRelateShow = Integer.parseInt(strisRelateShow);
            if (intisRelateShow==1)
                isRelateShow = true;
        }

        flowTypeCode = StrUtil.getNullString(mfu.getFieldValue("flowTypeCode"));

        color = StrUtil.getNullStr(mfu.getFieldValue("color"));
        bold = StrUtil.getNullStr(mfu.getFieldValue("isBold")).equals("true");
        expireDate = DateUtil.parse(mfu.getFieldValue("expireDate"), "yyyy-MM-dd");
        source = StrUtil.getNullStr(mfu.getFieldValue("source"));
        try {
            pageTemplateId = Integer.parseInt(mfu.getFieldValue(
                    "pageTemplateId"));
        }
        catch (Exception e) {
            pageTemplateId = -1;
        }
        String docType = StrUtil.getNullStr(mfu.getFieldValue("docType"));
        if (!docType.equals("" + TYPE_VOTE)) {
            type = Integer.parseInt(docType);
        }

        if (!dir_code.equals(class1)) {
            Leaf lf = new Leaf();
            lf = lf.getLeaf(dir_code);
            parentCode = lf.getParentCode();
        }

        Conn conn = new Conn(connname);
        PreparedStatement pstmt = null;
        try {
            //更新文件内容
            pstmt = conn.prepareStatement(SAVE_DOCUMENT);
            pstmt.setString(1, title);
            pstmt.setInt(2, canComment ? 1 : 0);
            pstmt.setBoolean(3, isHome);
            pstmt.setInt(4, examine);
            pstmt.setString(5, keywords);
            pstmt.setInt(6, intisRelateShow);
            pstmt.setInt(7, templateId);
            pstmt.setString(8, dir_code);
            pstmt.setInt(9, isNew);
            pstmt.setString(10, author);
            pstmt.setString(11, flowTypeCode);
            pstmt.setString(12, "" + System.currentTimeMillis());
            pstmt.setString(13, parentCode);
            pstmt.setString(14, color);
            pstmt.setInt(15, bold?1:0);
            pstmt.setString(16, DateUtil.toLongString(expireDate));
            pstmt.setString(17, source);
            pstmt.setInt(18, type);
            pstmt.setInt(19, pageTemplateId);
            pstmt.setInt(20, id);
            conn.executePreUpdate();
            // 更新缓存
            DocCacheMgr dcm = new DocCacheMgr();
            if (oldexamine==examine) {
                dcm.refreshUpdate(id);
            }
            else {
                dcm.refreshUpdate(id, class1, parentCode);
            }

            // 如果是更改了类别
            if (!dir_code.equals(class1)) {
                dcm.refreshChangeDirCode(class1, dir_code);
                class1 = dir_code;
            }

            // 更新内容
            DocContent dc = new DocContent();
            dc = dc.getDocContent(id, 1);
            dc.saveWithoutFile(application, mfu);
        } catch (SQLException e) {
            logger.error(e.getMessage());
            throw new ErrMsgException("DB operate error.");
        } finally {
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
        return true;
    }

    public void clearDustbin() throws ErrMsgException {
        String sql = "select id from document where examine=?";
         Conn conn = new Conn(connname);
         PreparedStatement pstmt = null;
         try {
             pstmt = conn.prepareStatement(sql);
             pstmt.setInt(1, EXAMINE_DUSTBIN);
             ResultSet rs = conn.executePreQuery();
             while (rs.next()) {
                 Document doc = getDocument(rs.getInt(1));
                 doc.del();
                 // 更新缓存
                 DocCacheMgr dcm = new DocCacheMgr();
                 dcm.refreshUpdate(doc.getId(), doc.getDirCode(), doc.getParentCode());
             }
         } catch (SQLException e) {
             logger.error(e.getMessage());
             throw new ErrMsgException("Err db.");
         } finally {
             if (conn != null) {
                 conn.close();
                 conn = null;
             }
         }
    }

    public boolean UpdateExamine(int examine) throws ErrMsgException {
        String sql = "update document set examine=? where id=?";
        Conn conn = new Conn(connname);
        PreparedStatement pstmt = null;
        try {
            pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1, examine);
            pstmt.setInt(2, id);
            conn.executePreUpdate();
            // 更新缓存
            DocCacheMgr dcm = new DocCacheMgr();
            dcm.refreshUpdate(id, class1, parentCode);
        } catch (SQLException e) {
            logger.error(e.getMessage());
            throw new ErrMsgException("Err db.");
        } finally {
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
        return true;
    }

    public synchronized boolean UpdateIsHome(boolean isHome) throws
            ErrMsgException {
        String sql = "update document set isHome=? where id=?";
        Conn conn = new Conn(connname);
        PreparedStatement pstmt = null;
        try {
            //更新文件内容
            pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1, isHome ? 1 : 0);
            pstmt.setInt(2, id);
            conn.executePreUpdate();
            // 更新缓存
            DocCacheMgr dcm = new DocCacheMgr();
            // dcm.refreshUpdate(id);
            dcm.refreshUpdate(id, class1, parentCode);
        } catch (SQLException e) {
            logger.error(e.getMessage());
            throw new ErrMsgException("Err db.");
        } finally {
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
        return true;
    }

    public synchronized boolean increaseHit() throws
            ErrMsgException {
        hit ++;
        Conn conn = new Conn(connname);
        PreparedStatement pstmt = null;
        try {
            //更新文件内容
            pstmt = conn.prepareStatement(SAVE_HIT);
            pstmt.setInt(1, hit);
            pstmt.setInt(2, id);
            conn.executePreUpdate();
            // 更新缓存
            DocCacheMgr dcm = new DocCacheMgr();
            dcm.refreshUpdate(id);
        } catch (SQLException e) {
            logger.error(e.getMessage());
            throw new ErrMsgException("DB operate error.");
        } finally {
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
        return true;
    }

    public synchronized boolean UpdateSummaryWithoutFile(ServletContext application,
                                                CMSMultiFileUploadBean mfu) throws
            ResKeyException {
        Conn conn = new Conn(connname);
        boolean re = true;
        try {
            //取得表单中域的信息
            String idstr = StrUtil.getNullString(mfu.getFieldValue("id"));
            if (!StrUtil.isNumeric(idstr))
                throw new ResKeyException(SkinUtil.ERR_ID);
            id = Integer.parseInt(idstr);
            summary = StrUtil.getNullString(mfu.getFieldValue("htmlcode"));
/*
            String FilePath = StrUtil.getNullString(mfu.getFieldValue(
                    "filepath"));
            // 处理附件
            String tempAttachFilePath = application.getRealPath("/") + FilePath +
                                        "/";
            mfu.setSavePath(tempAttachFilePath); //取得目录
            File f = new File(tempAttachFilePath);
            if (!f.isDirectory()) {
                f.mkdirs();
            }
            // 写入磁盘
            mfu.writeAttachment(true);

            Vector attachs = mfu.getAttachments();
            Iterator ir = attachs.iterator();
            String sql = "";
            while (ir.hasNext()) {
                FileInfo fi = (FileInfo) ir.next();
                String filepath = mfu.getSavePath() + fi.getDiskName();
                sql +=
                        "insert into document_attach (fullpath,doc_id,name,diskname,visualpath,page_num) values (" +
                        StrUtil.sqlstr(filepath) + "," + id + "," +
                        StrUtil.sqlstr(fi.getName()) +
                        "," + StrUtil.sqlstr(fi.getDiskName()) + "," +
                        StrUtil.sqlstr(FilePath) + "," + 0 + ");";
            }
            if (!sql.equals(""))
                conn.executeUpdate(sql);
*/
            PreparedStatement pstmt = null; //更新文件内容
            pstmt = conn.prepareStatement(SAVE_SUMMARY);
            pstmt.setString(1, summary);
            pstmt.setInt(2, id);
            re = conn.executePreUpdate()==1?true:false;
            // 更新缓存
            DocCacheMgr dcm = new DocCacheMgr();
            dcm.refreshUpdate(id);
        } catch (SQLException e) {
            re = false;
            logger.error(e.getMessage());
        } finally {
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
        return re;
    }

    public synchronized boolean UpdateSummary(ServletContext application, CMSMultiFileUploadBean mfu) throws
            ResKeyException {
        String isuploadfile = StrUtil.getNullString(mfu.getFieldValue(
                "isuploadfile"));
        // logger.info("filepath=" + mfu.getFieldValue("filepath"));
        if (isuploadfile.equals("false"))
            return UpdateSummaryWithoutFile(application, mfu);

        String FilePath = StrUtil.getNullString(mfu.getFieldValue("filepath"));
        String tempAttachFilePath = application.getRealPath("/") + FilePath +
                                    "/";
        mfu.setSavePath(tempAttachFilePath); //取得目录
        File f = new File(tempAttachFilePath);
        if (!f.isDirectory()) {
            f.mkdirs();
        }

        boolean re = false;
        ResultSet rs = null;
        Conn conn = new Conn(connname);
        try {
            // 删除图像文件
            String sql = "select path from cms_images where mainkey=" + id +
                         " and kind='document' and subkey=" + 0 + "";

            rs = conn.executeQuery(sql);
            if (rs != null) {
                String fpath = "";
                while (rs.next()) {
                    fpath = rs.getString(1);
                    if (fpath != null) {
                        File virtualFile = new File(Global.getRealPath() + fpath);
                        virtualFile.delete();
                    }
                }

            }
            if (rs != null) {
                rs.close();
                rs = null;
            }
            // 从数据库中删除图像
            sql = "delete from cms_images where mainkey=" + id +
                  " and kind='document' and subkey=" + 0 + "";
            conn.executeUpdate(sql);

            // 处理图片
            int ret = mfu.getRet();
            if (ret == 1) {
                mfu.writeFile(false);
                Vector files = mfu.getFiles();
                // logger.info("files size=" + files.size());
                java.util.Enumeration e = files.elements();
                String filepath = "";
                sql = "";
                while (e.hasMoreElements()) {
                    FileInfo fi = (FileInfo) e.nextElement();
                    filepath = FilePath + "/" + fi.getName();
                    int imgId = (int)SequenceMgr.nextID(SequenceMgr.CMS_IMAGES);
                    sql = "insert into cms_images (id, path,mainkey,kind,subkey) values (" + imgId + "," +
                            StrUtil.sqlstr(filepath) + "," + id +
                            ",'document'," + 0 + ")";
                    conn.executeUpdate(sql);
                }
            } else
                throw new ErrMsgException(mfu.getErrMessage());
            if (rs != null) {
                try {
                    rs.close();
                } catch (Exception e) {}
                rs = null;
            }

            re = UpdateSummaryWithoutFile(application, mfu);
        } catch (Exception e) {
            logger.error("UpdateSummary:" + e.getMessage());
        } finally {
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }

        return re;
    }

    public synchronized boolean updateTemplateId() {
        String sql = "update document set template_id=? where id=?";
        Conn conn = new Conn(connname);
        boolean re = false;
        try {
            PreparedStatement pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1, templateId);
            pstmt.setInt(2, id);
            re = conn.executePreUpdate()==1?true:false;
            if (re) {
                // 更新缓存
                DocCacheMgr dcm = new DocCacheMgr();
                dcm.refreshUpdate(id);
            }
        }
        catch (SQLException e) {
            logger.error(e.getMessage());
        }
        finally {
            if (conn!=null) {
                conn.close(); conn = null;
            }
        }
        return re;
    }

    public synchronized boolean Update(ServletContext application,
                                       CMSMultiFileUploadBean mfu) throws
            ErrMsgException {
        String isuploadfile = StrUtil.getNullString(mfu.getFieldValue(
                "isuploadfile"));
        // logger.info("filepath=" + mfu.getFieldValue("filepath"));
        if (isuploadfile.equals("false"))
            return UpdateWithoutFile(application, mfu);

        // 取得表单中域的信息
        String dir_code = StrUtil.getNullStr(mfu.getFieldValue("dir_code"));
        author = StrUtil.getNullString(mfu.getFieldValue("author"));
        title = StrUtil.getNullString(mfu.getFieldValue("title"));
        String strIsHome = StrUtil.getNullString(mfu.getFieldValue("isHome"));
        if (strIsHome.equals(""))

⌨️ 快捷键说明

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