1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.web

File XWikiServletResponse.java

 

Coverage histogram

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

Code metrics

6
52
40
1
312
232
43
0.83
1.3
40
1.08

Classes

Class Line # Actions
XWikiServletResponse 35 52 0% 43 52
0.4693877746.9%
 

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  181380 toggle public XWikiServletResponse(HttpServletResponse response)
42    {
43  181425 this.response = response;
44    }
45   
 
46  63351 toggle @Override
47    public int getStatus()
48    {
49  63346 return this.response.getStatus();
50    }
51   
 
52  0 toggle @Override
53    public HttpServletResponse getHttpServletResponse()
54    {
55  0 return this.response;
56    }
57   
 
58  1615 toggle @Override
59    public void sendRedirect(String redirect) throws IOException
60    {
61  1615 if (StringUtils.isBlank(redirect)) {
62    // Nowhere to go to
63  10 return;
64    }
65  1605 if (StringUtils.containsAny(redirect, '\r', '\n')) {
66  0 LOGGER.warn("Possible HTTP Response Splitting attack, attempting to redirect to [{}]", redirect);
67  0 return;
68    }
69  1605 this.response.sendRedirect(redirect);
70    }
71   
 
72  59904 toggle @Override
73    public void setContentType(String type)
74    {
75  59915 this.response.setContentType(type);
76    }
77   
 
78  0 toggle @Override
79    public void setBufferSize(int i)
80    {
81  0 this.response.setBufferSize(i);
82    }
83   
 
84  0 toggle @Override
85    public int getBufferSize()
86    {
87  0 return this.response.getBufferSize();
88    }
89   
 
90  3432 toggle @Override
91    public void flushBuffer() throws IOException
92    {
93  3432 this.response.flushBuffer();
94    }
95   
 
96  0 toggle @Override
97    public void resetBuffer()
98    {
99  0 this.response.resetBuffer();
100    }
101   
 
102  0 toggle @Override
103    public boolean isCommitted()
104    {
105  0 return this.response.isCommitted();
106    }
107   
 
108  0 toggle @Override
109    public void reset()
110    {
111  0 this.response.reset();
112    }
113   
 
114  38954 toggle @Override
115    public void setContentLength(int length)
116    {
117  38958 this.response.setContentLength(length);
118    }
119   
 
120  0 toggle @Override
121    public String getCharacterEncoding()
122    {
123  0 return this.response.getCharacterEncoding();
124    }
125   
 
126  70516 toggle @Override
127    public ServletOutputStream getOutputStream() throws IOException
128    {
129  70518 return this.response.getOutputStream();
130    }
131   
 
132  47437 toggle @Override
133    public PrintWriter getWriter() throws IOException
134    {
135  47447 return this.response.getWriter();
136    }
137   
 
138  4620 toggle @Override
139    public void setCharacterEncoding(String s)
140    {
141  4620 this.response.setCharacterEncoding(s);
142    }
143   
 
144  23551 toggle @Override
145    public void addCookie(Cookie cookie)
146    {
147  23553 this.response.addCookie(cookie);
148    }
149   
 
150  0 toggle public void addCookie(String cookieName, String cookieValue, int age)
151    {
152  0 Cookie cookie = new Cookie(cookieName, cookieValue);
153  0 cookie.setVersion(1);
154  0 cookie.setMaxAge(age);
155  0 this.response.addCookie(cookie);
156    }
157   
158    /**
159    * Remove a cookie.
160    *
161    * @param request The servlet request needed to find the cookie to remove
162    * @param cookieName The name of the cookie that must be removed.
163    */
 
164  0 toggle @Override
165    public void removeCookie(String cookieName, XWikiRequest request)
166    {
167  0 Cookie cookie = request.getCookie(cookieName);
168  0 if (cookie != null) {
169  0 cookie.setMaxAge(0);
170  0 cookie.setPath(cookie.getPath());
171  0 addCookie(cookie);
172    }
173    }
174   
 
175  42990 toggle @Override
176    public void setLocale(Locale locale)
177    {
178  43006 this.response.setLocale(locale);
179    }
180   
 
181  0 toggle @Override
182    public Locale getLocale()
183    {
184  0 return this.response.getLocale();
185    }
186   
 
187  41201 toggle @Override
188    public void setDateHeader(String name, long value)
189    {
190  41204 this.response.setDateHeader(name, value);
191    }
192   
 
193  0 toggle @Override
194    public void setIntHeader(String name, int value)
195    {
196  0 this.response.setIntHeader(name, value);
197    }
198   
 
199  89383 toggle @Override
200    public void setHeader(String name, String value)
201    {
202  89388 this.response.setHeader(name, value);
203    }
204   
 
205  946 toggle @Override
206    public void addHeader(String name, String value)
207    {
208  949 this.response.addHeader(name, value);
209    }
210   
 
211  0 toggle @Override
212    public void addDateHeader(String name, long value)
213    {
214  0 this.response.addDateHeader(name, value);
215    }
216   
 
217  0 toggle @Override
218    public void addIntHeader(String name, int value)
219    {
220  0 this.response.addIntHeader(name, value);
221    }
222   
 
223  8459 toggle @Override
224    public void setStatus(int i)
225    {
226  8459 this.response.setStatus(i);
227    }
228   
229    /**
230    * @deprecated
231    */
 
232  10 toggle @Override
233    @Deprecated
234    public void setStatus(int i, String s)
235    {
236  10 this.response.setStatus(i, s);
237    }
238   
 
239  20 toggle @Override
240    public boolean containsHeader(String name)
241    {
242  20 return this.response.containsHeader(name);
243    }
244   
 
245  2750267 toggle @Override
246    public String encodeURL(String s)
247    {
248  2750463 return this.response.encodeURL(s);
249    }
250   
 
251  1306 toggle @Override
252    public String encodeRedirectURL(String s)
253    {
254  1306 return this.response.encodeRedirectURL(s);
255    }
256   
257    /**
258    * @deprecated
259    */
 
260  0 toggle @Override
261    @Deprecated
262    public String encodeUrl(String s)
263    {
264  0 return this.response.encodeUrl(s);
265    }
266   
267    /**
268    * @deprecated
269    */
 
270  0 toggle @Override
271    @Deprecated
272    public String encodeRedirectUrl(String s)
273    {
274  0 return this.response.encodeRedirectUrl(s);
275    }
276   
 
277  0 toggle @Override
278    public void sendError(int i, String s) throws IOException
279    {
280  0 this.response.sendError(i, s);
281    }
282   
 
283  5 toggle @Override
284    public void sendError(int i) throws IOException
285    {
286  5 this.response.sendError(i);
287    }
288   
 
289  0 toggle @Override
290    public String getContentType()
291    {
292  0 return this.response.getContentType();
293    }
294   
 
295  0 toggle @Override
296    public String getHeader(String s)
297    {
298  0 return this.response.getHeader(s);
299    }
300   
 
301  0 toggle @Override
302    public Collection<String> getHeaders(String s)
303    {
304  0 return this.response.getHeaders(s);
305    }
306   
 
307  0 toggle @Override
308    public Collection<String> getHeaderNames()
309    {
310  0 return this.response.getHeaderNames();
311    }
312    }