document.java
来自「一个用java编写的功能强大的OA系统」· Java 代码 · 共 1,589 行 · 第 1/4 页
JAVA
1,589 行
package cn.js.fan.module.cms;import java.io.*;import java.sql.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;import cn.js.fan.base.*;import cn.js.fan.db.*;import cn.js.fan.module.cms.plugin.*;import cn.js.fan.module.cms.plugin.base.*;import cn.js.fan.security.*;import cn.js.fan.util.*;import cn.js.fan.web.*;import com.cloudwebsoft.framework.util.*;import com.redmoon.kit.util.*;import com.redmoon.oa.db.*;import com.redmoon.oa.person.*;import com.redmoon.oa.pvg.*;import com.redmoon.oa.ui.*;import org.apache.log4j.*;import org.htmlparser.*;import org.htmlparser.filters.*;import org.htmlparser.nodes.*;import org.htmlparser.tags.*;import org.htmlparser.util.*;public class Document implements java.io.Serializable, ITagSupport, IDesktopUnit { public static final int NOTEMPLATE = -1; String connname = ""; int id = -1; String title; String content; String date; String class1; java.util.Date modifiedDate; String summary; boolean isHome = false; int examine = 0; public static final int EXAMINE_NOT = 0; public static final int EXAMINE_NOTPASS = 1; public static final int EXAMINE_PASS = 2; public static final int TYPE_DOC = 0; public static final int TYPE_VOTE = 1; transient Logger logger = Logger.getLogger(Document.class.getName()); private static final String INSERT_DOCUMENT = "INSERT into document (id, title, class1, type, voteoption, voteresult, nick, keywords, isrelateshow, can_comment, hit, template_id, parent_code, examine, isNew, author, flowTypeCode, color, isBold, expire_date,modifiedDate,createDate) VALUES (?,?,?,?,?,?,?,?,?,?,0,?,?,?,?,?,?,?,?,?,?,?)"; private static final String LOAD_DOCUMENT = "SELECT title, class1, modifiedDate, can_comment,summary,ishome,type,voteOption,voteResult,examine,nick,keywords,isrelateshow,hit,template_id,page_count,parent_code,isNew,author,flowTypeCode,color,isBold,expire_date,orgAddr,createDate FROM document WHERE id=?"; private static final String DEL_DOCUMENT = "delete FROM document WHERE id=?"; private static final String SAVE_DOCUMENT = "UPDATE document SET title=?, can_comment=?, ishome=?, modifiedDate=NOW(),examine=?,keywords=?,isrelateshow=?,template_id=?,class1=?,isNew=?,author=?,flowTypeCode=?,parent_code=?,color=?,isBold=?,expire_date=? WHERE id=?"; private static final String SAVE_SUMMARY = "UPDATE document SET summary=? WHERE id=?"; private static final String SAVE_HIT = "UPDATE document SET hit=? WHERE id=?"; public Document() { connname = Global.defaultDB; if (connname.equals("")) logger.info("Document:默认数据库名为空!"); } public Document(int id) { connname = Global.defaultDB; if (connname.equals("")) logger.info("Document:默认数据库名为空!"); this.id = id; loadFromDB(); } public void renew() { if (logger==null) logger = Logger.getLogger(Document.class.getName()); } public int getIDOrCreateByCode(String code, String nick) { int myid = getFirstIDByCode(code); if (myid != -1) { this.id = myid; loadFromDB(); } else { content = " "; Leaf leaf = new Leaf(); leaf = leaf.getLeaf(code); title = leaf.getName(); create(code, title, content, 0, "", "", nick, leaf.getTemplateId(), nick); this.id = getFirstIDByCode(code); leaf.setDocID(id); leaf.update(); } return id; } public void delDocumentByDirCode(String code) throws ErrMsgException { Vector v = getDocumentsByDirCode(code); Iterator ir = v.iterator(); while (ir.hasNext()) { Document doc = (Document) ir.next(); doc.del(); } } public Vector getDocumentsByDirCode(String code) { Vector v = new Vector(); String sql = "select id from document where class1=" + StrUtil.sqlstr(code); Conn conn = new Conn(connname); ResultSet rs = null; try { rs = conn.executeQuery(sql); if (rs != null) { while (rs.next()) { v.addElement(getDocument(rs.getInt(1))); } } } catch (SQLException e) { logger.error(e.getMessage()); } finally { if (rs != null) { try { rs.close(); } catch (Exception e) {} } if (conn != null) { conn.close(); conn = null; } } return v; } public Document getDocumentByDirCode(String dirCode) { Leaf leaf = new Leaf(); leaf = leaf.getLeaf(dirCode); if (leaf != null && leaf.isLoaded() && leaf.getType() == leaf.TYPE_DOCUMENT) { int id = leaf.getDocID(); return getDocument(id); } else return null; } public int getFirstIDByCode(String code) { String sql = "select id from document where class1=" + StrUtil.sqlstr(code); Conn conn = new Conn(connname); ResultSet rs = null; try { rs = conn.executeQuery(sql); if (rs != null && rs.next()) { return rs.getInt(1); } } catch (SQLException e) { logger.error(e.getMessage()); } finally { if (rs != null) { try { rs.close(); } catch (Exception e) {} } if (conn != null) { conn.close(); conn = null; } } return -1; } public String getSummary() { return this.summary; } public int getID() { return id; } public void setID(int id) { this.id = id; } public String getTitle() { return title; } public boolean getIsHome() { return this.isHome; } public void setIsHome(boolean h) { this.isHome = h; } public void setType(int type) { this.type = type; } public void setVoteOption(String voteOption) { this.voteOption = voteOption; } public void setVoteResult(String voteResult) { this.voteResult = voteResult; } public String getContent(int pageNum) { DocContent dc = new DocContent(); dc = dc.getDocContent(id, pageNum); if (dc!=null) return dc.getContent(); else return null; } public String getPageList(HttpServletRequest request, UserDesktopSetupDb uds) { DesktopMgr dm = new DesktopMgr(); DesktopUnit du = dm.getDesktopUnit(uds.getModuleCode()); String url = du.getPageList(); return url + StrUtil.UrlEncode(uds.getModuleItem()); } public String display(HttpServletRequest request, UserDesktopSetupDb uds) { Privilege privilege = new Privilege(); String dir_code = uds.getModuleItem(); Leaf lf = new Leaf(); lf = lf.getLeaf(dir_code); if (lf==null) return ""; if (!dir_code.equals("")) { LeafPriv lp = new LeafPriv(dir_code); if (!lp.canUserSee(privilege.getUser(request))) { return SkinUtil.LoadString(request, "pvg_invalid"); } } int count = uds.getCount(); String sql = "select id from document where class1=" + StrUtil.sqlstr(dir_code) + " and examine=" + Document.EXAMINE_PASS + " order by modifiedDate desc"; Iterator ir = list(sql, count).iterator(); String str = "<ul>"; DesktopMgr dm = new DesktopMgr(); DesktopUnit du = dm.getDesktopUnit(uds.getModuleCode()); String url = du.getPageShow(); while (ir.hasNext()) { Document doc = (Document) ir.next(); if (DateUtil.compare(new java.util.Date(), doc.getExpireDate()) == 2) { str += "<li><a href='" + url + "?id=" + doc.getID() + "'>"; if (doc.isBold()) str += "<B>"; if (!doc.getColor().equals("")) { str += "<font color='" + doc.getColor() + "'>"; } str += StrUtil.toHtml(doc.getTitle()); if (!doc.getColor().equals("")) str += "</font>"; if (doc.isBold()) str += "</B>"; str += " [" + doc.getModifiedDate() + "]</a></li>"; } else { str += "<li><a href='" + url + "?id=" + doc.getID() + "'>" + StrUtil.toHtml(doc.getTitle()) + " [" + doc.getModifiedDate() + "]</a></li>"; } } str += "</ul>"; return str; } public Vector list(String sql, int count) { ResultSet rs = null; Vector result = new Vector(); Conn conn = new Conn(connname); try { conn.setMaxRows(count); rs = conn.executeQuery(sql); if (rs == null) { return result; } else { rs.setFetchSize(count); 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")); 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(); } color = StrUtil.getNullStr(mfu.getFieldValue("color")); bold = StrUtil.getNullStr(mfu.getFieldValue("isBold")).equals("true"); expireDate = DateUtil.parse(mfu.getFieldValue("expireDate"), "yyyy-MM-dd");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?