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

📄 forumjsp.java

📁 野蔷薇论坛源码 java 自己看看吧。 学习用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* 
 * Created on 2007-2-17
 * Last modified on 2007-9-29
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.club.view.jsp;

import java.util.List;

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

import org.apache.log4j.Logger;

import com.yeqiangwei.club.param.CounterParameter;
import com.yeqiangwei.club.param.FavoriteParameter;
import com.yeqiangwei.club.param.TopicParameter;
import com.yeqiangwei.club.service.counter.CountService;
import com.yeqiangwei.club.service.forum.ForumService;
import com.yeqiangwei.club.service.topic.ReplyService;
import com.yeqiangwei.club.service.ServiceLocator;
import com.yeqiangwei.club.service.ServiceWrapper;
import com.yeqiangwei.club.service.topic.TopicService;
import com.yeqiangwei.club.service.user.UserLogin;
import com.yeqiangwei.club.service.user.UserService;
import com.yeqiangwei.club.service.util.BasicInfoService;
import com.yeqiangwei.club.service.model.CountersModel;
import com.yeqiangwei.club.service.model.ForumLabelModel;
import com.yeqiangwei.club.service.model.ForumModel;
import com.yeqiangwei.club.service.model.ModelsOfForum;
import com.yeqiangwei.club.service.model.ReplyModel;
import com.yeqiangwei.club.service.model.TopicModel;
import com.yeqiangwei.club.service.model.UserModel;
import com.yeqiangwei.club.service.forum.FavoriteForumService;
import com.yeqiangwei.club.service.forum.ForumLabelService;
import com.yeqiangwei.club.service.forum.ForumResults;
import com.yeqiangwei.club.service.forum.ForumTemplate;
import com.yeqiangwei.club.util.BeanLocator;
import com.yeqiangwei.club.util.BeanUtils;
import com.yeqiangwei.util.FormatDateTime;
import com.yeqiangwei.util.HttpServletUtils;
import com.yeqiangwei.util.IpUtils;
import com.yeqiangwei.util.Validator;
import com.yeqiangwei.club.controller.form.ForumEditForm;
import com.yeqiangwei.club.controller.form.ForumLabelForm;
import com.yeqiangwei.club.controller.form.TopicPostForm;
import com.yeqiangwei.club.exception.ClubException;
import com.yeqiangwei.club.view.model.CountersView;
import com.yeqiangwei.club.view.model.ForumView;
import com.yeqiangwei.club.view.model.ModelsOfForumView;
import com.yeqiangwei.club.view.model.ReplyView;
import com.yeqiangwei.club.view.model.TopicView;
import com.yeqiangwei.club.view.model.UserView;
import com.yeqiangwei.club.view.util.ModelsOfForumToView;
import com.yeqiangwei.club.view.util.UrlUtils;
import com.yeqiangwei.club.view.util.UserSetUtils;
import com.yeqiangwei.html.OutPrint;
import com.yeqiangwei.util.ParamUtils;

public class ForumJsp extends BaseJsp{
	
	private static final Logger logger = Logger.getLogger(ForumJsp.class);
	
	private ForumTemplate forumTemplate;
	
	private String pagination = "";
	
	private String forumStyle;
	
	private String threadStyle;
	
	private String title;
	
	private int storey = 0;
	
	private int forumId = 0;
	
	private int lastpage = 1; //帖子回复的最后一页
	
	private GroupOfForumJsp groupOfForumJsp;
	
	private int page = 1;
	
	private int fpage = 1;
	
	private int maxpage = 0;
	
	public String getIndentStr(int layer){
		StringBuffer sb = new StringBuffer("");
		for(int i=0; i<layer; i++){
    		sb.append("&nbsp;");
    	}
		return sb.toString();
	}

	public String topicflag(){
		StringBuffer sb = new StringBuffer();
		String url = (UrlUtils.getUrl(UrlUtils.TOPIC,ParamUtils.getIntAuto(request,"topicId"),0,request));
		sb.append("<a href=\"");
		sb.append(this.getUserService().getBasicInfo().getUrl());
		sb.append("\" target=\"_blank\">");
		sb.append(this.getUserService().getBasicInfo().getName());
		sb.append("</a>&nbsp;&nbsp;<a href=\"");
		sb.append(url);
		sb.append("\" target=\"_blank\">");
		sb.append(url);
		sb.append("</a>");
		return sb.toString();
	}

