001: /*
002: * $Id: StrutsMockServletContext.java 508916 2007-02-18 16:54:58Z tschneider $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.views.jsp;
022:
023: import java.io.InputStream;
024: import java.net.MalformedURLException;
025: import java.net.URL;
026: import java.util.Collections;
027: import java.util.Enumeration;
028: import java.util.HashMap;
029: import java.util.Map;
030: import java.util.Set;
031:
032: import javax.servlet.RequestDispatcher;
033: import javax.servlet.Servlet;
034: import javax.servlet.ServletContext;
035: import javax.servlet.ServletException;
036:
037: /**
038: * StrutsMockServletContext
039: *
040: */
041: public class StrutsMockServletContext implements ServletContext {
042:
043: String realPath;
044: String servletInfo;
045: String contextPath;
046: Map initParams = new HashMap();
047: Map attributes = new HashMap();
048: InputStream resourceAsStream;
049:
050: public void setInitParameter(String name, String value) {
051: initParams.put(name, value);
052: }
053:
054: public void setRealPath(String value) {
055: realPath = value;
056: }
057:
058: public String getRealPath(String string) {
059: return realPath;
060: }
061:
062: public ServletContext getContext(String s) {
063: return null;
064: }
065:
066: public int getMajorVersion() {
067: return 0;
068: }
069:
070: public int getMinorVersion() {
071: return 0;
072: }
073:
074: public String getMimeType(String s) {
075: return null;
076: }
077:
078: public Set getResourcePaths(String s) {
079: return null;
080: }
081:
082: public URL getResource(String s) throws MalformedURLException {
083: return null;
084: }
085:
086: public InputStream getResourceAsStream(String s) {
087: if (resourceAsStream != null) {
088: return resourceAsStream;
089: }
090: return null;
091: }
092:
093: public void setResourceAsStream(InputStream is) {
094: this .resourceAsStream = is;
095: }
096:
097: public RequestDispatcher getRequestDispatcher(String s) {
098: return null;
099: }
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:
162: public String getContextPath() {
163: return contextPath;
164: }
165:
166: public void setContextPath(String contextPath) {
167: this.contextPath = contextPath;
168: }
169: }
|