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

📄 forumcomponent.java

📁 交易撮合系统是一套买卖信息沟通的平台
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
package com.laoer.bbscs.web.taglib;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.sql.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.struts2.components.Component;
import org.apache.struts2.views.jsp.IteratorStatus;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.laoer.bbscs.bean.Board;
import com.laoer.bbscs.bean.Forum;
import com.laoer.bbscs.bean.ForumBuy;
import com.laoer.bbscs.bean.UserInfoSimple;
import com.laoer.bbscs.bean.Vote;
import com.laoer.bbscs.comm.BBSCSUtil;
import com.laoer.bbscs.comm.Constant;
import com.laoer.bbscs.comm.Util;
import com.laoer.bbscs.service.Cache;
import com.laoer.bbscs.service.ForumService;
import com.laoer.bbscs.service.UserService;
import com.laoer.bbscs.service.VoteItemService;
import com.laoer.bbscs.service.VoteService;
import com.laoer.bbscs.service.config.ForumConfig;
import com.laoer.bbscs.service.config.SysConfig;
import com.laoer.bbscs.web.servlet.UserCookie;
import com.laoer.bbscs.web.servlet.UserSession;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.TextUtils;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

public class ForumComponent extends Component {
	/**
	 * Logger for this class
	 */
	private static final Log logger = LogFactory.getLog(ForumComponent.class);

	private PageContext pageContext;

	private HttpServletRequest request;

	private HttpServletResponse response;

	private String forumValue = "";

	private String boardValue = "%{board}";

	private String itemClass = "font2";

	private String inPagesValue = "%{inpages}";

	private String currentPageValue = "%{page}";

	private String currentActionValue = "%{action}";

	private String tagIdValue = "%{tagId}";

	private String type = "";

	private String totalnumValue = "%{totalnum}";

	protected String indexValue = "%{rowstatus}";

	private WebApplicationContext wc = null;

	public ForumComponent(ValueStack stack, PageContext pageContext, HttpServletRequest request,
			HttpServletResponse response) {
		super(stack);
		this.pageContext = pageContext;
		this.request = request;
		this.response = response;
		this.wc = WebApplicationContextUtils.getWebApplicationContext(pageContext.getServletContext());
	}

