1 17 package servletunit.struts; 18 19 import org.apache.cactus.server.ServletContextWrapper; 20 import servletunit.RequestDispatcherSimulator; 21 22 import javax.servlet.RequestDispatcher ; 23 import javax.servlet.ServletContext ; 24 import java.net.URL ; 25 import java.net.MalformedURLException ; 26 import java.io.File ; 27 import java.io.InputStream ; 28 import java.io.FileInputStream ; 29 import java.io.FileNotFoundException ; 30 31 39 public class StrutsServletContextWrapper extends ServletContextWrapper { 40 41 boolean processRequest = false; 42 private String dispatchedResource; 43 44 public StrutsServletContextWrapper(ServletContext context) { 45 super(context); 46 } 47 48 public void setProcessRequest(boolean flag) { 49 this.processRequest = flag; 50 } 51 52 public RequestDispatcher getRequestDispatcher(String path) { 53 dispatchedResource = path; 54 if (!processRequest) 55 return new RequestDispatcherSimulator(path); 56 else 57 return super.getRequestDispatcher(path); 58 } 59 60 public String getForward() { 61 return dispatchedResource; 62 } 63 64 70 public URL getResource(String pathname) throws MalformedURLException { 71 File file = new File (pathname); 72 if (file.exists()) 73 return file.toURL(); 74 else 75 return super.getResource(pathname); 76 } 77 78 84 public InputStream getResourceAsStream(String pathname) { 85 File file = new File (pathname); 86 if (file.exists()) 87 try { 88 return new FileInputStream (file); 89 } catch (FileNotFoundException e) { 90 return super.getResourceAsStream(pathname); 91 } 92 else 93 return super.getResourceAsStream(pathname); 94 } 95 96 } 97 98 | Popular Tags |