document.java

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

JAVA
1,961
字号
            return false;        return loaded;    }    public int getHit() {        return hit;    }    public int getTemplateId() {        return templateId;    }        public int getPageCountPlugin() {        PluginMgr pm = new PluginMgr();        PluginUnit pu = pm.getPluginUnitOfDir(getDirCode());        if (pu != null) {            IPluginDocument ipd = pu.getUnit().getDocument(id);            if (ipd.getPageCount() != ipd.PAGE_COUNT_NONE)                return ipd.getPageCount();        }        return getPageCount();    }    public int getPageCount() {        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 1;             else                return ary.length;        } else            return pageCount;    }    public String getParentCode() {        return parentCode;    }    public int getIsNew() {        return isNew;    }    public String getAuthor() {        return author;    }    public String getFlowTypeCode() {        return flowTypeCode;    }    public String getColor() {        return color;    }    public boolean isBold() {        return bold;    }    public java.util.Date getExpireDate() {        return expireDate;    }    public String getSource() {        return source;    }    public int getPageTemplateId() {        return pageTemplateId;    }    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;        String isuploadfile = StrUtil.getNullString(mfu.getFieldValue(                "isuploadfile"));        DocContent dc = new DocContent();        if (isuploadfile.equals("false")) {            if (dc.createWithoutFile(application, mfu, id, content, pageNo)) {                                                                return true;            }        } else {            if (dc.create(application, mfu, id, content, pageNo)) {                                                return true;            }        }        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 {        this.pageCount = pagecount;        return save();    }    public boolean save() throws            ErrMsgException {        String sql = "update document set source=?,page_no=?,page_count=?,template_id=? where id=?";        Conn conn = new Conn(connname);        PreparedStatement pstmt = null;        try {            pstmt = conn.prepareStatement(sql);            pstmt.setString(1, source);            pstmt.setInt(2, pageNo);            pstmt.setInt(3, pageCount);            pstmt.setInt(4, templateId);            pstmt.setInt(5, id);            conn.executePreUpdate();                        DocCacheMgr dcm = new DocCacheMgr();            dcm.refreshUpdate(id);        } catch (SQLException e) {            logger.error("UpdateSource:" + e.getMessage());            throw new ErrMsgException("DB operate error.");        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return true;    }    public synchronized boolean UpdateSource(String source) throws            ErrMsgException {        this.source = source;        return save();    }    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 boolean uploadDocument(FileUpload TheBean) throws            ResKeyException {        String strdocId = StrUtil.getNullStr(TheBean.getFieldValue("doc_id"));        String strfileId = StrUtil.getNullStr(TheBean.getFieldValue("file_id"));        int docId = Integer.parseInt(strdocId);        int fileId = Integer.parseInt(strfileId);        DocumentMgr dm = new DocumentMgr();        Document doc = dm.getDocument(docId);        Attachment att = doc.getAttachment(1, fileId);        if (att == null) {            throw new ResKeyException("res.cms.Document", "err_att_not_found",                                      new Object[] {"" + docId, "" + fileId});                    }        Vector v = TheBean.getFiles();        if (v.size() > 0) {            FileInfo fi = (FileInfo) v.get(0);            String fullPath = Global.getRealPath() + att.getVisualPath() + "/";            fi.write(fullPath, att.getDiskName());            return true;        } else            return false;    }    public int getId() {        return id;    }    public java.util.Date getCreateDate() {        return createDate;    }    public int getLevel() {        return level;    }    public int getPageType() {        return pageType;    }    public int getPageNo() {        return pageNo;    }    public void setId(int id) {        this.id = id;    }    public void setCreateDate(java.util.Date createDate) {        this.createDate = createDate;    }    public void setLevel(int level) {        this.level = level;    }    public void setPageType(int pageType) {        this.pageType = pageType;    }    public void setPageNo(int pageNo) {        this.pageNo = pageNo;    }    public String getDocHtmlPath() {        java.util.Date d = getCreateDate();        Calendar cal = Calendar.getInstance();        cal.setTime(d);        String year = "" + (cal.get(cal.YEAR));        String month = "" + (cal.get(cal.MONTH) + 1);        return "doc" + "/" + year + "/" + month;    }    public String getDocHtmlName(int pageNum) {        Config cfg = new Config();        return getDocHtmlPath() + "/" + getId() + "_" + pageNum + "." +                cfg.getProperty("cms.html_ext");    }        public boolean isDocWithTitleExist(String title, java.util.Date afterDate) {        boolean re = false;        String sql = "select id from document where title=? and createDate>=?";        try {            JdbcTemplate jt = new JdbcTemplate();            ResultIterator ri = jt.executeQuery(sql, new Object[] {title,                                                "" +                                                DateUtil.toLongString(afterDate)});            re = ri.size() > 0;        } catch (SQLException e) {            LogUtil.getLog(getClass()).error("" + e.getMessage());        }        return re;    }        public Vector list(long beginDate, long endDate) {        Vector v = new Vector();        Conn conn = new Conn(connname);        ResultSet rs = null;        String sql = "";        if (beginDate != 0 && endDate != 0) {            sql = "select id from document where createDate>=" + beginDate +                  " and createDate<=" + endDate + " and examine=" +                  EXAMINE_PASS;        } else if (beginDate == 0 && endDate != 0) {            sql = "select id from document where createDate<=" + endDate +                  " and examine=" + EXAMINE_PASS;        } else if (beginDate != 0 && endDate == 0) {            sql = "select id from document where createDate>=" + beginDate +                  " and examine=" + EXAMINE_PASS;        } else {            sql = "select id from document where examine=" + EXAMINE_PASS;        }        try {            rs = conn.executeQuery(sql);            if (rs != null) {                while (rs.next()) {                    v.addElement(getDocument(rs.getInt(1)));                }            }        } catch (SQLException e) {            logger.error("list(beginDate, endDate)" + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return v;    }        public synchronized boolean ChangeDir(String newDirCode) throws            ErrMsgException {        Directory dir = new Directory();        Leaf newlf = dir.getLeaf(newDirCode);        if (newDirCode.equals("") || newDirCode.equals("not") || newlf == null) {            throw new ErrMsgException("请选择目录");        }        if (newlf.getType() == Leaf.TYPE_DOCUMENT) {            throw new ErrMsgException("不能迁移至文章型目录节点");        }        boolean re = false;        PreparedStatement ps = null;        Conn conn = new Conn(connname);        try {            String sql = "update document set class1=? where id=?";            ps = conn.prepareStatement(sql);            ps = conn.prepareStatement(sql);            ps.setString(1, newDirCode);            ps.setLong(2, id);            re = conn.executePreUpdate() == 1;            DocCacheMgr dcm = new DocCacheMgr();            dcm.refreshUpdate(id);            dcm.refreshChangeDirCode(class1, newDirCode);        } catch (Exception e) {            Logger.getLogger(Document.class.getName()).error(e.getMessage());            throw new ErrMsgException("数据库出错!");        } finally {            if (ps != null) {                try {                    ps.close();                }                catch (Exception e) {}                ps = null;            }            if (conn != null) {                conn.close();                conn = null;            }        }        return re;    }    private int isNew = 0;    private String author;    private String flowTypeCode = "";    private String color;    private boolean bold = false;    private java.util.Date expireDate;    private String source;    private int pageTemplateId = NOTEMPLATE;     private java.util.Date createDate;    private int level = 0;    private int pageType = PAGE_TYPE_MANUAL;    private int pageNo = 1;}

⌨️ 快捷键说明

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