001: /*
002: ItsNat Java Web Application Framework
003: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
004: Author: Jose Maria Arranz Santamaria
005:
006: This program is free software: you can redistribute it and/or modify
007: it under the terms of the GNU Affero General Public License as published by
008: the Free Software Foundation, either version 3 of the License, or
009: (at your option) any later version. See the GNU Affero General Public
010: License for more details. See the copy of the GNU Affero General Public License
011: included in this program. If not, see <http://www.gnu.org/licenses/>.
012: */
013:
014: package org.itsnat.core.http;
015:
016: import java.io.IOException;
017: import javax.servlet.ServletConfig;
018: import javax.servlet.ServletException;
019: import javax.servlet.http.HttpServlet;
020: import javax.servlet.http.HttpServletRequest;
021: import javax.servlet.http.HttpServletResponse;
022: import org.itsnat.core.*;
023:
024: /**
025: * Simplifies the development of new ItsNat based servlets.
026: *
027: * <p>New servlets may inherit from this class and overload {@link #init(javax.servlet.ServletConfig config)}
028: * to setup the ItsNat infrastructure (default properties, register templates etc).</p>
029: *
030: * <p>This class creates an ItsNat servlet wrapping this servlet and forwards
031: * request/response calls to the ItsNat servlet, these are converted to ItsNat
032: * request/response calls.</p>
033: *
034: * @author Jose Maria Arranz Santamaria
035: */
036: public abstract class HttpServletWrapper extends HttpServlet {
037: protected ItsNatHttpServlet itsNatServlet;
038:
039: /**
040: * Creates a new instance of HttpServletWrapper
041: */
042: public HttpServletWrapper() {
043: }
044:
045: /**
046: * Returns the ItsNat servlet wrapping this servlet.
047: *
048: * @return the ItsNat servlet.
049: * @see ItsNatHttpServlet#getHttpServlet()
050: */
051: public ItsNatHttpServlet getItsNatHttpServlet() {
052: return itsNatServlet;
053: }
054:
055: /**
056: * Initializes the ItsNat servlet wrapping this servlet. Overload this method
057: * to initialize the ItsNat servlet (setup properties, register templates etc).
058: */
059: public void init(ServletConfig config) throws ServletException {
060: super .init(config);
061:
062: this .itsNatServlet = (ItsNatHttpServlet) ItsNat.get()
063: .createItsNatServlet(this );
064: }
065:
066: /**
067: * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods
068: * and forwards them to the {@link ItsNatHttpServlet}.
069: *
070: * @param request servlet request object.
071: * @param response servlet response object.
072: */
073: protected void processRequest(HttpServletRequest request,
074: HttpServletResponse response) throws ServletException,
075: IOException {
076: getItsNatHttpServlet().processRequest(request, response);
077: }
078:
079: // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
080: /**
081: * Handles the HTTP <code>GET</code> method.
082: *
083: * @param request servlet request
084: * @param response servlet response
085: */
086: protected void doGet(HttpServletRequest request,
087: HttpServletResponse response) throws ServletException,
088: IOException {
089: processRequest(request, response);
090: }
091:
092: /**
093: * Handles the HTTP <code>POST</code> method.
094: *
095: * @param request servlet request
096: * @param response servlet response
097: */
098: protected void doPost(HttpServletRequest request,
099: HttpServletResponse response) throws ServletException,
100: IOException {
101: processRequest(request, response);
102: }
103:
104: /**
105: * Returns a short description of the servlet.
106: */
107: public String getServletInfo() {
108: return "ItsNat Servlet";
109: }
110: // </editor-fold>
111: }
|