1 16 package org.apache.myfaces.context.servlet; 17 18 import org.apache.myfaces.util.IteratorEnumeration; 19 20 import org.apache.commons.logging.Log; 21 import org.apache.commons.logging.LogFactory; 22 23 import javax.servlet.RequestDispatcher ; 24 import javax.servlet.Servlet ; 25 import javax.servlet.ServletContext ; 26 import javax.servlet.ServletException ; 27 import java.io.InputStream ; 28 import java.net.MalformedURLException ; 29 import java.net.URL ; 30 import java.util.*; 31 32 38 public class ServletContextMockImpl 39 implements ServletContext 40 { 41 private static final Log log = LogFactory.getLog(ServletContextMockImpl.class); 42 43 private Map _attributes = new HashMap(); 44 private Map _initParameters = new HashMap(); 45 private Map _resourceMap = new HashMap(); 46 47 48 public ServletContext getContext(String s) 49 { 50 throw new UnsupportedOperationException (); 51 } 52 53 public int getMajorVersion() 54 { 55 throw new UnsupportedOperationException (); 56 } 57 58 public int getMinorVersion() 59 { 60 throw new UnsupportedOperationException (); 61 } 62 63 public String getMimeType(String s) 64 { 65 throw new UnsupportedOperationException (); 66 } 67 68 public Set getResourcePaths(String s) 69 { 70 80 return Collections.EMPTY_SET; 81 } 82 83 public URL getResource(String s) throws MalformedURLException 84 { 85 String path = (String )_resourceMap.get(s); 86 if (path != null) 87 { 88 return Thread.currentThread().getContextClassLoader() 89 .getResource(path); 90 } 91 else 92 { 93 log.warn("Resource '" + s + "' cannot be resolved."); 94 return null; 95 } 96 } 97 98 public InputStream getResourceAsStream(String s) 99 { 100 String path = (String )_resourceMap.get(s); 101 if (path != null) 102 { 103 return Thread.currentThread().getContextClassLoader() 104 .getResourceAsStream(path); 105 } 106 else 107 { 108 log.warn("Resource '" + s + "' cannot be resolved."); 109 return null; 110 } 111 } 112 113 public RequestDispatcher getRequestDispatcher(String s) 114 { 115 throw new UnsupportedOperationException (); 116 } 117 118 public RequestDispatcher getNamedDispatcher(String s) 119 { 120 throw new UnsupportedOperationException (); 121 } 122 123 public Servlet getServlet(String s) throws ServletException 124 { 125 throw new UnsupportedOperationException (); 126 } 127 128 public Enumeration getServlets() 129 { 130 throw new UnsupportedOperationException (); 131 } 132 133 public Enumeration getServletNames() 134 { 135 throw new UnsupportedOperationException (); 136 } 137 138 public void log(String s) 139 { 140 throw new UnsupportedOperationException (); 141 } 142 143 144 public void log(Exception exception, String s) 145 { 146 throw new UnsupportedOperationException (); 147 } 148 149 public void log(String s, Throwable throwable) 150 { 151 throw new UnsupportedOperationException (); 152 } 153 154 public String getRealPath(String s) 155 { 156 return "/junit_dummy_real_path"; 157 } 158 159 public String getServerInfo() 160 { 161 throw new UnsupportedOperationException (); 162 } 163 164 public String getInitParameter(String s) 165 { 166 return (String ) _initParameters.get(s); 167 } 168 169 public Enumeration getInitParameterNames() 170 { 171 return new IteratorEnumeration(_initParameters.keySet().iterator()); 172 } 173 174 public Object getAttribute(String s) 175 { 176 return _attributes.get(s); 177 } 178 179 public Enumeration getAttributeNames() 180 { 181 return new IteratorEnumeration(_attributes.keySet().iterator()); 182 } 183 184 public void setAttribute(String s, Object obj) 185 { 186 _attributes.put(s, obj); 187 } 188 189 public void removeAttribute(String s) 190 { 191 _attributes.remove(s); 192 } 193 194 public String getServletContextName() 195 { 196 throw new UnsupportedOperationException (); 197 } 198 199 200 202 public void addResource(String webPath, String classPath) 203 { 204 _resourceMap.put(webPath, classPath); 205 } 206 207 208 } 209 | Popular Tags |