1 64 65 package com.jcorporate.expresso.core.servlet.viewhandler; 66 67 import com.jcorporate.expresso.core.ExpressoConstants; 68 import com.jcorporate.expresso.core.controller.ControllerException; 69 import com.jcorporate.expresso.core.controller.ControllerResponse; 70 import com.jcorporate.expresso.core.controller.NonHandleableException; 71 import com.jcorporate.expresso.core.servlet.DBServlet; 72 import org.apache.log4j.Logger; 73 74 import javax.servlet.ServletException ; 75 import javax.servlet.http.HttpServletRequest ; 76 import javax.servlet.http.HttpServletResponse ; 77 import java.io.IOException ; 78 79 80 public abstract class ViewHandler 81 extends DBServlet { 82 private static Logger log = Logger.getLogger(ViewHandler.class); 83 84 public ViewHandler() { 85 } 86 87 90 public abstract void handleView(ControllerResponse con, 91 HttpServletRequest req, 92 HttpServletResponse res) 93 throws ServletException , IOException , 94 ControllerException, 95 NonHandleableException; 96 97 98 110 public void doGet(HttpServletRequest request, HttpServletResponse response) 111 throws ServletException , IOException { 112 super.doGet(request, response); 113 log.debug("ViewHandler Begins in Get method"); 114 process(request, response); 115 } 116 117 118 131 public void doPost(HttpServletRequest req, HttpServletResponse res) 132 throws ServletException , IOException { 133 super.doPost(req, res); 134 log.debug("ViewHandler Begins in Post method"); 135 process(req, res); 136 } 137 138 139 public String getTitle() { 140 return ("View Handler Servlet"); 141 } 142 143 154 public void process(HttpServletRequest request, 155 HttpServletResponse response) 156 throws ServletException , IOException { 157 ControllerResponse res = (ControllerResponse) request.getAttribute(ExpressoConstants.CONTROLLER_RESPONSE_KEY); 158 159 if (res == null) { 160 throw new ServletException ("No Controller Response found in request"); 161 } 162 try { 163 handleView(res, request, response); 164 } catch (ControllerException ce) { 165 throw new ServletException (ce); 166 } catch (NonHandleableException ce) { 167 throw new ServletException (ce); 168 } 169 } 170 } | Popular Tags |