listsubjecttemplateimpl.java
来自「cwbbs 云网论坛源码」· Java 代码 · 共 186 行
JAVA
186 行
package cn.js.fan.module.cms.template;import java.util.*;import javax.servlet.http.*;import cn.js.fan.db.*;import cn.js.fan.module.cms.*;import cn.js.fan.util.*;import com.cloudwebsoft.framework.template.*;import com.cloudwebsoft.framework.util.LogUtil;import cn.js.fan.web.Global;public class ListSubjectTemplateImpl extends ListPart { String dirCode = ""; String query = ""; public ListSubjectTemplateImpl() { } public String toString(HttpServletRequest request, List params) { if (steps == null) return ""; dirCode = StrUtil.getNullStr((String) props.get("dirCode")); String dir = dirCode; if (dirCode!=null && dirCode.startsWith("request")) { int p = dirCode.indexOf("."); if (p!=-1) { String param = dirCode.substring(p + 1); dir = ParamUtil.get(request, param); if (dir.equals("")) { dir = StrUtil.getNullStr((String)request.getAttribute("dirCode")); } } } if (dir.equals("")) throw new IllegalArgumentException("ListSubjectTemplateImpl " + getName() + "'s dirCode is empty."); boolean isCreateHtml = StrUtil.getNullStr((String)request.getAttribute("isCreateHtml")).equals("true"); String s = (String) props.get("start"); if (s!=null && !StrUtil.isNumeric(s)) throw new IllegalArgumentException("start:" + s + " is not a number"); String e = (String) props.get("end"); if (e!=null && !StrUtil.isNumeric(e)) throw new IllegalArgumentException("end:" + e + " is not a number"); cn.js.fan.module.cms.Config cfg = new cn.js.fan.module.cms.Config(); int pageSize = cfg.getIntProperty("cms.listPageSize"); query = StrUtil.getNullStr((String)props.get("query")); int total = 0; SubjectListDb sld = new SubjectListDb(); if (!query.equals("")) { total = sld.getDocCount(query); } else { query = SQLBuilder.getSubjectDocListSql(dir); total = sld.getDocCount(query); } int myStart = -1, myEnd = -1; if (s == null && e == null) { String cp = ParamUtil.get(request, "CPages"); if (cp.equals("")) { cp = (String) request.getAttribute("CPages"); } int curPage = StrUtil.toInt(cp, 1); myStart = (curPage - 1) * pageSize; myEnd = curPage * pageSize; if (isCreateHtml) { int listPageHtmlCreateCount = cfg.getIntProperty("cms.listPageHtmlCreateCount"); if (curPage>listPageHtmlCreateCount) { int t = pageSize * paginator.getTotalPages() - total; if (t>0) { myStart -= t; myEnd -= t; } } } } else { myStart = Integer.parseInt(s); myEnd = Integer.parseInt(e); } Iterator ir = null; total = sld.getDocCount(query); ir = sld.getDocuments(query, dir, myStart, myEnd); paginator = new Paginator(request, total, pageSize); StringBuffer buf = new StringBuffer(); boolean isHtml = cfg.getBooleanProperty("cms.html_doc"); while (ir.hasNext()) { Document doc = (Document) ir.next(); int nSteps = steps.size(); for (int i = 0; i < nSteps; i++) { ITemplate step = (ITemplate) steps.get(i); if (step instanceof PaginatorPart) { PaginatorPart pp = (PaginatorPart)step; String writeCount = (String)request.getAttribute(pp.hashCode() + "_WriteCount_" + myStart); if ((i==0 || !ir.hasNext()) && writeCount==null) { if (isCreateHtml) { int pageNo = StrUtil.toInt(StrUtil.getNullStr((String)request.getAttribute("pageNo")), 1); String pageStatics = "<script src=\"" + request.getContextPath() + "/inc/subject_list_page.jsp?op=statics&pageNo=" + pageNo + "&dirCode=" + StrUtil.UrlEncode(dir) + "\"></script>"; String pageBlock = "<script src=\"" + request.getContextPath() + "/inc/subject_list_page.jsp?pageNo=" + pageNo + "&dirCode=" + StrUtil.UrlEncode(dir) + "\"></script>"; buf.append(pp.write(request, this, pageStatics, pageBlock)); } else { pp.setUrl("?dirCode=" + StrUtil.UrlEncode(dir)); buf.append(pp.write(request, this)); } request.setAttribute(pp.hashCode() + "_WriteCount_" + myStart, "y"); } else continue; } else if (step instanceof FieldPart) { FieldPart fp = (FieldPart) step; if (fp.getName().equalsIgnoreCase("linkUrl")) { if (isHtml) { if (Global.virtualPath.equals("")) buf.append("/" + sld.getDocHtmlName(dir, doc, 1)); else buf.append("/" + Global.virtualPath + "/" + sld.getDocHtmlName(dir, doc, 1)); } else { buf.append(request.getContextPath() + "/subject_view.jsp?id=" + doc.getId() + "&dirCode=" + StrUtil.UrlEncode(dir)); } } else { buf.append(((FieldPart) step).write(doc)); } } else if (step instanceof ListPart) { ListPart listPart = (ListPart) step; String dynName = listPart.getName(); buf.append("<!-- BEGIN:" + dynName + "-->\n"); buf.append(listPart.toString(request, null)); buf.append("<!-- END:" + dynName + "-->\n"); } else { buf.append(step.toString(request, null)); } } } return buf.toString(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?