package com.ntsky.bbs.web.webwork.action.topic;

import java.util.List;
import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.opensymphony.xwork.ModelDriven;

import com.ntsky.framework.util.HttpUtil;
import com.ntsky.framework.util.DateUtil;
import com.ntsky.framework.util.StringUtil;
import com.ntsky.framework.util.lumaqq.IPSeeker;

import com.ntsky.bbs.Symbols;
import com.ntsky.bbs.domain.Forum;
import com.ntsky.bbs.domain.Poll;
import com.ntsky.bbs.domain.Topic;
import com.ntsky.bbs.exception.ActionException;
import com.ntsky.bbs.exception.ServiceException;
import com.ntsky.bbs.util.config.SystemConfig;
import com.ntsky.bbs.util.memory.ForumSingleton;
import com.ntsky.bbs.util.page.Pagination;
import com.ntsky.bbs.util.page.QueryResult;

/**
 * 创建主题信息Action
 *  
 * @author ntsky
 * @link www.ntsky.com
 * 
 * @version $Revision: 1.9 $ $Date: 2007/04/05 18:10:12 $
 */
public class ViewTopicAction extends TopicActionSupport {

	private int topicId;
	public void setTopicId(int topicId){
		this.topicId = topicId;
	}
	
	private Forum forum;
	public Forum getForum(){
		return this.forum;
	}
	
	/**
	 * 主题数据
	 */
	private Topic topic;
	public Topic getTopic(){
		return this.topic;
	}
	
	// 投票
	private Poll poll;
	public Poll getPoll(){
		return this.poll;
	}
	
	/**
	 * 查询主题信息
	 * 
	 * @return String 执行信息
	 */
	public String execute() throws Exception {
		if(logger.isInfoEnabled()){
			logger.info("查询主题 ['"+topicId+"'] 的信息.");
		}
		// ---------- 权限 ------------
		if(super.isAccess("canViewTopic")==0){
			return NO_PERMISSION;
		}
		
		try{
			QueryResult queryResult = topicService.viewTopic(topicId,new Pagination(getPaginationStart(),SystemConfig.getInstance().getIntPropertyValue(Symbols.PAGINATION,Symbols.PAGINATION_POST)));
			
			// 贴子
			posts = queryResult.getItems();
			// 分页
			setPagination(queryResult.getPagination());
			// 主题
			topic = topicService.getTopic(topicId);
			
			if(topic.getIsVote()==1){
				poll = pollService.findPoll(topicId);
			}
			
			// 论坛
			forum = ForumSingleton.getInstance().getForum(topic.getForumId());
		}
		catch(ServiceException se){
			throw new ActionException(se);
		}
	    
	    return SUCCESS;
    }

}
