Removing conversion of ISO-8859 to UTF-8 in VitroRequest because this is now handled by the URIEncoding on the Connector in server.xml. NIHVIVO-3277 NIHVIVO-3410

This commit is contained in:
briancaruso 2011-12-02 18:47:57 +00:00
parent d4e2ea9ebc
commit 3502db6219

View file

@ -2,9 +2,6 @@
package edu.cornell.mannlib.vitro.webapp.controller;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
@ -19,21 +16,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDao;
public class VitroRequest extends HttpServletRequestWrapper {
private static final String FROM_ENCODING = "ISO-8859-1";
private static final String TO_ENCODING = "UTF-8";
public static boolean convertParameterEncoding = true;
//Attribute in case of special model editing such as display model editing
public static final String SPECIAL_WRITE_MODEL = "specialWriteModel";
public static boolean getConvertParameterEncoding() {
return convertParameterEncoding;
}
public static void setConvertParameterEncoding(boolean cpe) {
convertParameterEncoding = cpe;
}
private Map<String,String[]> convertedParameterMap;
public static final String SPECIAL_WRITE_MODEL = "specialWriteModel";
private HttpServletRequest _req;
@ -163,80 +147,19 @@ public class VitroRequest extends HttpServletRequestWrapper {
setAttribute("appBean",ab);
}
/* These methods are overridden so that we might convert URL-encoded request parameters to UTF-8
* Call static method setConvertParameterEncoding(false) to disable conversion.
*/
@SuppressWarnings("unchecked")
@Override
public Map<String, String[]> getParameterMap() {
if ((_req.getAttribute("convertParameterEncoding") != null && !((Boolean)_req.getAttribute("convertParameterEncoding"))) || _req.getParameterMap() == null || this.getMethod().equals("POST") || !convertParameterEncoding) {
return _req.getParameterMap();
} else {
if (convertedParameterMap == null){
convertedParameterMap = convertParameterMap( _req.getParameterMap() );
}
return convertedParameterMap;
}
public Map<String, String[]> getParameterMap() {
return _req.getParameterMap();
}
@Override
public String getParameter(String name) {
if ((_req.getAttribute("convertParameterEncoding") != null && !((Boolean)_req.getAttribute("convertParameterEncoding"))) || _req.getParameter(name) == null || this.getMethod().equals("POST") || !convertParameterEncoding)
return _req.getParameter(name);
else {
Map<String, String[]> pmap = getParameterMap();
String[] values = pmap.get(name);
if( values == null )
return null;
else if( values.length == 0 )
return null;
else
return values[0];
}
return _req.getParameter(name);
}
@Override
public String[] getParameterValues(String name) {
if ((_req.getAttribute("convertParameterEncoding") != null && !((Boolean)_req.getAttribute("convertParameterEncoding"))) || this.getMethod().equals("POST") || !convertParameterEncoding)
return _req.getParameterValues(name);
else {
Map<String, String[]> pmap = getParameterMap();
if( pmap != null )
return pmap.get(name);
else
return null;
}
}
public static HashMap<String,String[]> convertParameterMap( Map<String, String[]> map ){
if( map == null ) return null;
HashMap<String,String[]> rMap = new HashMap<String,String[]>();
Iterator<String> keyIt = map.keySet().iterator();
while (keyIt.hasNext()) {
String key = keyIt.next();
rMap.put(key, convertValues( map.get(key) ));
}
return rMap;
}
public static String[] convertValues(String[] in ){
if( in == null ) return null;
String[] rv = new String[ in.length ];
for (int i=0; i<in.length; i++) {
rv[i] = convertValue( in[i] );
}
return rv;
}
public static String convertValue(String in ){
if( in == null ) return null;
try{
return new String(in.getBytes(FROM_ENCODING), TO_ENCODING);
} catch (UnsupportedEncodingException e) {
System.out.println(e);
return null;
}
}
return _req.getParameterValues(name);
}
}