View Javadoc

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