1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.wysiwyg.server.internal.filter.http

File MutableHttpServletRequest.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

6
18
12
1
131
81
18
1
1.5
12
1.5

Classes

Class Line # Actions
MutableHttpServletRequest 40 18 0% 18 4
0.888888988.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 org.xwiki.wysiwyg.server.internal.filter.http;
21   
22    import java.io.IOException;
23    import java.util.Collections;
24    import java.util.Enumeration;
25    import java.util.HashMap;
26    import java.util.Map;
27   
28    import javax.servlet.ServletResponse;
29    import javax.servlet.http.HttpServletRequest;
30    import javax.servlet.http.HttpServletRequestWrapper;
31    import javax.servlet.http.HttpServletResponse;
32   
33    import org.xwiki.wysiwyg.server.filter.MutableServletRequest;
34   
35    /**
36    * {@link MutableServletRequest} implementation for the HTTP protocol.
37    *
38    * @version $Id: 35ec7a2d5dfc0e8ef9706ec449b6fa8f5d93e8df $
39    */
 
40    public class MutableHttpServletRequest extends HttpServletRequestWrapper implements MutableServletRequest
41    {
42    /**
43    * Parameters used instead of those from the wrapped request. This way exiting request parameters can be overwritten
44    * and also new parameters can be added.
45    */
46    private final Map<String, String[]> params = new HashMap<String, String[]>();
47   
48    /**
49    * Wraps the specified request and copies its parameters to {@link #params} where they can be overwritten later.
50    *
51    * @param request The request to be wrapped.
52    */
 
53  5 toggle @SuppressWarnings("unchecked")
54    public MutableHttpServletRequest(HttpServletRequest request)
55    {
56  5 super(request);
57   
58  5 params.putAll(request.getParameterMap());
59    }
60   
 
61  5 toggle @Override
62    public String setParameter(String name, String value)
63    {
64  5 String[] previousValues = params.put(name, new String[] {value});
65  5 return (previousValues == null || previousValues.length == 0) ? null : previousValues[0];
66    }
67   
 
68  0 toggle @Override
69    public String[] setParameterValues(String name, String[] values)
70    {
71  0 return params.put(name, values);
72    }
73   
 
74  12 toggle @Override
75    public String removeParameter(String name)
76    {
77  12 String[] previousValues = params.remove(name);
78  12 return (previousValues == null || previousValues.length == 0) ? null : previousValues[0];
79    }
80   
 
81  166 toggle @Override
82    public String getParameter(String name)
83    {
84  166 String[] values = params.get(name);
85  166 return (values == null || values.length == 0) ? null : values[0];
86    }
87   
 
88  5 toggle @Override
89    public Map<String, String[]> getParameterMap()
90    {
91  5 return Collections.unmodifiableMap(params);
92    }
93   
 
94  5 toggle @Override
95    public Enumeration<String> getParameterNames()
96    {
97  5 return Collections.enumeration(params.keySet());
98    }
99   
 
100  68 toggle @Override
101    public String[] getParameterValues(String name)
102    {
103  68 return params.get(name);
104    }
105   
 
106  1 toggle @Override
107    public void sendRedirect(ServletResponse res, String url) throws IOException
108    {
109  1 ((HttpServletResponse) res).sendRedirect(url);
110    }
111   
 
112  1 toggle @Override
113    public String getReferer()
114    {
115  1 return getHeader("Referer");
116    }
117   
 
118  2 toggle @Override
119    public Object getSessionAttribute(String attrName)
120    {
121  2 return getSession().getAttribute(attrName);
122    }
123   
 
124  2 toggle @Override
125    public Object setSessionAttribute(String attrName, Object attrValue)
126    {
127  2 Object oldValue = getSession().getAttribute(attrName);
128  2 getSession().setAttribute(attrName, attrValue);
129  2 return oldValue;
130    }
131    }