View Javadoc
1   /*
2    * Copyright (c) 2002-2022, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.pluginwizard.web;
35  
36  import java.io.IOException;
37  import java.io.PrintWriter;
38  import java.util.ArrayList;
39  import java.util.Collection;
40  import java.util.List;
41  
42  import java.util.Locale;
43  
44  import javax.servlet.ServletOutputStream;
45  import javax.servlet.http.Cookie;
46  import javax.servlet.http.HttpServletResponse;
47  
48  /**
49   *
50   * @author levy
51   */
52  public class MokeHttpServletResponse implements HttpServletResponse
53  {
54  
55      private int _status;
56      private long contentLength;
57  
58      @Override
59      public void addCookie( Cookie cookie )
60      {
61      }
62  
63      @Override
64      public boolean containsHeader( String string )
65      {
66          return true;
67      }
68  
69      @Override
70      public String encodeURL( String string )
71      {
72          return string;
73      }
74  
75      @Override
76      public String encodeRedirectURL( String string )
77      {
78          return string;
79      }
80  
81      @Override
82      public String encodeUrl( String string )
83      {
84          return string;
85      }
86  
87      @Override
88      public String encodeRedirectUrl( String string )
89      {
90          return string;
91      }
92  
93      @Override
94      public void sendError( int i, String string ) throws IOException
95      {
96      }
97  
98      @Override
99      public void sendError( int i ) throws IOException
100     {
101     }
102 
103     @Override
104     public void sendRedirect( String string ) throws IOException
105     {
106     }
107 
108     @Override
109     public void setDateHeader( String string, long l )
110     {
111     }
112 
113     @Override
114     public void addDateHeader( String string, long l )
115     {
116     }
117 
118     @Override
119     public void setHeader( String string, String string1 )
120     {
121     }
122 
123     @Override
124     public void addHeader( String string, String string1 )
125     {
126     }
127 
128     @Override
129     public void setIntHeader( String string, int i )
130     {
131     }
132 
133     @Override
134     public void addIntHeader( String string, int i )
135     {
136     }
137 
138     @Override
139     public void setStatus( int status )
140     {
141         if ( !this.isCommitted( ) )
142         {
143             this._status = status;
144         }
145     }
146 
147     @Override
148     public void setStatus( int status, String string )
149     {
150         setStatus( status );
151     }
152 
153     @Override
154     public String getCharacterEncoding( )
155     {
156         return "UTF-8";
157     }
158 
159     @Override
160     public String getContentType( )
161     {
162         return "text";
163     }
164 
165     @Override
166     public ServletOutputStream getOutputStream( ) throws IOException
167     {
168         return null;
169     }
170 
171     @Override
172     public PrintWriter getWriter( ) throws IOException
173     {
174         throw new UnsupportedOperationException( "Not supported yet." ); // To change body of generated methods, choose Tools | Templates.
175     }
176 
177     @Override
178     public void setCharacterEncoding( String string )
179     {
180     }
181 
182     @Override
183     public void setContentLength( int i )
184     {
185     }
186 
187     @Override
188     public void setContentType( String string )
189     {
190     }
191 
192     @Override
193     public void setBufferSize( int i )
194     {
195     }
196 
197     @Override
198     public int getBufferSize( )
199     {
200         return 1024;
201     }
202 
203     @Override
204     public void flushBuffer( ) throws IOException
205     {
206     }
207 
208     @Override
209     public void resetBuffer( )
210     {
211     }
212 
213     @Override
214     public boolean isCommitted( )
215     {
216         return true;
217     }
218 
219     @Override
220     public void reset( )
221     {
222     }
223 
224     @Override
225     public void setLocale( Locale locale )
226     {
227     }
228 
229     @Override
230     public Locale getLocale( )
231     {
232         return Locale.getDefault( );
233     }
234 
235     @Override
236     public int getStatus( )
237     {
238         return 200;
239     }
240 
241     @Override
242     public String getHeader( String string )
243     {
244         return "mock";
245     }
246 
247     @Override
248     public Collection<String> getHeaders( String string )
249     {
250         List<String> listHeaders = new ArrayList<String>( );
251         listHeaders.add( "mock" );
252 
253         return listHeaders;
254     }
255 
256     @Override
257     public Collection<String> getHeaderNames( )
258     {
259         List<String> listHeaders = new ArrayList<String>( );
260         listHeaders.add( "mock" );
261 
262         return listHeaders;
263     }
264 
265     @Override
266     public void setContentLengthLong( long contentLength )
267     {
268         this.contentLength = contentLength;
269         // doAddHeaderValue(HttpHeaders.CONTENT_LENGTH, contentLength, true);
270     }
271 
272 }