Package com.lgx8.gateway.servlet

Source Code of com.lgx8.gateway.servlet.GatewayBaseServlet

package com.lgx8.gateway.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.lgx8.common.entities.GatewayConfig;
import com.lgx8.common.entities.IPObject;
import com.lgx8.common.util.Constants;
import com.lgx8.gateway.entities.AreaCategory;
import com.lgx8.gateway.entities.Category;
import com.lgx8.gateway.service.IGatewayService;

import freemarker.template.Configuration;

/**
* Servlet implementation class GatewayBaseServlet
*/
public class GatewayBaseServlet extends HttpServlet {
 
  /**
   *
   */
  private static final long serialVersionUID = 7546683682294910918L;

  private Configuration configuration;
 
  public Map<Object, Object> root = new HashMap<Object, Object>();
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GatewayBaseServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
   
    /**
   * @see Servlet#init(ServletConfig)
   */
  @SuppressWarnings("unchecked")
  public void init(ServletConfig config) throws ServletException {
    super.init(config);
    configuration = new Configuration();
        configuration.setServletContextForTemplateLoading(getServletContext(), "ftl/gateway");
        configuration.setDefaultEncoding("UTF-8");
       
        GatewayConfig gatewayConfig = (GatewayConfig) getServletContext().getAttribute("gatewayConfig");
    root.put("gatewayConfig", gatewayConfig);
   
    List<AreaCategory> areaCategorys = (List<AreaCategory>) getServletContext().getAttribute("areaCategorys");
    root.put("areaCategorys", areaCategorys);
   
    List<Category> categorys = (List<Category>) getServletContext().getAttribute("categorys");
    root.put("categorys", categorys);
   
    root.put("searchURL", Constants.SEARCH_URL);
   
    ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    IGatewayService gatewayService = (IGatewayService) ac.getBean("gatewayService");
   
    List<IPObject> iPObjects = gatewayService.findAllIPObject();
   
    root.put("iPObjects",iPObjects);
  }
 
  /**
   * @see Servlet#destroy()
   */
  public void destroy() {
    super.destroy();
    configuration = null;
  }

  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request, response);
  }

  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  }

  public Configuration getConfiguration() {
    return configuration;
  }

  public void setConfiguration(Configuration configuration) {
    this.configuration = configuration;
  }

}
TOP

Related Classes of com.lgx8.gateway.servlet.GatewayBaseServlet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.