package com.mingsoft.servlet.admin.articletype;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

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

import net.sf.json.JSONArray;

import com.mingsoft.biz.IArticleTypeBiz;
import com.mingsoft.biz.impl.ArticleTypeBizImpl;
import com.mingsoft.constant.JspPage;
import com.mingsoft.entity.ArticleTypeTreeEntity;
import com.mingsoft.servlet.BaseServlet;
/**
 * 发送文章管理模块下拉框选项的JOSN
 * @author 成卫雄
 * QQ:330216230
 * 技术支持：景德镇铭飞科技
 * 官网：www.ming-soft.com
 */
public class TreeArticleServlet extends BaseServlet{

	private static final long serialVersionUID = 1L;

	@Override
	public void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doGet(request, response);
		doPost(request, response);
		if (request.getParameter("type")!=null && request.getParameter("type").equals("json")) {
			doPost(request, response);
		} else {
			request.getRequestDispatcher(JspPage.ARTICLETYPE_LIST).forward(request, response);
		}
	}

	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doPost(request, response);
		 IArticleTypeBiz artucleTypeBiz = new ArticleTypeBizImpl();
		 List<ArticleTypeTreeEntity> articleTypeTree = artucleTypeBiz.articleForList();
		 PrintWriter out = response.getWriter();
		 String str = JSONArray.fromObject(articleTypeTree).toString();
		 out.write(str);
		 out.close();
	}
}
