📄 document.java
字号:
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 flow_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.getDate(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); 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 String getVoteResult() { return voteResult; } public String getNick() { return nick; } public String getModifiedDate() { Date d = modifiedDate; if (d != null) return d.toString().substring(0, 10); else return ""; } public boolean vote(int id, int votesel) throws ErrMsgException { boolean re = false; Conn conn = new Conn(connname); try { String[] rlt = voteResult.split("\\|"); int len = rlt.length; int[] intre = new int[len]; for (int i = 0; i < len; i++) intre[i] = Integer.parseInt(rlt[i]); intre[votesel]++; String result = ""; for (int i = 0; i < len; i++) { if (result.equals("")) result = "" + intre[i]; else result += "|" + intre[i]; } String sql = "update flow_document set voteresult=" + StrUtil.sqlstr(result) + " where id=" + id; logger.info(sql); re = conn.executeUpdate(sql) == 1 ? true : false; DocCacheMgr dcm = new DocCacheMgr(); dcm.refreshUpdate(id); } catch (SQLException e) { logger.error("vote:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } protected long[] getDocBlock(String query, String groupKey, int startIndex) { DocCacheMgr dcm = new DocCacheMgr(); return dcm.getDocBlock(query, groupKey, startIndex); } public DocBlockIterator getDocuments(String query, String groupKey, int startIndex, int endIndex) { if (!SecurityUtil.isValidSql(query)) return null; long[] docBlock = getDocBlock(query, groupKey, startIndex); return new DocBlockIterator(docBlock, query, groupKey, startIndex, endIndex); } public int getDocCount(String sql) { DocCacheMgr dcm = new DocCacheMgr(); return dcm.getDocCount(sql); } public Document getDocument(int id) { DocCacheMgr dcm = new DocCacheMgr(); return dcm.getDocument(id); } private int type = 0; private String voteOption; private String voteResult; private String nick; public String getKeywords() { return keywords; } public boolean getIsRelateShow() { return isRelateShow; } private String keywords; private boolean isRelateShow; private boolean loaded = false; public boolean isLoaded() { if (id==-1) return false; return loaded; } public int getHit() { return hit; } public int getTemplateId() { return templateId; } public int getPageCount() { return pageCount; } public String getParentCode() { return parentCode; } public int getIsNew() { return isNew; } public String getAuthor() { return author; } public String getFlowTypeCode() { return flowTypeCode; } private int hit = 0; private int templateId = NOTEMPLATE; public boolean AddContentPage(ServletContext application, CMSMultiFileUploadBean mfu, String content) throws ErrMsgException { String action = StrUtil.getNullStr(mfu.getFieldValue("action")); int afterpage = -1; if (action.equals("insertafter")) { String insafter = StrUtil.getNullStr(mfu.getFieldValue("afterpage")); if (StrUtil.isNumeric(insafter)) afterpage = Integer.parseInt(insafter); } int pageNo = 1; if (afterpage!=-1) pageNo = afterpage + 1; else pageNo = pageCount + 1; System.out.println("pageNo=" + pageNo); String isuploadfile = StrUtil.getNullString(mfu.getFieldValue( "isuploadfile")); DocContent dc = new DocContent(); if (isuploadfile.equals("false")) { if (dc.createWithoutFile(application, mfu, id, content, pageNo)) { pageCount++; return UpdatePageCount(pageCount); } } else { if (dc.create(application, mfu, id, content, pageNo)) { pageCount++; return UpdatePageCount(pageCount); } } return false; } public boolean EditContentPage(ServletContext application, CMSMultiFileUploadBean mfu) throws ErrMsgException { String strpageNum = StrUtil.getNullStr(mfu.getFieldValue("pageNum")); int pageNum = Integer.parseInt(strpageNum); DocContent dc = new DocContent(); dc = dc.getDocContent(id, pageNum); dc.setContent(content); dc.save(application, mfu); return true; } public synchronized boolean UpdatePageCount(int pagecount) throws ErrMsgException { String sql = "update flow_document set modifiedDate=NOW(),page_count=? where id=?"; Conn conn = new Conn(connname); PreparedStatement pstmt = null; try { pstmt = conn.prepareStatement(sql); pstmt.setInt(1, pagecount); 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; } private int pageCount = 1; private String parentCode; public Vector getAttachments(int pageNum) { DocContent dc = new DocContent(); dc = dc.getDocContent(id, pageNum); if (dc==null) return null; return dc.getAttachments(); } public Attachment getAttachment(int pageNum, int att_id) { Iterator ir = getAttachments(pageNum).iterator(); while (ir.hasNext()) { Attachment at = (Attachment)ir.next(); if (at.getId()==att_id) return at; } return null; } public Document getTemplate() { if (templateId == this.NOTEMPLATE) return null; else return getDocument(templateId); } private int isNew = 0; private String author; private String flowTypeCode = "";}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -