View Javadoc

    1   /*
    2    * $Id: StrutsMockServletContext.java 508916 2007-02-18 16:54:58Z tschneider $
    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      String contextPath;
    47      Map initParams = new HashMap();
    48      Map attributes = new HashMap();
    49      InputStream resourceAsStream;
    50
    51      public void setInitParameter(String name, String value) {
    52          initParams.put(name, value);
    53      }
    54
    55      public void setRealPath(String value) {
    56          realPath = value;
    57      }
    58
    59      public String getRealPath(String string) {
    60          return realPath;
    61      }
    62
    63      public ServletContext getContext(String s) {
    64          return null;
    65      }
    66
    67      public int getMajorVersion() {
    68          return 0;
    69      }
    70
    71      public int getMinorVersion() {
    72          return 0;
    73      }
    74
    75      public String getMimeType(String s) {
    76          return null;
    77      }
    78
    79      public Set getResourcePaths(String s) {
    80          return null;
    81      }
    82
    83      public URL getResource(String s) throws MalformedURLException {
    84          return null;
    85      }
    86
    87      public InputStream getResourceAsStream(String s) {
    88          if (resourceAsStream != null) {
    89              return resourceAsStream;
    90          }
    91          return null;
    92      }
    93
    94      public void setResourceAsStream(InputStream is) {
    95          this.resourceAsStream = is;
    96      }
    97
    98      public RequestDispatcher getRequestDispatcher(String s) {
    99          return null;
    100     }
    101
    102     public RequestDispatcher getNamedDispatcher(String s) {
    103         return null;
    104     }
    105
    106     public Servlet getServlet(String s) throws ServletException {
    107         return null;
    108     }
    109
    110     public Enumeration getServlets() {
    111         return null;
    112     }
    113
    114     public Enumeration getServletNames() {
    115         return null;
    116     }
    117
    118     public void log(String s) {
    119     }
    120
    121     public void log(Exception e, String s) {
    122     }
    123
    124     public void log(String s, Throwable throwable) {
    125     }
    126
    127     public String getServerInfo() {
    128         return servletInfo;
    129     }
    130
    131     public String getInitParameter(String s) {
    132         return (String) initParams.get(s);
    133     }
    134
    135     public Enumeration getInitParameterNames() {
    136         return Collections.enumeration(initParams.keySet());
    137     }
    138
    139     public Object getAttribute(String s) {
    140         return attributes.get(s);
    141     }
    142
    143     public Enumeration getAttributeNames() {
    144         return Collections.enumeration(attributes.keySet());
    145     }
    146
    147     public void setAttribute(String s, Object o) {
    148         attributes.put(s, o);
    149     }
    150
    151     public void removeAttribute(String s) {
    152         attributes.remove(s);
    153     }
    154
    155     public String getServletContextName() {
    156         return null;
    157     }
    158
    159     public void setServletInfo(String servletInfo) {
    160         this.servletInfo = servletInfo;
    161     }
    162
    163     public String getContextPath() {
    164         return contextPath;
    165     }
    166
    167     public void setContextPath(String contextPath) {
    168         this.contextPath = contextPath;
    169     }
    170 }