1 20 package org.enhydra.barracuda.contrib.dbroggisch.examples.controller; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import javax.servlet.http.HttpServletRequest ; 25 import org.enhydra.barracuda.core.event.ApplicationGateway; 26 import org.enhydra.barracuda.core.event.DispatcherFactory; 27 import org.enhydra.barracuda.core.helper.servlet.RequestWrapper; 28 import org.enhydra.barracuda.core.helper.servlet.DefaultServletRequestWrapper; 29 import org.enhydra.barracuda.contrib.dbroggisch.page.PageDispatcherFactory; 30 import org.enhydra.barracuda.contrib.dbroggisch.page.RenderPageEventGateway; 31 import org.apache.log4j.Logger; 32 33 import org.enhydra.barracuda.contrib.dbroggisch.examples.controller.servlets.MyMultipartRequest; 34 35 36 public class DBRApplicationGateway extends ApplicationGateway { 37 38 private static final Logger logger = Logger.getLogger(DBRApplicationGateway.class.getName()); 39 40 public static boolean WRAPPER_INSTALLED = false; 41 42 public void initializeLocal() { 43 WRAPPER_INSTALLED = installWrapper(); 44 specifyEventGateways(new RenderPageEventGateway()); 45 46 } 47 48 private boolean installWrapper() { 49 String destDir = null; 50 File tempDir = (File )getServletConfig().getServletContext().getAttribute("javax.servlet.context.tempdir"); 51 if(tempDir.canWrite()) { 53 REQUEST_WRAPPER = new SampleRequestWrapper(tempDir.getAbsolutePath()); 54 return true; 55 } 56 return false; 57 } 58 59 public static class SampleRequestWrapper implements RequestWrapper { 60 String _destDir; 61 public SampleRequestWrapper(String destDir) { 62 _destDir = destDir; 63 } 64 65 public HttpServletRequest wrap(HttpServletRequest req) { 66 try { 70 return new DefaultServletRequestWrapper(new MyMultipartRequest(req, _destDir)); 71 } catch(IOException ex) { 72 return new DefaultServletRequestWrapper(req); 73 } 74 } 75 } 76 77 82 public DispatcherFactory getDispatcherFactory() { 83 return new PageDispatcherFactory(); 84 } 85 86 } 87 | Popular Tags |