1 37 package net.sourceforge.cruisecontrol.mock; 38 39 import java.net.URL ; 40 import java.net.MalformedURLException ; 41 import java.io.InputStream ; 42 import java.io.File ; 43 import java.io.FileInputStream ; 44 import java.io.FileNotFoundException ; 45 import java.util.Collections ; 46 import java.util.Enumeration ; 47 import java.util.HashMap ; 48 import java.util.Map ; 49 50 import javax.servlet.ServletContext ; 51 import javax.servlet.RequestDispatcher ; 52 import javax.servlet.Servlet ; 53 import javax.servlet.ServletException ; 54 55 59 public class MockServletContext implements ServletContext { 60 private File baseResourceDir; 61 private Map initParams = new HashMap (); 62 63 public MockServletContext() { 64 } 65 66 public String getInitParameter(String name) { 67 return (String ) initParams.get(name); 68 } 69 70 public void setInitParameter(String name, String value) { 71 initParams.put(name, value); 72 } 73 74 public ServletContext getContext(String s) { 75 return null; 76 } 77 78 public int getMajorVersion() { 79 return 0; 80 } 81 82 public int getMinorVersion() { 83 return 0; 84 } 85 86 public String getMimeType(String s) { 87 return null; 88 } 89 90 public URL getResource(String s) throws MalformedURLException { 91 92 return new URL (baseResourceDir.toURL(), s); 94 } 95 96 public InputStream getResourceAsStream(String resourceName) { 97 try { 98 return new FileInputStream (new File (baseResourceDir, resourceName)); 99 } catch (FileNotFoundException e) { 100 return null; 101 } 102 } 103 104 public RequestDispatcher getRequestDispatcher(String s) { 105 return null; 106 } 107 108 public RequestDispatcher getNamedDispatcher(String s) { 109 return null; 110 } 111 112 public Servlet getServlet(String s) throws ServletException { 113 return null; 114 } 115 116 public Enumeration getServlets() { 117 return null; 118 } 119 120 public Enumeration getServletNames() { 121 return null; 122 } 123 124 public void log(String s) { 125 } 126 127 public void log(Exception e, String s) { 128 } 129 130 public void log(String s, Throwable throwable) { 131 } 132 133 public String getRealPath(String s) { 134 return null; 135 } 136 137 public String getServerInfo() { 138 return null; 139 } 140 141 public Enumeration getInitParameterNames() { 142 return Collections.enumeration(initParams.keySet()); 143 } 144 145 public Object getAttribute(String s) { 146 return null; 147 } 148 149 public Enumeration getAttributeNames() { 150 return null; 151 } 152 153 public void setAttribute(String s, Object o) { 154 } 155 156 public void removeAttribute(String s) { 157 } 158 159 163 public void setBaseResourceDir(File dir) { 164 baseResourceDir = dir; 165 } 166 } 167 | Popular Tags |