📄 forumcovertag.java
字号:
package com.laoer.bbscs.web.taglib;
import java.util.*;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import org.apache.struts.taglib.*;
import org.springframework.web.context.*;
import org.springframework.web.context.support.*;
import com.laoer.bbscs.bean.*;
import com.laoer.bbscs.comm.*;
import com.laoer.bbscs.service.BoardService;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
/**
* <p>Title: Tianyi BBS</p>
*
* <p>Description: BBSCS</p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: Laoer.com</p>
*
* @author Gong Tianyi
* @version 7.0
*/
public class ForumCoverTag
extends TagSupport {
private static final Log logger = LogFactory.getLog(ForumCoverTag.class);
protected String type = "";
protected String boardObjName = "board";
protected String commendListObjName = "commendList";
private String boardListObjName = "blist";
protected String boardHotObjName = "bhotlist";
public ForumCoverTag() {
}
public int doStartTag() throws JspException {
return (SKIP_BODY);
}
public int doEndTag() throws JspException {
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
WebApplicationContext wc = WebApplicationContextUtils.getWebApplicationContext(this.
pageContext.getServletContext());
Object boardObj = TagUtils.getInstance().lookup(pageContext, boardObjName, null, null);
Board board = (Board) boardObj;
//StringBuffer sb = new StringBuffer();
if (this.getType().equalsIgnoreCase("commend")) {
/*
Object commendListObj = TagUtils.getInstance().lookup(pageContext, commendListObjName, null, null);
List commendList = (List) commendListObj;
int counter = 0;
for (int i = 0; i < commendList.size(); i++) {
Commend c = (Commend) commendList.get(i);
if (counter == 0) {
counter = 2;
sb.append("<tr>");
}
sb.append("<td width=\"50%\">");
sb.append("[<a href=\"");
sb.append(BBSCSUtil.getActionMappingURL("/forum?action=index&bid=" + c.getBoardID(), request));
sb.append("\">");
sb.append(c.getBoardName());
sb.append("</a>]");
sb.append("<a href=\"");
sb.append(BBSCSUtil.getActionMappingURL("/read?action=topic&id=" + c.getPostMainID() + "&bid=" +
c.getBoardID(), request));
sb.append("\">");
sb.append(c.getTitle());
sb.append("</a>");
sb.append("</td>");
if (counter == 1) {
counter = 0;
sb.append("</tr>");
}
else {
counter = counter - 1;
}
}*/
File commendFile = new File(BBSCSUtil.getIncludePath() + "ForumCover_Commend_" +
board.getId().longValue() + ".html");
String commendlist = "";
try {
commendlist = FileUtils.readFileToString(commendFile, Constant.CHARSET);
if (commendlist == null) {
commendlist = "";
}
}
catch (IOException ex) {
logger.error(ex);
commendlist = "";
}
TagUtils.getInstance().write(pageContext, commendlist);
return (SKIP_BODY);
}
if (this.getType().equalsIgnoreCase("boardlist")) {
/*
Object boardListObj = TagUtils.getInstance().lookup(pageContext, boardListObjName, null, null);
BoardService boardService = (BoardService) wc.getBean("boardService");
List blist = (List) boardListObj;
for (int i = 0; i < blist.size(); i++) {
Board b = (Board) blist.get(i);
sb.append("<tr>");
sb.append("<td width=\"15%\">·");
sb.append("<a href=\"");
sb.append(BBSCSUtil.getActionMappingURL("/forum?action=index&bid=" + b.getId().longValue(), request));
sb.append("\">");
sb.append(b.getBoardName());
sb.append("</a>");
sb.append(">></td>");
sb.append("<td width=\"85%\">");
List blist1 = boardService.findBoardsByParentID(b.getId().longValue(), 1, 0,
Constant.FIND_BOARDS_BY_ORDER);
for (int j = 0; j < blist1.size(); j++) {
Board b1 = (Board) blist1.get(j);
sb.append("·");
sb.append("<a href=\"");
sb.append(BBSCSUtil.getActionMappingURL("/forum?action=index&bid=" + b1.getId().longValue(),
request));
sb.append("\">");
sb.append(b1.getBoardName());
sb.append("</a> ");
}
sb.append("</td>");
sb.append("</tr>");
}*/
/**
Map bmap = (Map) boardMapObjObj;
Set bset = bmap.entrySet();
Iterator it = bset.iterator();
while (it.hasNext()) {
Map.Entry bentry = (Map.Entry) it.next();
Board b = (Board) bentry.getKey();
List blist1 = (List) bentry.getValue();
sb.append("<tr>");
sb.append("<td width=\"15%\">·");
sb.append("<a href=\"");
sb.append(BBSCSUtil.getActionMappingURL("/forum?action=index&bid=" + b.getId().longValue(), request));
sb.append("\">");
sb.append(b.getBoardName());
sb.append("</a>");
sb.append(">></td>");
sb.append("<td width=\"85%\">");
for (int j = 0; j < blist1.size(); j++) {
Board b1 = (Board) blist1.get(j);
sb.append("·");
sb.append("<a href=\"");
sb.append(BBSCSUtil.getActionMappingURL("/forum?action=index&bid=" + b1.getId().longValue(),
request));
sb.append("\">");
sb.append(b1.getBoardName());
sb.append("</a> ");
}
sb.append("</td>");
sb.append("</tr>");
}*/
File blistFile = new File(BBSCSUtil.getIncludePath() + "ForumCover_BoardList_" +
board.getId().longValue() + ".html");
String boardlist = "";
try {
boardlist = FileUtils.readFileToString(blistFile, Constant.CHARSET);
if (boardlist == null) {
boardlist = "";
}
}
catch (IOException ex) {
logger.error(ex);
boardlist = "";
}
TagUtils.getInstance().write(pageContext, boardlist);
return (SKIP_BODY);
}
if (this.getType().equalsIgnoreCase("hotboard")) {
/*
Object boardHotObj = TagUtils.getInstance().lookup(pageContext, boardHotObjName, null, null);
List bhotlist = (List) boardHotObj;
BoardService boardService = (BoardService) wc.getBean("boardService");
List bhlist = boardService.getBoardsNeedCount(bhotlist);
Collections.sort(bhlist, new BoardsMainPostNumComparator());
int len = bhlist.size();
if (len >= 10) {
len = 10;
}
for (int i = 0; i < len; i++) {
Board b = (Board) bhlist.get(i);
sb.append("<tr>");
sb.append("<td width=\"70%\">");
sb.append("<a href=\"");
sb.append(BBSCSUtil.getActionMappingURL("/forum?action=index&bid=" + b.getId().longValue(), request));
sb.append("\">");
sb.append(b.getBoardName());
sb.append("</a>");
sb.append("</td>");
sb.append("<td width=\"30%\">");
sb.append(b.getMainPostNum());
sb.append("</td>");
sb.append("</tr>");
}*/
File bhostlistFile = new File(BBSCSUtil.getIncludePath() + "ForumCover_BoardHotList_" +
board.getId().longValue() + ".html");
String boardhostlist = "";
try {
boardhostlist = FileUtils.readFileToString(bhostlistFile, Constant.CHARSET);
if (boardhostlist == null) {
boardhostlist = "";
}
}
catch (IOException ex) {
logger.error(ex);
boardhostlist = "";
}
TagUtils.getInstance().write(pageContext, boardhostlist);
return (SKIP_BODY);
}
if (this.getType().equalsIgnoreCase("choice")) {
File choiceFile = new File(BBSCSUtil.getIncludePath() + "Choice_" + board.getId().longValue() + ".html");
String choice = "";
try {
choice = FileUtils.readFileToString(choiceFile, Constant.CHARSET);
if (choice == null) {
choice = "";
}
}
catch (IOException ex) {
logger.error(ex);
choice = "";
}
TagUtils.getInstance().write(pageContext, choice);
return (SKIP_BODY);
}
return (SKIP_BODY);
}
public String getBoardObjName() {
return boardObjName;
}
public String getType() {
return type;
}
public String getBoardListObjName() {
return boardListObjName;
}
public String getCommendListObjName() {
return commendListObjName;
}
public String getBoardHotObjName() {
return boardHotObjName;
}
public void setBoardObjName(String boardObjName) {
this.boardObjName = boardObjName;
}
public void setType(String type) {
this.type = type;
}
public void setBoardListObjName(String boardListObjName) {
this.boardListObjName = boardListObjName;
}
public void setCommendListObjName(String commendListObjName) {
this.commendListObjName = commendListObjName;
}
public void setBoardHotObjName(String boardHotObjName) {
this.boardHotObjName = boardHotObjName;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -