⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 doctemplateimpl.java

📁 云网论坛CWBBS 源码,内容丰富,学习,参考,教学的好资料,具体见内说明,
💻 JAVA
字号:
package cn.js.fan.module.cms.template;

import com.cloudwebsoft.framework.template.VarPart;
import com.cloudwebsoft.framework.util.BeanUtil;
import cn.js.fan.util.ParamUtil;
import com.cloudwebsoft.framework.util.LogUtil;
import cn.js.fan.util.StrUtil;
import cn.js.fan.module.cms.Document;
import cn.js.fan.module.cms.Leaf;
import cn.js.fan.module.cms.Attachment;
import cn.js.fan.web.Global;
import cn.js.fan.module.cms.DocContent;
import cn.js.fan.module.cms.SQLBuilder;
import java.util.Iterator;
import cn.js.fan.module.cms.DocCacheMgr;
import cn.js.fan.util.DateUtil;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 * $doc.dirCode(code).summary 提取文章的摘要
 * $doc.id(id).title 提取文章的标题
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class DocTemplateImpl extends VarPart {
    public DocTemplateImpl() {

    }

    public String write(Document doc) {
        BeanUtil bu = new BeanUtil();
        Object obj = null;
        if (field.equalsIgnoreCase("content")) {
            String pageNum = (String) ParamUtil.get(request, "CPages");
            if (!StrUtil.isNumeric(pageNum)) {
                pageNum = (String) request.getAttribute("CPages");
                if (pageNum == null)
                    pageNum = "1";
            }
            obj = doc.getContent(Integer.parseInt(pageNum));
            return format(obj, props);
        } else if (field.equals("vote")) { // 投票
            if (doc.getType() == 1) {
                String[] voptions = doc.getVoteOption().split("\\|");
                int len = voptions.length;
                String str = "";
                str += "<table>";
                str += "<form action='" + request.getContextPath() + "/doc_vote.jsp?op=vote&id=" + doc.getId() +
                        "' name=formvote method='post'>";
                for (int k = 0; k < len; k++) {
                    str += "<tr>";
                    str += "<td width=26>" + (k+1) + "、</td>";
                    str +=
                            "<td width=720><input class='n' type=radio name=votesel value='" +
                            k + "'>";
                    str += voptions[k] + "</td>";
                    str += "</tr>";
                }
                str += "<tr>";
                str += "<td colspan='2' align=center><input type='submit' value=' 投  票 '>";
                str += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                str += "<input name='btn' type='button' value='查看结果' onClick=\"window.location.href='" + request.getContextPath() + "/doc_vote.jsp?id=" + doc.getId() + "&op=view'\"></td>";
                str += "</tr>";
                str += "</form>";
                str += "</table>";
                return str;
            } else
                return "";
        } else if (field.equalsIgnoreCase("attachments")) {
            String pageNum = (String) ParamUtil.get(request, "CPages");
            if (!StrUtil.isNumeric(pageNum)) {
                pageNum = (String) request.getAttribute("CPages");
                if (pageNum == null)
                    pageNum = "1";
            }
            java.util.Vector attachments = doc.getAttachments(Integer.parseInt(
                    pageNum));
            java.util.Iterator ir = attachments.iterator();
            String str = "";
            while (ir.hasNext()) {
                Attachment am = (Attachment) ir.next();
                str +=
                        "<table width='569'  border='0' cellspacing=0 cellpadding=0>";
                str += "<tr>";
                str +=
                        "<td width=91 height=26 align='right'><img src=" +
                        request.getContextPath() + "/images/attach.gif></td>";
                str +=
                        "<td>&nbsp; <a target=_blank href='" +
                        request.getContextPath() + "/doc_getfile.jsp?pageNum=" +
                        pageNum + "&id=" + doc.getId() + "&attachId=" +
                        am.getId() + "'>" + am.getName() +
                        "</a> &nbsp;下载次数&nbsp;<script src='/" +
                        Global.virtualPath +
                        "/inc/doc_att_down_count.jsp?pageNum=" + pageNum +
                        "&docId=" + doc.getId() + "&attachId=" + +am.getId() +
                        "'></script></td>";
                str += "</tr></table>";
            }
            return str;
        } else if (field.equals("pageBlock")) {
            int pagesize = 1;
            int total = DocContent.getContentCount(doc.getID());
            DocPagniator paginator = new DocPagniator(request, total, pagesize);
            String isCreateHtml = StrUtil.getNullStr((String) request.
                    getAttribute("isCreateHtml"));
            if (isCreateHtml.equals("true")) {
                String pageNum = (String) ParamUtil.get(request, "CPages");
                if (!StrUtil.isNumeric(pageNum)) {
                    pageNum = (String) request.getAttribute("CPages");
                    if (pageNum == null)
                        pageNum = "1";
                }
                return paginator.getHtmlCurPageBlock(doc,
                        Integer.parseInt(pageNum));
            } else
                return paginator.getCurPageBlock("?id=" +
                                                 ParamUtil.get(request, "id") +
                                                 "&dirCode=" +
                                                 StrUtil.
                                                 UrlEncode(ParamUtil.
                        get(request, "dirCode")));
        } else if (field.equals("relatedDoc")) {
            String keywords = StrUtil.getNullStr(doc.getKeywords());
            String str = "";
            if (!keywords.equals("")) {
                String sql = SQLBuilder.getDocRelateSql(keywords);
                cn.js.fan.module.cms.Config cfg = new cn.js.fan.module.cms.
                                                  Config();
                boolean isHtml = cfg.getBooleanProperty("cms.html_doc");
                Iterator ir = doc.getDocuments(sql, DocCacheMgr.FULLTEXT, 0, 10);
                while (ir.hasNext()) {
                    Document document = (Document) ir.next();
                    str +=
                            "<table width=100% border=0 align=left cellpadding=0 cellspacing=0 class=p>";
                    str += "<tr>";
                    // 系统设置是否静态化
                    if (!isHtml) {
                        str += "<td height=20 align=left>&nbsp;&nbsp;<a href='" +
                                request.getContextPath() + "/doc_view.jsp?id=" +
                                document.getId() + "'>" + document.getTitle() +
                                "</a>&nbsp;&nbsp;&nbsp;[" +
                                DateUtil.format(document.getModifiedDate(),
                                                "yyyy-MM-dd") +
                                "]</td>";
                    } else {
                        str += "<td height=20 align=left>&nbsp;&nbsp;<a href='" +
                                request.getContextPath() + "/" +
                                doc.getDocHtmlName(1) + "'>" +
                                document.getTitle() +
                                "</a>&nbsp;&nbsp;&nbsp;[" +
                                DateUtil.format(document.getModifiedDate(),
                                                "yyyy-MM-dd") +
                                "]</td>";
                    }
                    str += "</tr>";
                    str += "</table>";
                }
            }
            return str;
        } else if (field.equals("comment_post")) {
            String str = "<a href='" + request.getContextPath() +
                         "/doc_comment.jsp?id=" + doc.getId() + "'>【发表评论】";
            if (doc.isCanComment())
                return str;
            else
                return "";
        } else {
            obj = bu.getProperty(doc, field);
            return format(obj, props);
        }
    }

    public String toString() {
        if (keyName.equalsIgnoreCase("id")) {
            // LogUtil.getLog(getClass()).info("toString:keyValue=" + keyValue);
            if (keyValue.equals("")) {
                keyValue = (String) request.getAttribute("id"); // 当添加修改文章自动生成静态页面时
            }
            int id = Integer.parseInt(keyValue);
            Document doc = new Document();
            doc = doc.getDocument(id);
            return write(doc);
        } else if (keyName.equalsIgnoreCase("dirCode")) {
            Leaf lf = new Leaf();
            lf = lf.getLeaf(keyValue);
            int id = lf.getDocID();
            Document doc = new Document();
            doc = doc.getDocument(id);
            return write(doc);
        } else
            return "Key " + keyName + " is invalid!";
    }

}

⌨️ 快捷键说明

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