document.java

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

JAVA
1,961
字号
        String isuploadfile = StrUtil.getNullString(mfu.getFieldValue(                "isuploadfile"));                if (isuploadfile.equals("false"))            return UpdateSummaryWithoutFile(application, mfu);        String FilePath = StrUtil.getNullString(mfu.getFieldValue("filepath"));        String tempAttachFilePath = Global.getRealPath() + FilePath +                                    "/";        mfu.setSavePath(tempAttachFilePath);         File f = new File(tempAttachFilePath);        if (!f.isDirectory()) {            f.mkdirs();        }        boolean re = false;        ResultSet rs = null;        Conn conn = new Conn(connname);        try {                        String sql = "select path from cms_images where mainkey=" + id +                         " and kind='document' and subkey=" + 0 + "";            rs = conn.executeQuery(sql);            if (rs != null) {                String fpath = "";                while (rs.next()) {                    fpath = rs.getString(1);                    if (fpath != null) {                        File virtualFile = new File(Global.getRealPath() +                                fpath);                        virtualFile.delete();                    }                }            }            if (rs != null) {                rs.close();                rs = null;            }                        sql = "delete from cms_images where mainkey=" + id +                  " and kind='document' and subkey=" + 0 + "";            conn.executeUpdate(sql);                        int ret = mfu.getRet();            if (ret == 1) {                mfu.writeFile(false);                Vector files = mfu.getFiles();                                java.util.Enumeration e = files.elements();                String filepath = "";                sql = "";                while (e.hasMoreElements()) {                    FileInfo fi = (FileInfo) e.nextElement();                    filepath = FilePath + "/" + fi.getName();                    int imgId = (int) SequenceMgr.nextID(SequenceMgr.CMS_IMAGES);                    sql =                            "insert into cms_images (id, path,mainkey,kind,subkey) values (" +                            imgId + "," +                            StrUtil.sqlstr(filepath) + "," + id +                            ",'document'," + 0 + ")";                    conn.executeUpdate(sql);                }            } else                throw new ErrMsgException(mfu.getErrMessage());            if (rs != null) {                try {                    rs.close();                } catch (Exception e) {}                rs = null;            }            re = UpdateSummaryWithoutFile(application, mfu);        } catch (Exception e) {            logger.error("UpdateSummary:" + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return re;    }    public synchronized boolean updateTemplateId() throws ErrMsgException {        return save();    }    public synchronized boolean Update(ServletContext application,                                       CMSMultiFileUploadBean mfu) throws            ErrMsgException {        String isuploadfile = StrUtil.getNullString(mfu.getFieldValue(                "isuploadfile"));                if (isuploadfile.equals("false"))            return UpdateWithoutFile(application, mfu);                String dir_code = StrUtil.getNullStr(mfu.getFieldValue("dir_code"));        author = StrUtil.getNullString(mfu.getFieldValue("author"));        title = StrUtil.getNullString(mfu.getFieldValue("title"));        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);        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;        }        String strisnew = StrUtil.getNullStr(mfu.getFieldValue("isNew"));        if (StrUtil.isNumeric(strisnew))            isNew = Integer.parseInt(strisnew);        else            isNew = 0;        String strCanComment = StrUtil.getNullStr(mfu.getFieldValue(                "canComment"));        if (strCanComment.equals(""))            canComment = false;        else if (strCanComment.equals("1"))            canComment = true;        flowTypeCode = StrUtil.getNullStr(mfu.getFieldValue("flowTypeCode"));        color = StrUtil.getNullStr(mfu.getFieldValue("color"));        bold = StrUtil.getNullStr(mfu.getFieldValue("isBold")).equals("true");        expireDate = DateUtil.parse(mfu.getFieldValue("expireDate"),                                    "yyyy-MM-dd");        source = StrUtil.getNullStr(mfu.getFieldValue("source"));        try {            pageTemplateId = Integer.parseInt(mfu.getFieldValue(                    "pageTemplateId"));        } catch (Exception e) {            pageTemplateId = -1;        }        String docType = StrUtil.getNullStr(mfu.getFieldValue("docType"));        if (!docType.equals("" + TYPE_VOTE)) {            type = Integer.parseInt(docType);        }        if (!dir_code.equals(class1)) {            Leaf lf = new Leaf();            lf = lf.getLeaf(dir_code);            if (lf.getType() == Leaf.TYPE_DOCUMENT) {                throw new ErrMsgException(lf.getName() + " 为文章型节点,不能更改至该目录!");            }            parentCode = lf.getParentCode();        }        String subjects = StrUtil.getNullStr(mfu.getFieldValue("subjects"));        int oldlevel = level;        level = StrUtil.toInt(StrUtil.getNullStr(mfu.getFieldValue("level")), 0);                java.util.Date newCreateDate = DateUtil.parse(mfu.getFieldValue("createDate"), "yyyy-MM-dd HH:mm:ss");        boolean isCreatDateModified = DateUtil.compare(newCreateDate, createDate)!=0;        if (isCreatDateModified)            createDate = newCreateDate;        Conn conn = new Conn(connname);        PreparedStatement pstmt = null;        try {                        pstmt = conn.prepareStatement(SAVE_DOCUMENT);            pstmt.setString(1, title);            pstmt.setInt(2, canComment ? 1 : 0);            pstmt.setBoolean(3, isHome);            pstmt.setInt(4, examine);            pstmt.setString(5, keywords);            pstmt.setInt(6, intisRelateShow);            pstmt.setInt(7, templateId);            pstmt.setString(8, dir_code);            pstmt.setInt(9, isNew);            pstmt.setString(10, author);            pstmt.setString(11, flowTypeCode);            pstmt.setString(12, "" + System.currentTimeMillis());            pstmt.setString(13, parentCode);            pstmt.setString(14, color);            pstmt.setInt(15, bold ? 1 : 0);            pstmt.setString(16, DateUtil.toLongString(expireDate));            pstmt.setString(17, source);            pstmt.setInt(18, type);            pstmt.setInt(19, pageTemplateId);            String strPageType = StrUtil.getNullStr(mfu.getFieldValue(                    "pageType"));            pageType = StrUtil.toInt(strPageType, PAGE_TYPE_MANUAL);            pstmt.setInt(20, pageType);            pstmt.setInt(21, level);            pstmt.setInt(22, pageNo);            pstmt.setString(23, DateUtil.toLongString(createDate));            pstmt.setInt(24, id);            conn.executePreUpdate();                        DocContent dc = new DocContent();            dc = dc.getDocContent(id, 1);            dc.save(application, mfu);                        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();                }            }                        if (!subjects.equals("")) {                String[] subjectAry = StrUtil.split(subjects, ",");                SubjectListDb sld = new SubjectListDb();                sld.setDocBelongtoSubjects(new JdbcTemplate(), subjectAry, id);            }        } catch (SQLException e) {            logger.error("update:" + e.getMessage());            throw new ErrMsgException("DB operate error.");        } catch (ResKeyException e) {            throw new ErrMsgException(e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }                        DocCacheMgr dcm = new DocCacheMgr();            if (oldexamine == examine && oldlevel == level && !isCreatDateModified) {                dcm.refreshUpdate(id);            } else {                dcm.refreshUpdate(id, class1, parentCode);                                SubjectListCache slc = new SubjectListCache(new SubjectListDb());                if (!subjects.equals("")) {                    String[] subjectAry = StrUtil.split(subjects, ",");                    int len = subjectAry.length;                    for (int i = 0; i < len; i++) {                        slc.refreshList(subjectAry[i]);                    }                }            }                        if (!dir_code.equals(class1)) {                dcm.refreshChangeDirCode(class1, dir_code);                class1 = dir_code;            }        }        return true;    }    public boolean create(ServletContext application,                          CMSMultiFileUploadBean mfu, String nick) throws            ResKeyException, ErrMsgException {        String isuploadfile = StrUtil.getNullString(mfu.getFieldValue(                "isuploadfile"));                author = StrUtil.getNullString(mfu.getFieldValue("author"));        title = StrUtil.getNullString(mfu.getFieldValue("title"));        content = StrUtil.getNullString(mfu.getFieldValue("htmlcode"));        String dir_code = StrUtil.getNullStr(mfu.getFieldValue("dir_code"));        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;        }        String strexamine = StrUtil.getNullStr(mfu.getFieldValue("examine"));        if (StrUtil.isNumeric(strexamine)) {            examine = Integer.parseInt(strexamine);        } else            examine = 0;        String strisnew = StrUtil.getNullStr(mfu.getFieldValue("isNew"));        if (StrUtil.isNumeric(strisnew))            isNew = Integer.parseInt(strisnew);        else            isNew = 0;        flowTypeCode = StrUtil.getNullStr(mfu.getFieldValue("flowTypeCode"));        String strCreateDate = StrUtil.getNullStr(mfu.getFieldValue("createDate"));        if (strCreateDate.trim().equals(""))            createDate = new java.util.Date();        else            createDate = DateUtil.parse(strCreateDate, "yyyy-MM-dd HH:mm:ss");                Directory dir = new Directory();                Leaf lf = dir.getLeaf(dir_code);        if (lf.getType() == 0)            throw new ResKeyException("res.cms.Document", "err_dir_type_none");        if (lf.getType() == 1) {            if (getFirstIDByCode(dir_code) != -1)                throw new ResKeyException("res.cms.Document",                                          "err_dir_type_doc_created");                    }        String strCanComment = StrUtil.getNullStr(mfu.getFieldValue(                "canComment"));        if (strCanComment.equals(""))            canComment = false;        else if (strCanComment.equals("1"))            canComment = true;                String strtid = StrUtil.getNullStr(mfu.getFieldValue("templateId"));        if (StrUtil.isNumeric(strtid))            templateId = Integer.parseInt(strtid);        this.id = (int) SequenceMgr.nextID(SequenceMgr.DOCUMENT);                String docType = mfu.getFieldValue("docType");        String[] voptions = null;        type = TYPE_DOC;         if (docType.equals("1")) {            type = TYPE_VOTE;            String voteoption = mfu.getFieldValue("vote").trim();            if (!voteoption.equals("")) {                voptions = voteoption.split("\\r\\n");            }                                                DocPollDb mpd = new DocPollDb();            String epdate = StrUtil.getNullString(mfu.getFieldValue(                    "expire_date"));            java.util.Date expireDate = DateUtil.parse(epdate, "yyyy-MM-dd");            String strMaxChoices = StrUtil.getNullString(mfu.getFieldValue(                    "max_choice"));            int maxChoices = StrUtil.toInt(strMaxChoices, 1);                        mpd.create(new JdbcTemplate(), new Object[] {                new Long(id), expireDate, new Integer(maxChoices)            });            int vlen = voptions.length;                        DocPollOptionDb mpod = new DocPollOptionDb();            for (int i = 0; i < vlen; i++) {                mpod.create(new JdbcTemplate(), new Object[] {                    new Long(id), new Integer(i), voptions[i]                });            }        } else if (docType.equals("2")) {            type = TYPE_LINK;        }        color = StrUtil.getNullStr(mfu.getFieldValue("color"));        bold = StrUtil.getNullStr(mfu.getFieldValue("isBold")).equals("true");        expireDate = DateUtil.parse(mfu.getFieldValue("expireDate"),                                    "yyyy-MM-dd");        source = StrUtil.getNullStr(mfu.getFieldValue("source"));        pageTemplateId = StrUtil.toInt(mfu.getFieldValue("pageTemplateId"), -1);        String subjects = StrUtil.getNullStr(mfu.getFieldValue("subjects"));        String strPageType = StrUtil.getNullStr(mfu.getFieldValue("pageType"));        pageType = StrUtil.toInt(strPageType, PAGE_TYPE_MANUAL);        level = StrUtil.toInt(StrUtil.getNullStr(mfu.getFieldValue("level")), 0);                DocCacheMgr dcm = new DocCacheMgr();        dcm.refreshCreate(dir_code, lf.getParentCode());        

⌨️ 快捷键说明

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