1 20 package org.enhydra.barracuda.core.comp.helper; 21 22 import java.io.*; 23 import java.util.*; 24 import javax.servlet.*; 25 import javax.servlet.http.*; 26 27 import org.apache.log4j.*; 28 29 34 public class FormGateway extends HttpServlet { 35 36 protected static final Logger logger = Logger.getLogger(FormGateway.class.getName()); 38 39 public static String FORM_EXT = ".form_forward"; 42 public static String FORM_TARGET = "ft::"; 43 44 53 public void handleDefault(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 54 55 Enumeration enum = req.getParameterNames(); 58 int matches = 0; 59 Servlet servlet = null; 60 String target = null; 61 if (logger.isDebugEnabled()) logger.debug("Looking for target parameters"); 62 while (enum.hasMoreElements()) { 63 String key = (String) enum.nextElement(); 64 String val = (String) req.getParameter(key); 65 if (logger.isDebugEnabled()) logger.debug("key:"+key+" val:"+val); 66 67 if (key.startsWith(FORM_TARGET)) { 68 if (logger.isDebugEnabled()) logger.debug("(form target match)"); 69 target = key.substring(FORM_TARGET.length()); 70 matches++; 71 } 72 } 73 75 if (matches!=1) throw new ServletException ("Unable to determine destination handler"); 80 else { 81 RequestDispatcher rd = req.getRequestDispatcher(target); 83 if (logger.isDebugEnabled()) logger.debug("Redirecting to url:"+target); 84 if (rd!=null) { 85 rd.forward(req, resp); 86 } else { 87 throw new ServletException ("Unable to locate RequestDispatcher"); 88 } 89 } 90 } 91 92 93 94 95 104 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 105 handleDefault(req, resp); 106 } 107 108 116 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 117 handleDefault(req, resp); 118 } 119 120 128 protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 129 handleDefault(req, resp); 130 } 131 132 140 protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 141 handleDefault(req, resp); 142 } 143 144 152 protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 153 handleDefault(req, resp); 154 } 155 156 164 protected void doTrace(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 165 handleDefault(req, resp); 166 } 167 } 168 | Popular Tags |