forumjsp.java

来自「社区文章采用的是平板、树形自由选择的两种展示方式」· Java 代码 · 共 795 行 · 第 1/2 页

JAVA
795
字号
			if(!Validator.isEmpty(model)){
				if(!Utils.isSpider(request)){
					this.getTopicService().setTopicViewing(model);
				}
				if(act.equals("")){
					model.setViews(model.getViews()+1);
					try {
						this.getTopicService().updateViews(model.getTopicId());
					} catch (ClubException e) {
						logger.error(e.toString());
					} //更新浏览次数
					logger.debug("update views: " + model.getViews());
				}
				tv = new TopicView();
				BeanUtils.copyProperties(tv,model);
				BeanUtils.copyProperties(tv,model.getTContent());
				if(model.getForumId()!=forumId){
					HttpServletUtils.redirect(response,UrlUtils.getUrl(UrlUtils.TOPIC, tv, request));
					return null;
				}
				User user = this.getUserService().findById(tv.getUserId());
				if(user!=null){
					UserView userView = new UserView();
					BeanUtils.copyProperties(userView, user);
					tv.setUserView(userView);
				}else{
					tv.setUserView( new UserView());
				}
				request.setAttribute("topicId",tv.getTopicId());
				if(act.equals("edittopic")){
					if(tv.getIsDeleted()){
						HttpServletUtils.redirect(response,"main.jsp");
						return null;
					}
					TopicPostForm form = (TopicPostForm)request.getAttribute("TopicPostForm");
					if(!Validator.isEmpty(form)){
						BeanUtils.copyProperties(tv,form);
					}
					else{
						form = new TopicPostForm();
						BeanUtils.copyProperties(form,tv);
					}
					request.setAttribute("TopicPostForm",form);
				}
			}else{
				logger.debug("not find Topic topicId:"+topicId);
				HttpServletUtils.redirect(response,"404.html");
				return null;
			}
		}
		if(rv!=null){
			title = rv.getTitle();
			return rv;
		}
		else if(tv!=null){
			title = tv.getTitle();
			return tv;
		}else{
			return null;
		}
	}
	
	public List<TopicView> searchTopic(int page, int rows){
		if(Validator.isEmpty(title)){
			return null;
		}
		List<Topic> list = this.getTopicService().searchTopic(title, page, rows);
		if(!Validator.isEmpty(list)){
			return BeanUtils.<Topic,TopicView>copyList(list,BeanLocator.TOPICVIEW);
		}else{
			return null;
		}
	}
	
	public TopicView findTopicById(){
		int topicId = ParamUtils.getIntAuto(request,"topicId");
		//logger.debug("request.getAttribute(\"topicId\"):"+request.getAttribute("topicId"));
		Topic model = this.getTopicService().findById(topicId);
		TopicView view = null;
		if(!Validator.isEmpty(model)){
			view = new TopicView();
			BeanUtils.copyProperties(view,model);
		}		
		return view;
	}
	
	public List<ReplyView> findReplyAndContent(int topicId){
		TopicParameter param = new TopicParameter();
		param.setOrderBy((byte)0);
		param.setForumId(forumId);
		param.setTopicId(topicId);
		param.setPage(page);
		if(!Validator.isEmpty(this.getForumService().findById(forumId))){
			param.setRows(this.getForumService().findById(forumId).getReplyListNumber());
		}else{
			int rows = ParamUtils.getIntParameter(request,"rows");
			if(rows>100){
				rows = 100;
			}
			param.setRows(rows);
		}
		long total = this.getReplyService().countByParameter(param);
		this.setLastpage(PaginationHelper.getLastpage(total,param.getRows()));
		if(param.getPage()>this.getLastpage()){
			param.setPage(this.getLastpage());
		}
		List<Reply> mlist = this.getReplyService().findReplyAndContent(param);
		List<ReplyView> list = BeanUtils.<Reply,ReplyView>copyList(mlist,BeanLocator.REPLYVIEW);
		if(!Validator.isEmpty(list)){
			for(int i=0; i<list.size(); i++){
				ReplyView v = list.get(i);
				BeanUtils.copyProperties(v,mlist.get(i).getRContent());
				v.setStorey(this.getSotrey(param.getRows()));
				list.set(i,v);
			}
		}
		request.setAttribute("lpage", this.getLastpage());
		StringBuffer url = new StringBuffer();
		url.append("f");
		url.append(forumId);
		url.append("b");
		url.append(ParamUtils.getStringParameter(request, "better", "0"));
		url.append("l");
		url.append(ParamUtils.getStringParameter(request, "labelId", "0"));
		url.append("fp");
		url.append(ParamUtils.getStringParameter(request, "fpage", "1"));
		url.append("t");
		url.append(topicId);
		url.append("p");
		this.setPagination(PaginationHelper.getPagination(url.toString(), param.getPage(), param.getRows(), total, 5));
		/*
		url.append("?forumId=");
		url.append(forumId);
		url.append("&fpage=");
		url.append(fpage);
		url.append("&topicId=");
		url.append(topicId);
		url.append("&page=");
		this.setPagination(OutPrint.pagination(page, param.getRows(), total, url.toString(),5));
		*/
		return list;
	}
	
	public List<ReplyView> findReplyAndContent(){
		int topicId = ParamUtils.getIntAuto(request,"topicId");
		/*
		if(topicId==-1){
			topicId = TypeChange.objToInt(ParamUtils.getAttribute(request,"topicId"));
			logger.debug("getAttribute(\"topicId\"):"+request.getAttribute("topicId"));
		}
		*/
		return this.findReplyAndContent(topicId);
	}

	public List<ReplyView> findReplyByTopicId(int rows){
		//int topicId = ParamUtils.getIntAuto(request,"topicId");
		return this.findReplyByTopicId(ParamUtils.getIntAuto(request,"topicId"),rows);
	}		
	
	public List<ReplyView> findReplyByTopicId(){
		int rows = 30;
		if(!Validator.isEmpty(this.getForumService().findById(forumId))){
			rows = (this.getForumService().findById(forumId).getReplyListNumber());
		}else{
			rows = ParamUtils.getIntParameter(request,"rows");
			if(rows>100){
				rows = 100;
			}
		}
		return this.findReplyByTopicId(rows);
	}
	
	public List<ReplyView> findReplyByTopicId(int topicId, int rows){
		return this.findReplyByTopicId(topicId,page,rows);
	}
	
	public List<ReplyView> findReplyByTopicId(int topicId, int page, int rows){
		TopicParameter param = new TopicParameter();
		param.setTopicId(topicId);
		param.setPage(new Integer(page));
		param.setRows(new Integer(rows));
		param.setOrderBy(new Byte("1"));
		long total = this.getReplyService().countByParameter(param);
		this.setLastpage(PaginationHelper.getLastpage(total,param.getRows()));
		if(param.getPage()>this.getLastpage()){
			param.setPage(this.getLastpage());
		}
		List<Reply> mlist = this.getReplyService().findReplyByTopicId(param);
		List<ReplyView> vlist = null;
		int replyId = ParamUtils.getIntParameter(request, "replyId",0);
		if(!Validator.isEmpty(mlist)){
			vlist = new ArrayList<ReplyView>();
			for(Reply reply:mlist){
				ReplyView replyView = new ReplyView();
				BeanUtils.copyProperties(replyView, reply);
				vlist.add(replyView);
			}
		}
		/*
		StringBuffer url = new StringBuffer(request.getRequestURI());
		url.append("?forumId=");
		url.append(forumId);
		url.append("&fpage=");
		url.append(fpage);
		if(replyId==0){
			url.append("&topicId=");
			url.append(topicId);	
		}else{
			url.append("&replyId=");
			url.append(replyId);	
		}
		url.append("&page=");
		this.setPagination(OutPrint.pagination(page, param.getRows(), total, url.toString(),5));
		*/
		
		StringBuffer url = new StringBuffer();
		url.append("f");
		url.append(forumId);
		url.append("b");
		url.append(ParamUtils.getStringParameter(request, "better", "0"));
		url.append("l");
		url.append(ParamUtils.getStringParameter(request, "labelId", "0"));
		url.append("fp");
		url.append(ParamUtils.getStringParameter(request, "fpage", "1"));
		if(replyId==0){
			url.append("t");
			url.append(topicId);
		}else{
			url.append("r");
			url.append(replyId);
		}
		url.append("p");
		this.setPagination(PaginationHelper.getPagination(url.toString(), param.getPage(), param.getRows(), total, 5));
		
		return vlist;
	}
	
	public List<UserView> findUsersFromFavorite(){
		FavoriteParameter param = new FavoriteParameter();
		param.setForumId(forumId);
		List<User> mlist = this.getFavoriteForumService().findUser(param);
		param.setRows(200);
		return BeanUtils.<User,UserView>copyList(mlist,BeanLocator.USERVIEW);
	}
	
	public long countUsersFromFavorite(){
		FavoriteParameter param = new FavoriteParameter();
		param.setForumId(forumId);
		return this.getFavoriteForumService().countByParameter(param);
	}
	
	public List<TopicView> getViewingTopics(int rows){
		List<Topic> list = this.getTopicService().getViewingTopics();
		List<TopicView> vlist = null;
		if(!Validator.isEmpty(list)){
			vlist = new ArrayList<TopicView>();
			for(int i=0; i<list.size(); i++){
				if(i==rows){
					break;
				}
				TopicView view = new TopicView();
				BeanUtils.copyProperties(view, list.get(i));
				vlist.add(view);
			}
		}
		return vlist;
	}

	public String getForumStyle() {
		return forumStyle;
	}

	public String getThreadStyle() {
		return threadStyle;
	}


	public String getPagination() {
		return pagination;
	}

	public void setPagination(String pagination) {
		this.pagination = pagination;
	}

	private TopicService getTopicService() {
		return ServiceWrapper.<TopicService>getSingletonInstance(ServiceLocator.TOPIC);
	}
	
	private ForumService getForumService() {
		return ServiceWrapper.<ForumService>getSingletonInstance(ServiceLocator.FORUM);
	}

	private ForumTemplate getForumTemplate() {
		if(Validator.isEmpty(forumTemplate)){
			forumTemplate = new ForumResults();
		}
		return forumTemplate;
	}
	
	
	public int getForumId() {
		return forumId;
	}

	public void setForumId(int forumId) {
		this.forumId = forumId;
	}

	public GroupOfForumJsp getGroupOfForumJsp() {
		if(Validator.isEmpty(groupOfForumJsp)){
			groupOfForumJsp = new GroupOfForumJsp(request,response);
		}
		return groupOfForumJsp;
	}
	
	private ReplyService getReplyService() {
		return ServiceWrapper.<ReplyService>getSingletonInstance(ServiceLocator.REPLY);
	}

	private UserService getUserService() {
		return ServiceWrapper.<UserService>getSingletonInstance(ServiceLocator.USER);
	}
	
	private CountService getCountService() {
		return ServiceWrapper.<CountService>getSingletonInstance(ServiceLocator.COUNT);
	}
	
	private FavoriteForumService getFavoriteForumService() {
		return ServiceWrapper.<FavoriteForumService>getSingletonInstance(ServiceLocator.FAVORITEFORUM);
	}
	
	public ForumLabelService getForumLabelService()
	{
		return ServiceWrapper.<ForumLabelService>getSingletonInstance(ServiceLocator.FORUMLABEL);
	}
	
	public int getFpage() {
		return fpage;
	}

	public void setFpage(int fpage) {
		this.fpage = fpage;
	}

	public int getTopicId() {
		return ParamUtils.getIntAuto(request,"topicId");
	}

	public int getLastpage() {
		return lastpage;
	}

	public void setLastpage(int lastpage) {
		this.lastpage = lastpage;
	}
	
	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}
	
	public static void main(String args[]){
		/*
		Reply m = new Reply();
		ReplyView v = new ReplyView();
		m.setIsDeleted(true);
		BeanUtils.copyProperties(v,m);
		System.out.println(v.getIsDeleted());
		*/
		/*
		com.yeqiangwei.club.dao.hibernate.ConnectionManager.init();
		ForumJsp j = new ForumJsp(null,null);
		ModelsOfForumView m = j.getModelsOfForumView(28);
		System.out.println(m.getForumView().getForumName());
		System.out.println("================================");
		List list = m.getForumViews();
		for(int i=0; i<list.size(); i++){
			com.yeqiangwei.club.view.model.ForumView fm = (com.yeqiangwei.club.view.model.ForumView) list.get(i);
			System.out.println(fm.getForumName());
		}
		*/
		
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
}

⌨️ 快捷键说明

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