document.java
来自「cwbbs 云网论坛源码」· Java 代码 · 共 1,961 行 · 第 1/5 页
JAVA
1,961 行
if (isuploadfile.equals("false")) return create(dir_code, title, content, type, nick, templateId, author); 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, nick); pstmt.setString(6, keywords); pstmt.setInt(7, intisRelateShow); pstmt.setInt(8, canComment ? 1 : 0); pstmt.setInt(9, hit); pstmt.setInt(10, templateId); pstmt.setString(11, parentCode); pstmt.setInt(12, examine); pstmt.setInt(13, isNew); pstmt.setString(14, author); pstmt.setString(15, flowTypeCode); pstmt.setString(16, "" + System.currentTimeMillis()); pstmt.setString(17, color); pstmt.setInt(18, bold ? 1 : 0); pstmt.setString(19, DateUtil.toLongString(expireDate)); pstmt.setString(20, source); pstmt.setInt(21, pageTemplateId); pstmt.setString(22, DateUtil.toLongString(createDate)); pstmt.setInt(23, pageType); pstmt.setInt(24, level); conn.executePreUpdate(); pstmt.close(); pstmt = null; DocContent dc = new DocContent(); dc.create(application, mfu, id, content, 1); String[] tmpAttachIds = mfu.getFieldValues("tmpAttachId"); if (tmpAttachIds != null) { int len = tmpAttachIds.length; for (int k = 0; k < len; k++) { Attachment att = new Attachment(Integer.parseInt(tmpAttachIds[ k])); att.setDocId(id); att.setPageNum(1); att.save(); } } lf.setDocCount(lf.getDocCount() + 1); lf.save(new JdbcTemplate()); if (!subjects.equals("")) { String[] subjectAry = StrUtil.split(subjects, ","); SubjectListDb sld = new SubjectListDb(); sld.setDocBelongtoSubjects(new JdbcTemplate(), subjectAry, id); } } catch (SQLException e) { logger.error("create:" + e.getMessage()); throw new ResKeyException(SkinUtil.ERR_DB); } finally { if (conn != null) { conn.close(); conn = null; } } return true; } public boolean create(String code_class1, String title, String content, int type, 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) SequenceMgr.nextID(SequenceMgr.DOCUMENT); 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, nick); pstmt.setString(6, ""); pstmt.setInt(7, 1); pstmt.setInt(8, canComment ? 1 : 0); pstmt.setInt(9, hit); pstmt.setInt(10, templateId); pstmt.setString(11, parentCode); pstmt.setInt(12, examine); pstmt.setInt(13, isNew); pstmt.setString(14, author); pstmt.setString(15, flowTypeCode); pstmt.setString(16, "" + System.currentTimeMillis()); pstmt.setString(17, color); pstmt.setInt(18, bold ? 1 : 0); pstmt.setString(19, DateUtil.toLongString(expireDate)); pstmt.setString(20, source); pstmt.setInt(21, pageTemplateId); pstmt.setString(22, DateUtil.toLongString(createDate)); pstmt.setInt(23, pageType); pstmt.setInt(24, level); conn.executePreUpdate(); DocContent dc = new DocContent(); dc.create(id, content, 1); lf.setDocCount(lf.getDocCount() + 1); lf.save(new JdbcTemplate()); } catch (SQLException e) { logger.error("create:" + 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); Leaf lf = new Leaf(); lf = lf.getLeaf(class1); if (lf!=null) { lf.setDocCount(lf.getDocCount() - 1); lf.save(new JdbcTemplate()); } } 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("loadFromDB: Document id= " + id + " not found." + StrUtil.trace(new Exception())); } else { this.title = rs.getString(1); this.class1 = rs.getString(2); this.modifiedDate = DateUtil.parse(rs.getString(3)); this.canComment = rs.getBoolean(4); this.summary = rs.getString(5); this.isHome = rs.getBoolean(6); this.type = rs.getInt(7); this.examine = rs.getInt(8); this.nick = rs.getString(9); this.keywords = rs.getString(10); this.isRelateShow = rs.getInt(11) == 1 ? true : false; this.hit = rs.getInt(12); this.templateId = rs.getInt(13); this.pageCount = rs.getInt(14); this.parentCode = rs.getString(15); this.isNew = rs.getInt(16); this.author = rs.getString(17); this.flowTypeCode = rs.getString(18); color = StrUtil.getNullString(rs.getString(19)); bold = rs.getInt(20) == 1; String s = rs.getString(21); if (s == null) expireDate = null; else expireDate = s.equals("0") ? null : DateUtil.parse(s); source = StrUtil.getNullStr(rs.getString(22)); pageTemplateId = rs.getInt(23); createDate = DateUtil.parse(rs.getString(24)); if (createDate == null) createDate = modifiedDate; level = rs.getInt(25); pageType = rs.getInt(26); pageNo = rs.getInt(27); 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 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 setSource(String source) { this.source = source; } public void setPageTemplateId(int pageTemplateId) { this.pageTemplateId = pageTemplateId; } public String getNick() { return nick; } public java.util.Date getModifiedDate() { return this.modifiedDate; } 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 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)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?