	public ForumJsp(HttpServletRequest request, HttpServletResponse response) {
		super(request, response);
		forumId = ParamUtils.getIntParameter(request,"forumId",0);
		page = ParamUtils.getIntParameter(request,"page",1);
		fpage = ParamUtils.getIntParameter(request,"fpage",1);
		lastpage = ParamUtils.getIntParameter(request,"lpage",1);
		maxpage = this.getUserService().getBasicInfo().getMaxpage();
		if(maxpage>0&&fpage>maxpage){
			fpage = maxpage;
			request.setAttribute("message","系统只提供最多"+maxpage+"页的文章列表,如果您需要找到更多内容请使用社区搜索功能!");
		}
	}
	
	public int getSotrey(int listnum){
		storey++;
		//int page = ParamUtils.getIntParameter(request,"page",1);
		if(storey==1&&page>1){
			storey = ((page-1)*listnum);
		}
		return storey;
	}
	
	/**
	 * 回复楼层
	 * @return
	 */
	public int getStorey(){
		return this.getStorey(request);
	}
	
	public int getStorey(HttpServletRequest request){
		int listnum = 0;
		ForumModel fmodel = this.getForumService().findById(forumId);
		if(!Validator.isEmpty(fmodel)){
			listnum = fmodel.getReplyListNumber(); 
		}
		return this.getSotrey(listnum);
	}

	public CountersView findCounter(){
		CounterParameter param = new CounterParameter();
		param.setForumId(forumId);
		param.setYmd(FormatDateTime.formatDateTimeToInt("yyyyMMdd"));
		CountersView view = new CountersView();
		CountersModel model = this.getCountService().findOnlyByParameter(param);
		if(!Validator.isEmpty(model)){
			BeanUtils.copyProperties(view,model);
		}
		return view;
	}
	
	public List<ForumView> findAll(){
		List<ForumModel> mlist = this.getForumTemplate().findAll();
		return BeanUtils.copyList(mlist, BeanLocator.FORUMVIEW);
	}
	
	public ForumLabelForm getForumLabelForm(){
		int id = ParamUtils.getIntParameter(request,"labelId");
		ForumLabelForm f = new ForumLabelForm();
		ForumLabelModel model = null;
		if(id>0){
			model = this.getForumLabelService().findById(id);
		}
		if(!Validator.isEmpty(model)){
			BeanUtils.copyProperties(f,model);
		}else{
			Object object = ParamUtils.getAttribute(request,"ForumLabelForm");
			if(!Validator.isEmpty(object)){
				f = (ForumLabelForm) object;
			}
		}
		return f;
	}
	
	public ForumEditForm getForumEditForm(){
		ForumEditForm f = new ForumEditForm();
		ForumModel model = null;
		if(forumId>0){
			model = this.getForumService().findById(forumId);
		}
		if(!Validator.isEmpty(model)){
			BeanUtils.copyProperties(f,model);
		}else{
			Object object = ParamUtils.getAttribute(request,"ForumEditForm");
			if(!Validator.isEmpty(object)){
				f = (ForumEditForm) object;
			}
		}
		return f;
	}
	
	public ForumView getForumView(){
		ForumView v = null;
		ForumModel m = this.getForumService().findById(forumId);
		if(!Validator.isEmpty(m)){
			v = new ForumView();
			BeanUtils.copyProperties(v,m);
		}
		return v;
	}
	
	private boolean cookieLabel(){
		boolean bea = false;
		StringBuffer sb = new StringBuffer();
		sb.append("f");
		sb.append(forumId);
		if(ParamUtils.getCookieValue(request,sb.toString(),null)==null){
			bea = true;
			ParamUtils.setCookieValue(response,sb.toString(),"1",0);
		}
		return bea;
	}
	
