1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.web

File XWikiServletResponse.java

 

Coverage histogram

../../../../img/srcFileCovDistChart5.png
74% of files have more coverage

Code metrics

6
57
40
1
329
237
43
0.75
1.42
40
1.08

Classes

Class Line # Actions
XWikiServletResponse 35 57 0% 43 60
0.4174757341.7%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.web;
21   
22    import java.io.IOException;
23    import java.io.PrintWriter;
24    import java.util.Collection;
25    import java.util.Locale;
26   
27    import javax.servlet.ServletOutputStream;
28    import javax.servlet.http.Cookie;
29    import javax.servlet.http.HttpServletResponse;
30   
31    import org.apache.commons.lang3.StringUtils;
32    import org.slf4j.Logger;
33    import org.slf4j.LoggerFactory;
34   
 
35    public class XWikiServletResponse implements XWikiResponse
36    {
37    private static final Logger LOGGER = LoggerFactory.getLogger(XWikiServletResponse.class);
38   
39    private HttpServletResponse response;
40   
41    /**
42    * The HTTP response status (200, 302, etc), see {@link #getStatus()}.
43    */
44    private int httpStatus;
45   
 
46  18576 toggle public XWikiServletResponse(HttpServletResponse response)
47    {
48  18574 this.response = response;
49    }
50   
51    /**
52    * Note that in Servlet 3.0 there's a better way to get the servlet response's code by calling
53    * <a href="http://download.oracle.com/javaee/6/api/javax/servlet/http/HttpServletResponse.html#getStatus%28%29">
54    * getStatus()</a>.
55    *
56    * @return the HTTP response status (200, 302, etc)
57    * @since 5.0M1
58    */
 
59  13846 toggle public int getStatus()
60    {
61  13846 return this.httpStatus;
62    }
63   
 
64  0 toggle @Override
65    public HttpServletResponse getHttpServletResponse()
66    {
67  0 return this.response;
68    }
69   
 
70  375 toggle @Override
71    public void sendRedirect(String redirect) throws IOException
72    {
73  375 if (StringUtils.isBlank(redirect)) {
74    // Nowhere to go to
75  0 return;
76    }
77  375 if (StringUtils.containsAny(redirect, '\r', '\n')) {
78  0 LOGGER.warn("Possible HTTP Response Splitting attack, attempting to redirect to [{}]", redirect);
79  0 return;
80    }
81  375 this.httpStatus = SC_FOUND;
82  375 this.response.sendRedirect(redirect);
83    }
84   
 
85  14332 toggle @Override
86    public void setContentType(String type)
87    {
88  14332 this.response.setContentType(type);
89    }
90   
 
91  0 toggle @Override
92    public void setBufferSize(int i)
93    {
94  0 this.response.setBufferSize(i);
95    }
96   
 
97  0 toggle @Override
98    public int getBufferSize()
99    {
100  0 return this.response.getBufferSize();
101    }
102   
 
103  0 toggle @Override
104    public void flushBuffer() throws IOException
105    {
106  0 this.response.flushBuffer();
107    }
108   
 
109  0 toggle @Override
110    public void resetBuffer()
111    {
112  0 this.response.resetBuffer();
113    }
114   
 
115  0 toggle @Override
116    public boolean isCommitted()
117    {
118  0 return this.response.isCommitted();
119    }
120   
 
121  0 toggle @Override
122    public void reset()
123    {
124  0 this.response.reset();
125    }
126   
 
127  9176 toggle @Override
128    public void setContentLength(int length)
129    {
130  9177 this.response.setContentLength(length);
131    }
132   
 
133  0 toggle @Override
134    public String getCharacterEncoding()
135    {
136  0 return this.response.getCharacterEncoding();
137    }
138   
 
139  15790 toggle @Override
140    public ServletOutputStream getOutputStream() throws IOException
141    {
142  15790 return this.response.getOutputStream();
143    }
144   
 
145  9640 toggle @Override
146    public PrintWriter getWriter() throws IOException
147    {
148  9642 return this.response.getWriter();
149    }
150   
 
151  1010 toggle @Override
152    public void setCharacterEncoding(String s)
153    {
154  1010 this.response.setCharacterEncoding(s);
155    }
156   
 
157  1061 toggle @Override
158    public void addCookie(Cookie cookie)
159    {
160  1061 this.response.addCookie(cookie);
161    }
162   
 
163  0 toggle public void addCookie(String cookieName, String cookieValue, int age)
164    {
165  0 Cookie cookie = new Cookie(cookieName, cookieValue);
166  0 cookie.setVersion(1);
167  0 cookie.setMaxAge(age);
168  0 this.response.addCookie(cookie);
169    }
170   
171    /**
172    * Remove a cookie.
173    *
174    * @param request The servlet request needed to find the cookie to remove
175    * @param cookieName The name of the cookie that must be removed.
176    */
 
177  0 toggle @Override
178    public void removeCookie(String cookieName, XWikiRequest request)
179    {
180  0 Cookie cookie = request.getCookie(cookieName);
181  0 if (cookie != null) {
182  0 cookie.setMaxAge(0);
183  0 cookie.setPath(cookie.getPath());
184  0 addCookie(cookie);
185    }
186    }
187   
 
188  11447 toggle @Override
189    public void setLocale(Locale locale)
190    {
191  11442 this.response.setLocale(locale);
192    }
193   
 
194  0 toggle @Override
195    public Locale getLocale()
196    {
197  0 return this.response.getLocale();
198    }
199   
 
200  9968 toggle @Override
201    public void setDateHeader(String name, long value)
202    {
203  9968 this.response.setDateHeader(name, value);
204    }
205   
 
206  0 toggle @Override
207    public void setIntHeader(String name, int value)
208    {
209  0 this.response.setIntHeader(name, value);
210    }
211   
 
212  21339 toggle @Override
213    public void setHeader(String name, String value)
214    {
215  21339 this.response.setHeader(name, value);
216    }
217   
 
218  289 toggle @Override
219    public void addHeader(String name, String value)
220    {
221  289 this.response.addHeader(name, value);
222    }
223   
 
224  0 toggle @Override
225    public void addDateHeader(String name, long value)
226    {
227  0 this.response.addDateHeader(name, value);
228    }
229   
 
230  0 toggle @Override
231    public void addIntHeader(String name, int value)
232    {
233  0 this.response.addIntHeader(name, value);
234    }
235   
 
236  1105 toggle @Override
237    public void setStatus(int i)
238    {
239  1106 this.response.setStatus(i);
240  1101 this.httpStatus = i;
241    }
242   
243    /**
244    * @deprecated
245    */
 
246  2 toggle @Override
247    @Deprecated
248    public void setStatus(int i, String s)
249    {
250  2 this.response.setStatus(i, s);
251  2 this.httpStatus = i;
252    }
253   
 
254  5 toggle @Override
255    public boolean containsHeader(String name)
256    {
257  5 return this.response.containsHeader(name);
258    }
259   
 
260  142285 toggle @Override
261    public String encodeURL(String s)
262    {
263  142280 return this.response.encodeURL(s);
264    }
265   
 
266  345 toggle @Override
267    public String encodeRedirectURL(String s)
268    {
269  345 return this.response.encodeRedirectURL(s);
270    }
271   
272    /**
273    * @deprecated
274    */
 
275  0 toggle @Override
276    @Deprecated
277    public String encodeUrl(String s)
278    {
279  0 return this.response.encodeUrl(s);
280    }
281   
282    /**
283    * @deprecated
284    */
 
285  0 toggle @Override
286    @Deprecated
287    public String encodeRedirectUrl(String s)
288    {
289  0 return this.response.encodeRedirectUrl(s);
290    }
291   
 
292  0 toggle @Override
293    public void sendError(int i, String s) throws IOException
294    {
295  0 this.httpStatus = i;
296  0 this.response.sendError(i, s);
297    }
298   
 
299  0 toggle @Override
300    public void sendError(int i) throws IOException
301    {
302  0 this.httpStatus = i;
303  0 this.response.sendError(i);
304    }
305   
 
306  0 toggle @Override
307    public String getContentType()
308    {
309  0 return this.response.getContentType();
310    }
311   
 
312  0 toggle @Override
313    public String getHeader(String s)
314    {
315  0 return this.response.getHeader(s);
316    }
317   
 
318  0 toggle @Override
319    public Collection<String> getHeaders(String s)
320    {
321  0 return this.response.getHeaders(s);
322    }
323   
 
324  0 toggle @Override
325    public Collection<String> getHeaderNames()
326    {
327  0 return this.response.getHeaderNames();
328    }
329    }