	@SuppressWarnings("unchecked")
	public boolean start(Writer writer) {
		boolean result = super.start(writer);
		if (forumValue == null) {
			forumValue = "top";
		} else if (altSyntax()) {
			if (forumValue.startsWith("%{") && forumValue.endsWith("}")) {
				forumValue = forumValue.substring(2, forumValue.length() - 1);
			}
		}
		if (boardValue == null) {
			boardValue = "top";
		} else if (altSyntax()) {
			if (boardValue.startsWith("%{") && boardValue.endsWith("}")) {
				boardValue = boardValue.substring(2, boardValue.length() - 1);
			}
		}
		if (inPagesValue == null) {
			inPagesValue = "top";
		} else if (altSyntax()) {
			if (inPagesValue.startsWith("%{") && inPagesValue.endsWith("}")) {
				inPagesValue = inPagesValue.substring(2, inPagesValue.length() - 1);
			}
		}
		if (currentPageValue == null) {
			currentPageValue = "top";
		} else if (altSyntax()) {
			if (currentPageValue.startsWith("%{") && currentPageValue.endsWith("}")) {
				currentPageValue = currentPageValue.substring(2, currentPageValue.length() - 1);
			}
		}
		if (currentActionValue == null) {
			currentActionValue = "top";
		} else if (altSyntax()) {
			if (currentActionValue.startsWith("%{") && currentActionValue.endsWith("}")) {
				currentActionValue = currentActionValue.substring(2, currentActionValue.length() - 1);
			}
		}
		if (tagIdValue == null) {
			tagIdValue = "top";
		} else if (altSyntax()) {
			if (tagIdValue.startsWith("%{") && tagIdValue.endsWith("}")) {
				tagIdValue = tagIdValue.substring(2, tagIdValue.length() - 1);
			}
		}
		if (totalnumValue == null) {
			totalnumValue = "top";
		} else if (altSyntax()) {
			if (totalnumValue.startsWith("%{") && totalnumValue.endsWith("}")) {
				totalnumValue = totalnumValue.substring(2, totalnumValue.length() - 1);
			}
		}
		if (indexValue == null) {
			indexValue = "top";
		} else if (altSyntax()) {
			if (indexValue.startsWith("%{") && indexValue.endsWith("}")) {
				indexValue = indexValue.substring(2, indexValue.length() - 1);
			}
		}

		// WebApplicationContext wc =
		// WebApplicationContextUtils.getWebApplicationContext(this.pageContext
		// .getServletContext());
		SysConfig sysConfig = (SysConfig) wc.getBean("sysConfig");
		ResourceBundleMessageSource messageSource = (ResourceBundleMessageSource) wc.getBean("messageSource");
		StringBuffer sb = new StringBuffer();

		Object forumObj = this.getStack().findValue(forumValue);
		if (forumObj == null) {
			return result;
		}
		Forum f = (Forum) forumObj;

		if (type.equalsIgnoreCase("floor")) {
			int index = 0;
			Object statusObj = this.getStack().findValue(indexValue);
			if (statusObj != null) {
				index = ((IteratorStatus) statusObj).getIndex();
			}
			int inpages = 1;
			Object inpagesObj = this.getStack().findValue(inPagesValue);
			if (inpagesObj != null) {
				inpages = ((Integer) inpagesObj).intValue();
			}
			UserCookie uc = new UserCookie(request, response, sysConfig);
			int perNum = this.getUserPostPerNum(uc.getPostPerNum(), sysConfig.getPostPerPage());
			int floor = (inpages - 1) * perNum + index;
			if (floor == 0) {
				sb.append(messageSource.getMessage("forum.floor0", null, request.getLocale()));
			} else {
				sb.append(messageSource.getMessage("forum.floor1", new String[] { String.valueOf(floor) }, request
						.getLocale()));
			}
			this.write(writer, sb.toString());
			return result;
		}

		if (type.equalsIgnoreCase("face")) {
			if (f.getFace() == 0) {
				sb.append("<img src=\"");
				sb.append(sysConfig.getPostDefFaceImg());
				sb.append("\" align=\"absmiddle\"/>");
			} else {
				sb.append("<img src=\"images/");
				sb.append(f.getFace());
				sb.append(".gif\" align=\"absmiddle\"/>");
			}
			this.write(writer, sb.toString());
			return result;
		}

		if (type.equalsIgnoreCase("title")) {
			Object boardObj = this.getStack().findValue(this.boardValue);
			int boardType = 3;
			Board board = (Board) boardObj;
			boardType = board.getBoardType();
			Object forumCurrentPageObj = this.getStack().findValue(this.currentPageValue);
			int fcpage = 1;
			if (forumCurrentPageObj != null) {
				fcpage = ((Integer) forumCurrentPageObj).intValue();
			}

			String fcaction = "index";
			Object fcactionObj = this.getStack().findValue(this.currentActionValue);
			if (fcactionObj != null) {
				fcaction = (String) fcactionObj;
			}

			String tagId = "0";
			Object tagIdObj = this.getStack().findValue(this.tagIdValue);
			if (tagIdObj != null) {
				tagId = (String) tagIdObj;
			}

			if (boardType == 2) {
				if (board.getId().longValue() != f.getBoardID()) {
					sb.append("[");
					sb.append(f.getBoardName());
					sb.append("] ");
				}
			}
			if (!f.getTagID().equals("0") && tagId.equals("0")) {
				sb.append("[");
				sb.append(f.getTagName());
				sb.append("] ");
			}
			if (f.getPostType() != 0) {
				if (f.getPostType() == 1) {
					sb.append(messageSource.getMessage("post.firstpus", null, this.request.getLocale()));
					sb.append(" ");
					// sb.append("[原创] ");
				}
				if (f.getPostType() == 2) {
					sb.append(messageSource.getMessage("post.fw", null, this.request.getLocale()));
					sb.append(" ");
					// sb.append("[转载] ");
				}
			}
			if (f.getIsVote() == 1) {
				// sb.append("[投票] ");
				sb.append(messageSource.getMessage("post.vote.title", null, this.request.getLocale()));
				sb.append(" ");
			}
			if (f.getTitleColor() != 0) {
				sb.append("<a href=\"");
				if (Constant.USE_URL_REWRITE) {
					sb.append("read-topic-" + f.getBoardID() + "-" + f.getMainID() + "-" + tagId + "-" + fcpage + "-"
							+ fcaction + "-1" + ".html");
				} else {
					sb.append(BBSCSUtil.getActionMappingURL("/read?action=topic&id=" + f.getMainID() + "&bid="
							+ f.getBoardID() + "&fcpage=" + fcpage + "&fcaction=" + fcaction + "&tagId=" + tagId,
							request));
				}
				sb.append("\">");
				sb.append("<font color=\"");
				sb.append(Constant.TITLECOLOR[f.getTitleColor()]);
				sb.append("\"><strong>");
				sb.append(TextUtils.htmlEncode(f.getTitle()));
				sb.append("</strong></font>");
				sb.append("</a>");
			} else {
				sb.append("<a href=\"");
				if (Constant.USE_URL_REWRITE) {
					sb.append("read-topic-" + f.getBoardID() + "-" + f.getMainID() + "-" + tagId + "-" + fcpage + "-"
							+ fcaction + "-1" + ".html");
				} else {
					sb.append(BBSCSUtil.getActionMappingURL("/read?action=topic&id=" + f.getMainID() + "&bid="
							+ f.getBoardID() + "&fcpage=" + fcpage + "&fcaction=" + fcaction + "&tagId=" + tagId,
							request));
				}

				sb.append("\">");
				sb.append(TextUtils.htmlEncode(f.getTitle()));
				sb.append("</a>");
			}
			this.write(writer, sb.toString());
			return result;
		}

		if (type.equalsIgnoreCase("titlehistory")) {
			Object boardObj = this.getStack().findValue(this.boardValue);
			int boardType = 3;
			Board board = (Board) boardObj;
			boardType = board.getBoardType();
			Object forumCurrentPageObj = this.getStack().findValue(this.currentPageValue);
			int fcpage = 1;
			if (forumCurrentPageObj != null) {
				fcpage = ((Integer) forumCurrentPageObj).intValue();
			}

			String fcaction = "index";
			Object fcactionObj = this.getStack().findValue(this.currentActionValue);
			if (fcactionObj != null) {
				fcaction = (String) fcactionObj;
			}

			String tagId = "0";
			Object tagIdObj = this.getStack().findValue(this.tagIdValue);
			if (tagIdObj != null) {
				tagId = (String) tagIdObj;
			}

			if (boardType == 2) {
				if (board.getId().longValue() != f.getBoardID()) {
					sb.append("[");
					sb.append(f.getBoardName());
					sb.append("] ");
				}
			}
			if (!f.getTagID().equals("0") && tagId.equals("0")) {
				sb.append("[");
				sb.append(f.getTagName());
				sb.append("] ");
			}
			if (f.getPostType() != 0) {
				if (f.getPostType() == 1) {
					sb.append(messageSource.getMessage("post.firstpus", null, this.request.getLocale()));
					sb.append(" ");
					// sb.append("[原创] ");
				}
				if (f.getPostType() == 2) {
					sb.append(messageSource.getMessage("post.fw", null, this.request.getLocale()));
					sb.append(" ");
					// sb.append("[转载] ");
				}
			}
			if (f.getIsVote() == 1) {
				// sb.append("[投票] ");
				sb.append(messageSource.getMessage("post.vote.title", null, this.request.getLocale()));
				sb.append(" ");
			}
			if (f.getTitleColor() != 0) {
				sb.append("<a href=\"");
				if (Constant.USE_URL_REWRITE) {
					sb.append("read-history-" + f.getBoardID() + "-" + f.getMainID() + "-" + tagId + "-" + fcpage + "-"
							+ fcaction + "-1" + ".html");
				} else {
					sb.append(BBSCSUtil.getActionMappingURL("/read?action=history&id=" + f.getMainID() + "&bid="
							+ f.getBoardID() + "&fcpage=" + fcpage + "&fcaction=" + fcaction + "&tagId=" + tagId,
							request));
				}
				sb.append("\">");
				sb.append("<font color=\"");
				sb.append(Constant.TITLECOLOR[f.getTitleColor()]);
				sb.append("\"><strong>");

⌨️ 快捷键说明

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