document.java

来自「一个用java编写的功能强大的OA系统」· Java 代码 · 共 1,589 行 · 第 1/4 页

JAVA
1,589
字号
    public boolean create(ServletContext application,                          CMSMultiFileUploadBean mfu, String nick) throws            ErrMsgException {        String isuploadfile = StrUtil.getNullString(mfu.getFieldValue(                "isuploadfile"));                author = StrUtil.getNullString(mfu.getFieldValue("author"));        title = StrUtil.getNullString(mfu.getFieldValue("title"));        content = StrUtil.getNullString(mfu.getFieldValue("htmlcode"));        String dir_code = StrUtil.getNullStr(mfu.getFieldValue("dir_code"));        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;        }        String strexamine = StrUtil.getNullStr(mfu.getFieldValue("examine"));        if (StrUtil.isNumeric(strexamine)) {            examine = Integer.parseInt(strexamine);        }        else            examine = 0;        String strisnew = StrUtil.getNullStr(mfu.getFieldValue("isNew"));        if (StrUtil.isNumeric(strisnew))            isNew = Integer.parseInt(strisnew);        else            isNew = 0;        flowTypeCode = StrUtil.getNullStr(mfu.getFieldValue("flowTypeCode"));                Directory dir = new Directory();        Leaf lf = dir.getLeaf(dir_code);        if (lf==null || !lf.isLoaded()) {            throw new ErrMsgException("节点:" + dir_code + "不存在!");        }        if (lf.getType() == 0)            throw new ErrMsgException("对不起,该目录不包含具体内容,请选择正确的目录项!");        if (lf.getType() == 1) {            if (getFirstIDByCode(dir_code) != -1)                throw new ErrMsgException("该目录节点为文章节点,且文章已经被创建!");        }        String strCanComment = StrUtil.getNullStr(mfu.getFieldValue(                "canComment"));        if (strCanComment.equals(""))            canComment = false;        else if (strCanComment.equals("1"))            canComment = true;                String strtid = StrUtil.getNullStr(mfu.getFieldValue("templateId"));        if (StrUtil.isNumeric(strtid))            templateId = Integer.parseInt(strtid);        color = StrUtil.getNullStr(mfu.getFieldValue("color"));        bold = StrUtil.getNullStr(mfu.getFieldValue("isBold")).equals("true");        expireDate = DateUtil.parse(mfu.getFieldValue("expireDate"), "yyyy-MM-dd");                String isvote = mfu.getFieldValue("isvote");        String[] voptions = null;        type = TYPE_DOC;         String voteresult = "", votestr = "";        if (isvote != null && isvote.equals("1")) {            type = TYPE_VOTE;            String voteoption = mfu.getFieldValue("vote").trim();            if (!voteoption.equals("")) {                voptions = voteoption.split("\\r\\n");            }            if (voteoption.indexOf("|") != -1)                throw new ErrMsgException("投票选项中不能包含|");            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];                }            }        }                DocCacheMgr dcm = new DocCacheMgr();        dcm.refreshCreate(dir_code, lf.getParentCode());                if (isuploadfile.equals("false"))            return create(dir_code, title, content, type, votestr, voteresult,                          nick, templateId, author);        this.id = (int) SequenceManager.nextID(SequenceManager.OA_DOCUMENT_CMS);        Conn conn = new Conn(connname);        PreparedStatement pstmt = null;        try {                        parentCode = lf.getParentCode();            pstmt = conn.prepareStatement(INSERT_DOCUMENT);            pstmt.setInt(1, id);            pstmt.setString(2, title);            pstmt.setString(3, dir_code);            pstmt.setInt(4, type);            pstmt.setString(5, votestr);            pstmt.setString(6, voteresult);            pstmt.setString(7, nick);            pstmt.setString(8, keywords);            pstmt.setInt(9, intisRelateShow);            pstmt.setInt(10, canComment?1:0);            pstmt.setInt(11, templateId);            pstmt.setString(12, parentCode);            pstmt.setInt(13, examine);            pstmt.setInt(14, isNew);            pstmt.setString(15, author);            pstmt.setString(16, flowTypeCode);            pstmt.setString(17, color);            pstmt.setInt(18, bold?1:0);            if (expireDate==null)                pstmt.setTimestamp(19, null);            else                pstmt.setTimestamp(19, new Timestamp(expireDate.getTime()));            java.util.Date d = new java.util.Date();            pstmt.setTimestamp(20, new Timestamp(d.getTime()));            pstmt.setTimestamp(21, new Timestamp(d.getTime()));            conn.executePreUpdate();            pstmt.close();            pstmt = null;                        DocContent dc = new DocContent();            dc.create(application, mfu, id, content, 1);        } catch (SQLException e) {            logger.error("create:" + e.getMessage());            throw new ErrMsgException("服务器内部错!");        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return true;    }        public boolean create(String code_class1, String title, String content,                          int type, String voteoption, String voteresult,                          String nick, int templateId, String author) {        Leaf lf = new Leaf();        lf = lf.getLeaf(code_class1);        parentCode = lf.getParentCode();        Conn conn = new Conn(connname);        this.id = (int) SequenceManager.nextID(SequenceManager.OA_DOCUMENT_CMS);        try {                        PreparedStatement pstmt = conn.prepareStatement(INSERT_DOCUMENT);            pstmt.setInt(1, id);            pstmt.setString(2, title);            pstmt.setString(3, code_class1);            pstmt.setInt(4, type);            pstmt.setString(5, voteoption);            pstmt.setString(6, voteresult);            pstmt.setString(7, nick);            pstmt.setString(8, "");            pstmt.setInt(9, 1);            pstmt.setInt(10, canComment?1:0);            pstmt.setInt(11, templateId);            pstmt.setString(12, parentCode);            pstmt.setInt(13, examine);            pstmt.setInt(14, isNew);            pstmt.setString(15, author);            pstmt.setString(16, flowTypeCode);            pstmt.setString(17, color);            pstmt.setInt(18, bold?1:0);            if (expireDate==null)                pstmt.setTimestamp(19, null);            else                pstmt.setTimestamp(19, new Timestamp(expireDate.getTime()));            java.util.Date d = new java.util.Date();            pstmt.setTimestamp(20, new Timestamp(d.getTime()));            pstmt.setTimestamp(21, new Timestamp(d.getTime()));            conn.executePreUpdate();                        DocContent dc = new DocContent();            dc.create(id, content);        } catch (SQLException e) {            logger.error(e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return true;    }    public String get(String field) {        if (field.equals("title"))            return getTitle();        else if (field.equals("content"))            return getContent(1);        else if (field.equals("summary"))            return getSummary();        else if (field.equals("id"))            return "" + getID();        else            return "";    }    public boolean del() throws ErrMsgException {        Conn conn = new Conn(connname);        ResultSet rs = null;        try {                        String sql = "select page_num from doc_content where doc_id=" + id;            rs = conn.executeQuery(sql);            if (rs!=null) {                while (rs.next()) {                    int pn = rs.getInt(1);                    DocContent dc = new DocContent();                    dc = dc.getDocContent(id, pn);                    dc.del();                }            }            if (rs!=null) {                rs.close();                rs = null;            }            PreparedStatement pstmt = conn.prepareStatement(DEL_DOCUMENT);            pstmt.setInt(1, id);            conn.executePreUpdate();                        DocCacheMgr dcm = new DocCacheMgr();            dcm.refreshDel(id, class1, parentCode);        } catch (SQLException e) {            logger.error(e.getMessage());            return false;        } finally {            if (rs != null) {                try {                    rs.close();                } catch (Exception e) {}                rs = null;            }            if (conn != null) {                conn.close();                conn = null;            }        }        return true;    }    private void loadFromDB() {                Conn conn = new Conn(connname);        PreparedStatement pstmt = null;        ResultSet rs = null;        try {            pstmt = conn.prepareStatement(LOAD_DOCUMENT);            pstmt.setInt(1, id);            rs = conn.executePreQuery();            if (!rs.next()) {                logger.error("文档 " + id +                             " 在数据库中未找到.");            } else {                this.title = rs.getString(1);                this.class1 = rs.getString(2);                this.modifiedDate = rs.getTimestamp(3);                this.canComment = rs.getBoolean(4);                this.summary = rs.getString(5);                this.isHome = rs.getBoolean(6);                this.type = rs.getInt(7);                this.voteOption = rs.getString(8);                this.voteResult = rs.getString(9);                this.examine = rs.getInt(10);                this.nick = rs.getString(11);                this.keywords = rs.getString(12);                this.isRelateShow = rs.getInt(13)==1?true:false;                this.hit = rs.getInt(14);                this.templateId = rs.getInt(15);                this.pageCount = rs.getInt(16);                this.parentCode = rs.getString(17);                this.isNew = rs.getInt(18);                this.author = rs.getString(19);                this.flowTypeCode = rs.getString(20);                this.color = rs.getString(21);                this.bold = rs.getInt(22)==1;                this.expireDate = rs.getTimestamp(23);                orgAddr = StrUtil.getNullStr(rs.getString(24));                createDate = rs.getTimestamp(25);                loaded = true;             }        } catch (SQLException e) {            logger.error("loadFromDB:" + e.getMessage());        } finally {                        if (conn != null) {                conn.close();                conn = null;            }        }    }    public String toString() {        return "Document " + id + ":" + title;    }    private boolean canComment = true;    public boolean getCanComment() {        return canComment;    }    public int getType() {        return type;    }    public String getVoteOption() {        return voteOption;    }    public int getExamine() {        return this.examine;    }    public void setExamine(int e) {        this.examine = e;    }    public void setNick(String nick) {        this.nick = nick;    }    public void setKeywords(String keywords) {        this.keywords = keywords;    }    public void setIsRelateShow(boolean isRelateShow) {        this.isRelateShow = isRelateShow;    }    public void setHit(int hit) {        this.hit = hit;    }    public void setTemplateId(int templateId) {        this.templateId = templateId;    }    public void setPageCount(int pageCount) {        this.pageCount = pageCount;    }    public void setParentCode(String parentCode) {        this.parentCode = parentCode;    }    public void setIsNew(int isNew) {        this.isNew = isNew;    }    public void setAuthor(String author) {        this.author = author;    }    public void setFlowTypeCode(String flowTypeCode) {        this.flowTypeCode = flowTypeCode;    }    public void setColor(String color) {        this.color = color;    }    public void setBold(boolean bold) {        this.bold = bold;    }    public void setExpireDate(java.util.Date expireDate) {        this.expireDate = expireDate;    }    public void setOrgAddr(String orgAddr) {        this.orgAddr = orgAddr;    }    public void setCreateDate(java.util.Date createDate) {        this.createDate = createDate;

⌨️ 快捷键说明

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