View Javadoc

1   /*
2    * $Id: StrutsMockServletContext.java 439747 2006-09-03 09:22:46Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.views.jsp;
19  
20  import java.io.InputStream;
21  import java.net.MalformedURLException;
22  import java.net.URL;
23  import java.util.Collections;
24  import java.util.Enumeration;
25  import java.util.HashMap;
26  import java.util.Map;
27  import java.util.Set;
28  
29  import javax.servlet.RequestDispatcher;
30  import javax.servlet.Servlet;
31  import javax.servlet.ServletContext;
32  import javax.servlet.ServletException;
33  
34  
35  /***
36   * StrutsMockServletContext
37   *
38   */
39  public class StrutsMockServletContext implements ServletContext {
40  
41      String realPath;
42      String servletInfo;
43      Map initParams = new HashMap();
44      Map attributes = new HashMap();
45      InputStream resourceAsStream;
46  
47      public void setInitParameter(String name, String value) {
48          initParams.put(name, value);
49      }
50  
51      public void setRealPath(String value) {
52          realPath = value;
53      }
54  
55      public String getRealPath(String string) {
56          return realPath;
57      }
58  
59      public ServletContext getContext(String s) {
60          return null;
61      }
62  
63      public int getMajorVersion() {
64          return 0;
65      }
66  
67      public int getMinorVersion() {
68          return 0;
69      }
70  
71      public String getMimeType(String s) {
72          return null;
73      }
74  
75      public Set getResourcePaths(String s) {
76          return null;
77      }
78  
79      public URL getResource(String s) throws MalformedURLException {
80          return null;
81      }
82  
83      public InputStream getResourceAsStream(String s) {
84      	if (resourceAsStream != null) {
85      		return resourceAsStream;
86      	}
87          return null;
88      }
89      
90      public void setResourceAsStream(InputStream is) {
91      	this.resourceAsStream = is;
92      }
93  
94      public RequestDispatcher getRequestDispatcher(String s) {
95          return null;
96      }
97  
98      public RequestDispatcher getNamedDispatcher(String s) {
99          return null;
100     }
101 
102     public Servlet getServlet(String s) throws ServletException {
103         return null;
104     }
105 
106     public Enumeration getServlets() {
107         return null;
108     }
109 
110     public Enumeration getServletNames() {
111         return null;
112     }
113 
114     public void log(String s) {
115     }
116 
117     public void log(Exception e, String s) {
118     }
119 
120     public void log(String s, Throwable throwable) {
121     }
122 
123     public String getServerInfo() {
124         return servletInfo;
125     }
126 
127     public String getInitParameter(String s) {
128         return (String) initParams.get(s);
129     }
130 
131     public Enumeration getInitParameterNames() {
132         return Collections.enumeration(initParams.keySet());
133     }
134 
135     public Object getAttribute(String s) {
136         return attributes.get(s);
137     }
138 
139     public Enumeration getAttributeNames() {
140         return Collections.enumeration(attributes.keySet());
141     }
142 
143     public void setAttribute(String s, Object o) {
144         attributes.put(s, o);
145     }
146 
147     public void removeAttribute(String s) {
148         attributes.remove(s);
149     }
150 
151     public String getServletContextName() {
152         return null;
153     }
154 
155     public void setServletInfo(String servletInfo) {
156         this.servletInfo = servletInfo;
157     }
158 }