document.java

来自「cwbbs 云网论坛源码」· Java 代码 · 共 1,961 行 · 第 1/5 页

JAVA
1,961
字号
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.db.*;import com.cloudwebsoft.framework.util.*;import com.redmoon.forum.*;import com.redmoon.kit.util.*;import org.apache.log4j.*;public class Document implements java.io.Serializable, ITagSupport {    public static final int NOTEMPLATE = -1;    String connname = "";    private String subjects;    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 TYPE_DOC = 0;    public static final int TYPE_VOTE = 1;    public static final int TYPE_LINK = 2;    public static final int TYPE_IMG = 3;    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 EXAMINE_DUSTBIN = 10;     public static final int LEVEL_TOP = 100;    public static final int PAGE_TYPE_MANUAL = 0;    public static final int PAGE_TYPE_TAG = 1;        public static String PAGE_TAG = "\\[page\\]";    transient Logger logger = Logger.getLogger(Document.class.getName());    private static final String INSERT_DOCUMENT =            "INSERT into document (id, title, class1, doc_type, nick, keywords, isrelateshow, can_comment, hit, template_id, parent_code, examine, isNew, author, flowTypeCode, modifiedDate, color, isbold, expire_date,source,page_template_id,createDate,page_type,doc_level) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";    private static final String LOAD_DOCUMENT =            "SELECT title, class1, modifiedDate, can_comment,summary,ishome,doc_type,examine,nick,keywords,isrelateshow,hit,template_id,page_count,parent_code,isNew,author,flowTypeCode,color,isbold,expire_date,source,page_template_id,createDate,doc_level,page_type,page_no 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=?, examine=?,keywords=?,isrelateshow=?,template_id=?,class1=?,isNew=?,author=?,flowTypeCode=?,modifiedDate=?,parent_code=?,color=?,isbold=?,expire_date=?,source=?,doc_type=?,page_template_id=?,page_type=?,doc_level=?,page_no=?,createDate=? 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:conname can not be empty.");        this.id = id;        loadFromDB();    }    public void renew() {        if (logger == null)            logger = Logger.getLogger(Document.class.getName());    }    public TemplateDb getTemplateDb() throws ErrMsgException {        Leaf lf = new Leaf();        lf = lf.getLeaf(getDirCode());        TemplateCatalogDb tcd = lf.getTemplateCatalogDb();        if (tcd==null) {            tcd = new TemplateCatalogDb();            tcd = tcd.getDefaultTemplateCatalogDb();                    }        TemplateDb td = new TemplateDb();        if (tcd.getInt("doc")!=TemplateDb.TYPE_CODE_DEFAULT) {            td = td.getTemplateDb(tcd.getInt("doc"));        }        else {            td = td.getDefaultTemplate(TemplateDb.TYPE_CODE_DOC);        }        return td;    }        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 String getContent(int pageNum) {        if (pageType == PAGE_TYPE_TAG) {            DocContent dc = new DocContent();            dc = dc.getDocContent(id, 1);            String[] ary = StrUtil.split(dc.getContent(), PAGE_TAG);            if (ary == null)                return "";             else if (ary.length < pageNum)                return null;            else                return ary[pageNum - 1];        } else {            DocContent dc = new DocContent();            dc = dc.getDocContent(id, pageNum);            if (dc != null)                return dc.getContent();            else                return null;        }    }    public long getDocCountNoCache(String listsql) {        int total = 0;        Conn conn = new Conn(connname);        try {                        String countsql = SQLFilter.getCountSql(listsql);            ResultSet rs = conn.executeQuery(countsql);            if (rs != null && rs.next()) {                total = rs.getInt(1);            }        } catch (SQLException e) {            logger.error(e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return total;    }    public ListResult listResult(String listsql, int curPage, int pageSize) throws            ErrMsgException {        int total = 0;        ResultSet rs = null;        ListResult lr = new ListResult();        Vector result = new Vector();        lr.setTotal(total);        lr.setResult(result);        Conn conn = new Conn(connname);        try {                        String countsql = SQLFilter.getCountSql(listsql);            rs = conn.executeQuery(countsql);            if (rs != null && rs.next()) {                total = rs.getInt(1);            }            if (rs != null) {                rs.close();                rs = null;            }            if (total != 0)                conn.setMaxRows(curPage * pageSize);             rs = conn.executeQuery(listsql);            if (rs == null) {                return lr;            } else {                rs.setFetchSize(pageSize);                int absoluteLocation = pageSize * (curPage - 1) + 1;                if (rs.absolute(absoluteLocation) == false) {                    return lr;                }                do {                    Document cmm = getDocument(rs.getInt(1));                    result.addElement(cmm);                } while (rs.next());            }        } catch (SQLException e) {            logger.error(e.getMessage());            throw new ErrMsgException("listResult: DB operate error.");        } finally {            if (rs != null) {                try {                    rs.close();                } catch (Exception e) {}                rs = null;            }            if (conn != null) {                conn.close();                conn = null;            }        }        lr.setResult(result);        lr.setTotal(total);        return lr;    }        public Vector list(String sql, int start, int end) {        start += 1;         end += 1;        ResultSet rs = null;        Vector result = new Vector();        Conn conn = new Conn(connname);        try {            conn.setMaxRows(end);             rs = conn.executeQuery(sql);            if (rs == null) {                return result;            } else {                                rs.setFetchSize(end - start + 1);                 if (rs.absolute(start) == false) {                    return result;                }                do {                    int id = rs.getInt(1);                    Document doc = getDocument(id);                    result.addElement(doc);                } while (rs.next());            }        } catch (SQLException e) {            logger.error("list: " + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return result;    }    public Vector list(String sql, Object[] params) {        Vector result = new Vector();        JdbcTemplate jt = new JdbcTemplate();        try {            ResultIterator ri = jt.executeQuery(sql, params);            while (ri.hasNext()) {                ResultRecord rr = (ResultRecord) ri.next();                int id = rr.getInt(1);                Document doc = getDocument(id);                result.addElement(doc);            }        } catch (SQLException e) {            logger.error("list: " + e.getMessage());

⌨️ 快捷键说明

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