View Javadoc

    1   /*
    2    * $Id: StrutsMockHttpServletResponse.java 490622 2006-12-28 00:55:27Z mrdon $
    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.ByteArrayOutputStream;
    24  import java.io.IOException;
    25  import java.io.PrintWriter;
    26  import java.util.Locale;
    27
    28  import com.mockobjects.servlet.MockHttpServletResponse;
    29
    30
    31  /***
    32   * StrutsMockHttpServletResponse
    33   *
    34   */
    35  public class StrutsMockHttpServletResponse extends MockHttpServletResponse {
    36      private Locale locale;
    37      private PrintWriter writer;
    38      private int status;
    39      private String redirectURL;
    40
    41      public Locale getLocale() {
    42          return locale;
    43      }
    44
    45      public void setLocale(Locale locale) {
    46          this.locale = locale;
    47      }
    48
    49      public String getContentType() {
    50          return null;  //To change body of implemented methods use File | Settings | File Templates.
    51      }
    52
    53      public PrintWriter getWriter() throws IOException {
    54          if (writer == null)
    55              return new PrintWriter(new ByteArrayOutputStream());
    56          else
    57              return writer;
    58      }
    59
    60      public void setCharacterEncoding(String string) {
    61          //To change body of implemented methods use File | Settings | File Templates.
    62      }
    63
    64      public void setWriter(PrintWriter writer) {
    65          this.writer = writer;
    66      }
    67
    68      public String encodeURL(String s) {
    69          return s;
    70      }
    71
    72      public String encodeRedirectURL(String s) {
    73          return s;
    74      }
    75
    76      public String encodeUrl(String s) {
    77          return s;
    78      }
    79
    80      public void setStatus(int i) {
    81          this.status = i;
    82          super.setStatus(i);
    83      }
    84
    85      public int getStatus() {
    86          return status;
    87      }
    88
    89
    90      public String getRedirectURL() {
    91          return redirectURL;
    92      }
    93
    94      public void sendRedirect(String redirectURL) throws IOException {
    95          this.redirectURL = redirectURL;
    96          super.sendRedirect(redirectURL);
    97      }
    98  }