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

📄 document.java

📁 源码/软件简介: 云网论坛1.1RC国际版是采用JSP开发的集论坛、CMS(网站内容管理系统)、博客、聊天室、商城、交友、语音灌水等于一体的门户式社区。拥有CWBBS ( Cloud Web BBS
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     * @param count int
     * @return Vector
     */
    public Vector list(String sql, int count) {
        ResultSet rs = null;
        Vector result = new Vector();
        Conn conn = new Conn(connname);
        try {
            rs = conn.executeQuery(sql);
            if (rs == null) {
                return result;
            } else {
                // defines the number of rows that will be read from the database when the ResultSet needs more rows
                rs.setFetchSize(count); // rs一次从POOL中所获取的记录数
                while (rs.next()) {
                    int id = rs.getInt(1);
                    Document doc = getDocument(id);
                    result.addElement(doc);
                }
            }
        } catch (SQLException e) {
            logger.error("list: " + e.getMessage());
        } finally {
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
        return result;
    }

    public String RenderContent(HttpServletRequest request, int pageNum) {
        DocContent dc = new DocContent();
        dc = dc.getDocContent(id, pageNum);
        if (dc != null) {
            // 插件名称
            Leaf lf = new Leaf();
            lf = lf.getLeaf(class1);
            String pluginCode = lf.getPluginCode();
            if (pluginCode!=null && pluginCode.equals(PluginUnit.DEFAULT))
                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"));

        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.setInt(14, 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 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);
        } catch (SQLException e) {
            logger.error(e.getMessage());
            throw new ErrMsgException("服务器内部错!");
        } 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();
                    sql = "insert into cms_images (path,mainkey,kind,subkey) values (" +
                            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) {

⌨️ 快捷键说明

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