	public ModelsOfForumView getModelsOfForumView(){
		CountersModel counters = new CountersModel();
		counters.setHits(1);
		counters.setForumId(forumId);
		if(this.cookieLabel()){
			UserModel user = UserLogin.getUserModel(request);
			if(!Validator.isEmpty(user)){
				switch(user.getSex()){
					case 1:
					counters.setBoys(1);
					break;
					
					case 2:
					counters.setGirls(1);
					break;
					
					default:
					counters.setGirls(1);
				}
			}else{
				counters.setOthers(1);
			}
		}
		try {
			this.getCountService().doCount(counters);
		} catch (ClubException e) {
			logger.error(e.toString());
		}
		return this.getModelsOfForumView(forumId);
	}
	
	@SuppressWarnings("unchecked")
	public ModelsOfForumView getModelsOfForumView(int forumId){
		ModelsOfForumView modelsOfForumView = new ModelsOfForumView();
		ModelsOfForum modelsOfForum = this.getForumService().getModelsOfForum(forumId);			
		if(!Validator.isEmpty(modelsOfForum)){
			ModelsOfForumToView modelsOfForumToView = new ModelsOfForumToView();
			modelsOfForumView = modelsOfForumToView.toView(modelsOfForum);
			if(Validator.isEmpty(modelsOfForum.getForumModel())){
				logger.debug("未找到相关版面信息 forumId:"+forumId);
				HttpServletUtils.redirect(response,"404.html");
				return null;
			}
		}else{
			logger.debug("未找到相关版面 forumId:"+forumId);
			HttpServletUtils.redirect(response,"404.html");
			return null;
		}
		return modelsOfForumView;
	}
	
	public List<TopicView> findTopicByForumId(){
		int drows = 20;
		if(!Validator.isEmpty(this.getForumService().findById(forumId))){
			drows = this.getForumService().findById(forumId).getTopicListNumber(); //版面默认显示的文章数
		}
		int rows = ParamUtils.getIntParameter(request,"rows",drows);
		if(rows>100){
			rows = drows;
		}
		StringBuffer url = new StringBuffer();
		url.append("forum.jsp?forumId=");
		url.append(forumId);
		TopicParameter param = new TopicParameter();
		param.setIsDeleted(false);
		param.setForumId(forumId);
		param.setPage(fpage);
		param.setRows(rows);
		param.setOrderBy((byte)1);
		byte better = ParamUtils.getByteParameter(request,"better");
		int labelId = ParamUtils.getIntParameter(request,"labelId");
		if(better>0){
			param.setBetter(new Byte(better));
			url.append("&better=");
			url.append(better);
		}
		if(labelId>0){
			param.setLabelId(labelId);
			url.append("&labelId=");
			url.append(labelId);
		}
		List<TopicModel> list = this.getTopicService().findByParameter(param);
		long total = this.getTopicService().countByParameter(param);
		url.append("&fpage=");
		this.setPagination(OutPrint.pagination(fpage, rows, total, url.toString(),5, maxpage));
		if(!Validator.isEmpty(list)){
			return BeanUtils.<TopicModel,TopicView>copyList(list,BeanLocator.TOPICVIEW);
		}else{
			return null;
		}
	}
	
	public TopicPostForm getTopicPostForm(){
		TopicPostForm topicPostForm = (TopicPostForm) request.getAttribute("TopicPostForm");
		if(Validator.isEmpty(topicPostForm)){
			topicPostForm = new TopicPostForm();
		}
		UserModel userModel =  UserLogin.getUserModel(request);
		if(!Validator.isEmpty(userModel)){
			topicPostForm.setUserId(userModel.getUserId());
			topicPostForm.setUserName(userModel.getUserName());
			topicPostForm.setPassword(userModel.getPassword());
		}else{
			String eip = IpUtils.enAddr(request.getRemoteAddr());
			eip = eip.substring(eip.length()-6,eip.length());
			topicPostForm.setUserName("过客"+eip);
		}
		return topicPostForm;
	}
	
	/*
	public TopicModel getTopicModelById(){
		int topicId = ParamUtils.getIntAuto(request,"topicId");
		
	}
	*/
	
	public Object findTopicAndContentById(){

⌨️ 快捷键说明

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