documentmgr.java
来自「cwbbs 云网论坛源码」· Java 代码 · 共 1,162 行 · 第 1/3 页
JAVA
1,162 行
IPrivilege privilege) throws ErrMsgException { Document doc = getDocument(id); String v = ParamUtil.get(request, "value"); boolean re = doc.UpdateIsHome(v.equals("y") ? true : false); return re; } public boolean vote(HttpServletRequest request, int id) throws ErrMsgException { Privilege privilege = new Privilege(); if (!privilege.isUserLogin(request)) throw new ErrMsgException(SkinUtil.LoadString(request, SkinUtil.ERR_NOT_LOGIN)); String[] opts = ParamUtil.getParameters(request, "votesel"); if (opts==null) throw new ErrMsgException(SkinUtil.LoadString(request, "res.forum.MsgDb", "err_vote_none")); String name = privilege.getUser(request); DocPollDb mpd = new DocPollDb(); mpd = (DocPollDb)mpd.getQObjectDb(new Integer(id)); Date d = mpd.getDate("expire_date"); if (d!=null) { if (DateUtil.compare(d, new java.util.Date()) != 1) throw new ErrMsgException(StrUtil.format(SkinUtil.LoadString(request,"res.forum.MsgDb", "err_vote_expire"), new Object[] {DateUtil.format(d, "yyyy-MM-dd")})); } int len = opts.length; int max_choice = mpd.getInt("max_choice"); if (len > max_choice) { throw new ErrMsgException(StrUtil.format(SkinUtil.LoadString(request,"res.forum.MsgDb", "err_vote_max_count"), new Object[] {"" + max_choice})); } DocPollOptionDb mpod = new DocPollOptionDb(); Vector v = mpd.getOptions(id); int optLen = v.size(); for (int i=0; i<optLen; i++) { DocPollOptionDb mo = mpod.getDocPollOptionDb(id, i); String vote_user = StrUtil.getNullString(mo.getString("vote_user")); String[] ary = StrUtil.split(vote_user, ","); if (ary!=null) { int len2 = ary.length; for (int k=0; k<len2; k++) { if (ary[k].equals(name)) throw new ErrMsgException(SkinUtil.LoadString(request, "res.forum.MsgDb", "err_vote_repeat")); } } } boolean re = true; for (int i=0; i<len; i++) { DocPollOptionDb mo = mpod.getDocPollOptionDb(id, StrUtil.toInt(opts[i])); mo.set("vote_count", new Integer(mo.getInt("vote_count") + 1)); String vote_user = StrUtil.getNullString(mo.getString("vote_user")); if (vote_user.equals("")) vote_user = name; else vote_user += "," + name; mo.set("vote_user", vote_user); try { re = mo.save(); } catch (ResKeyException e) { throw new ErrMsgException(e.getMessage(request)); } } return re; } public boolean OperatePage(ServletContext application, HttpServletRequest request, IPrivilege privilege) throws ErrMsgException { CMSMultiFileUploadBean mfu = doUpload(application, request); fileUpload = mfu; String op = StrUtil.getNullStr(mfu.getFieldValue("op")); String dir_code = StrUtil.getNullStr(mfu.getFieldValue("dir_code")); boolean isValid = false; LeafPriv lp = new LeafPriv(); lp.setDirCode(dir_code); if (op.equals("add")) { if (lp.canUserAppend(privilege.getUser(request))) isValid = true; } if (op.equals("edit")) { if (lp.canUserModify(privilege.getUser(request))) isValid = true; } if (!isValid) throw new ErrMsgException(Privilege.MSG_INVALID); String strdoc_id = StrUtil.getNullStr(mfu.getFieldValue("id")); int doc_id = Integer.parseInt(strdoc_id); Document doc = new Document(); doc = doc.getDocument(doc_id); if (op.equals("add")) { String content = StrUtil.getNullStr(mfu.getFieldValue( "htmlcode")); boolean re = doc.AddContentPage(application, mfu, content); if (re) { Config cfg = new Config(); boolean isCreateHtml = cfg.getBooleanProperty("cms.html_auto"); if (isCreateHtml) { createAllPageHtml(request, doc); } } return re; } else if (op.equals("edit")) { boolean re = doc.EditContentPage(application, mfu); if (re) { String strpageNum = StrUtil.getNullStr(mfu.getFieldValue( "pageNum")); int pageNum = Integer.parseInt(strpageNum); Config cfg = new Config(); boolean isCreateHtml = cfg.getBooleanProperty("cms.html_auto"); if (isCreateHtml) { createHtml(request, doc, pageNum); } } return re; } return false; } public boolean uploadDocument(ServletContext application, HttpServletRequest request) throws ErrMsgException { java.util.Date currentTime = new java.util.Date(); long inserttime = currentTime.getTime(); String filenm = String.valueOf(inserttime); FileUpload TheBean = new FileUpload(); TheBean.setMaxFileSize(Global.FileSize); int ret = 0; try { ret = TheBean.doUpload(application, request); if (ret == -3) { String str = SkinUtil.LoadString(request, "res.cms.Document", "err_upload_size"); str = StrUtil.format(str, new Object[] {"" + Global.FileSize}); throw new ErrMsgException(str); } if (ret == -4) { throw new ErrMsgException(TheBean.getErrMessage(request)); } } catch (Exception e) { logger.error("uploadDocument:" + e.getMessage()); } if (ret == 1) { Document doc = new Document(); boolean re = false; try { re = doc.uploadDocument(TheBean); } catch (ResKeyException e) { throw new ErrMsgException(e.getMessage(request)); } return re; } else return false; } public void createListPageHtml(HttpServletRequest request, String dirCode, int pageNum) { if (Leaf.isLeafOfSubsite(dirCode)) return; Leaf lf = new Leaf(); lf = lf.getLeaf(dirCode); try { TemplateDb td = lf.getTemplateDb(); String filePath = Global.realPath + td.getString("path"); TemplateLoader tl = new TemplateLoader(request, filePath); request.setAttribute("dirCode", dirCode); request.setAttribute("isCreateHtml", "true"); request.setAttribute("CPages", "" + pageNum); FileUtil fu = new FileUtil(); File f = new File(Global.getRealPath() + lf.getListHtmlPath()); if (!f.isDirectory()) { f.mkdirs(); } Document doc = new Document(); String sql = SQLBuilder.getDirDocListSql(dirCode); int total = doc.getDocCount(sql); Config cfg = new Config(); int pageSize = cfg.getIntProperty("cms.listPageSize"); ListDocPagniator paginator = new ListDocPagniator(request, total, pageSize); int pageNo = paginator.pageNum2No(pageNum); request.setAttribute("pageNo", "" + pageNo); fu.WriteFile(Global.getRealPath() + lf.getListHtmlNameByPageNo(pageNo), tl.toString(), "UTF-8"); ListResult lr = doc.listResult(sql, pageNum, pageSize); Iterator ir = lr.getResult().iterator(); while (ir.hasNext()) { doc = (Document)ir.next(); doc.setPageNo(pageNo); doc.save(); } } catch (IOException e) { LogUtil.getLog(getClass()).error("createListPageHtml:" + e.getMessage()); } catch (ErrMsgException e) { LogUtil.getLog(getClass()).error("createListPageHtm2:" + e.getMessage()); } } public void createSubjectListHtmlOfDirecroty(HttpServletRequest request) throws ErrMsgException { String dirCode = ParamUtil.get(request, "code"); boolean isIncludeChildren = ParamUtil.getBoolean(request, "isIncludeChildren", false); int pageNumBegin = ParamUtil.getInt(request, "pagNumBegin", 1); int pageNumEnd = ParamUtil.getInt(request, "pagNumEnd", -1); createSubjectListHtmlOfDirectory(request, dirCode, isIncludeChildren, pageNumBegin, pageNumEnd); } public void createSubjectListHtmlOfDirectory(HttpServletRequest request, String dirCode, boolean isIncludeChildren, int pageNumBegin, int pageNumEnd) throws ErrMsgException { String sql = SQLBuilder.getSubjectDocListSql(dirCode); SubjectListDb doc = new SubjectListDb(); int total = doc.getDocCount(sql); cn.js.fan.module.cms.Config cfg = new cn.js.fan.module.cms.Config(); int pageSize = cfg.getIntProperty("cms.listPageSize"); Paginator paginator = new Paginator(request, total, pageSize); int totalpages = paginator.getTotalPages(); if (totalpages == 0) { totalpages = 1; } if (pageNumEnd == -1) { pageNumEnd = totalpages; } for (int num = pageNumBegin; num <= pageNumEnd; num++) { createSubjectListPageHtml(request, dirCode, num); } if (isIncludeChildren) { SubjectDb lf = new SubjectDb(); lf = lf.getSubjectDb(dirCode); Vector vchild = lf.getChildren(); Iterator irchild = vchild.iterator(); while (irchild.hasNext()) { Leaf childlf = (Leaf) irchild.next(); createSubjectListHtmlOfDirectory(request, childlf.getCode(), isIncludeChildren, pageNumBegin, pageNumEnd); } } } public void createSubjectListPageHtml(HttpServletRequest request, String subjectCode, int pageNum) { SubjectDb lf = new SubjectDb(); lf = lf.getSubjectDb(subjectCode); try { TemplateDb td = lf.getTemplateDb(); String filePath = Global.realPath + td.getString("path"); TemplateLoader tl = new TemplateLoader(request, filePath); request.setAttribute("dirCode", subjectCode); request.setAttribute("isCreateHtml", "true"); request.setAttribute("CPages", "" + pageNum); FileUtil fu = new FileUtil(); File f = new File(Global.getRealPath() + lf.getListHtmlPath()); if (!f.isDirectory()) { f.mkdirs(); } Document doc = new Document(); String sql = SQLBuilder.getSubjectDocListSql(subjectCode); int total = doc.getDocCount(sql); Config cfg = new Config(); int pageSize = cfg.getIntProperty("cms.listPageSize"); ListDocPagniator paginator = new ListDocPagniator(request, total, pageSize); int pageNo = paginator.pageNum2No(pageNum); request.setAttribute("pageNo", "" + pageNo); fu.WriteFile(Global.getRealPath() + lf.getListHtmlNameByPageNo(pageNo), tl.toString(), "UTF-8"); } catch (IOException e) { LogUtil.getLog(getClass()).error("createListPageHtml:" + e.getMessage()); } catch (ErrMsgException e) { LogUtil.getLog(getClass()).error("createListPageHtm2:" + e.getMessage()); } } public void createColumnPageHtml(HttpServletRequest request, String dirCode) { Leaf lf = new Leaf(); lf = lf.getLeaf(dirCode); try { TemplateDb td = lf.getTemplateDb(); String filePath = Global.realPath + td.getString("path"); TemplateLoader tl = new TemplateLoader(request, filePath); request.setAttribute("dirCode", dirCode); request.setAttribute("isCreateHtml", "true"); FileUtil fu = new FileUtil(); File f = new File(Global.getRealPath() + lf.getListHtmlPath()); if (!f.isDirectory()) { f.mkdirs(); } Config cfg = new Config(); fu.WriteFile(Global.getRealPath() + lf.getListHtmlPath() + "/index." + cfg.getProperty("cms.html_ext"), tl.toString(), "UTF-8"); } catch (IOException e) { LogUtil.getLog(getClass()).error("createColumnPageHtml:" + e.getMessage()); } catch (ErrMsgException e) { LogUtil.getLog(getClass()).error("createColumnPageHtm2:" + e.getMessage()); } } public void delAllPageHtml(HttpServletRequest request, Document doc) throws ErrMsgException { for (int i = 0; i < doc.getPageCountPlugin(); i++) { File f = new File(Global.getRealPath() + doc.getDocHtmlName(i + 1)); f.delete(); } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?