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:
parent
d4e2ea9ebc
commit
3502db6219
1 changed files with 6 additions and 83 deletions
|
@ -2,9 +2,6 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.controller;
|
package edu.cornell.mannlib.vitro.webapp.controller;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -19,21 +16,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDao;
|
||||||
|
|
||||||
public class VitroRequest extends HttpServletRequestWrapper {
|
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
|
//Attribute in case of special model editing such as display model editing
|
||||||
public static final String SPECIAL_WRITE_MODEL = "specialWriteModel";
|
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;
|
|
||||||
|
|
||||||
private HttpServletRequest _req;
|
private HttpServletRequest _req;
|
||||||
|
|
||||||
|
@ -163,80 +147,19 @@ public class VitroRequest extends HttpServletRequestWrapper {
|
||||||
setAttribute("appBean",ab);
|
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")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String[]> getParameterMap() {
|
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();
|
||||||
return _req.getParameterMap();
|
|
||||||
} else {
|
|
||||||
if (convertedParameterMap == null){
|
|
||||||
convertedParameterMap = convertParameterMap( _req.getParameterMap() );
|
|
||||||
}
|
|
||||||
return convertedParameterMap;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getParameter(String name) {
|
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);
|
||||||
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];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getParameterValues(String name) {
|
public String[] getParameterValues(String name) {
|
||||||
if ((_req.getAttribute("convertParameterEncoding") != null && !((Boolean)_req.getAttribute("convertParameterEncoding"))) || this.getMethod().equals("POST") || !convertParameterEncoding)
|
return _req.getParameterValues(name);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue