Author: xlawrence
Date: Fri Jun 1 15:01:11 2007
New Revision: 17443
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D17443&repname=
=3Djahia
Log:
Fix encoding issue. Set the default decoding charset to UTF-8.
Backport fixes ans optimizations developped on the SP branch during impleme=
ntation of the Generali form generator
Modified:
trunk/core/src/java/org/jahia/tools/files/FileUpload.java
Modified: trunk/core/src/java/org/jahia/tools/files/FileUpload.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/tools/files/FileUpload.java&rev=3D17443&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/core/src/java/org/jahia/tools/files/FileUpload.java (original)
+++ trunk/core/src/java/org/jahia/tools/files/FileUpload.java Fri Jun 1 15=
:01:11 2007
@@ -45,6 +45,7 @@
=
private static final org.apache.log4j.Logger logger =3D
org.apache.log4j.Logger.getLogger (FileUpload.class);
+ private static final String UTF_8 =3D "UTF-8";
=
private Map params;
private Map files;
@@ -53,6 +54,7 @@
=
private String savePath =3D "";
private int fileMaxSize;
+ private String encoding;
=
/**
* Constructor
@@ -61,15 +63,41 @@
* @param savePath the path where files should be saved
* @param fileMaxSize the max size of file to upload
*/
- public FileUpload(HttpServletRequest req,
- String savePath, int fileMaxSize)
+ public FileUpload(final HttpServletRequest req,
+ final String savePath,
+ final int fileMaxSize)
throws IOException {
=
this.req =3D req;
this.fileMaxSize =3D fileMaxSize;
this.savePath =3D savePath;
+ this.encoding =3D UTF_8;
init();
+ }
+
+ /**
+ * Constructor
+ *
+ * @param req
+ * @param savePath the path where files should be saved
+ * @param fileMaxSize the max size of file to upload
+ * @param charset The charset to use to decode the values (default =3D=
UTF-8)
+ */
+ public FileUpload(final HttpServletRequest req,
+ final String savePath,
+ final int fileMaxSize,
+ final String charset)
+ throws IOException {
=
+ this.req =3D req;
+ this.fileMaxSize =3D fileMaxSize;
+ this.savePath =3D savePath;
+ if (charset =3D=3D null) {
+ this.encoding =3D UTF_8;
+ } else {
+ this.encoding =3D charset;
+ }
+ init();
}
=
/**
@@ -87,28 +115,28 @@
=
if (checkSavePath(savePath)) {
try {
- DiskFileItemFactory factory =3D new DiskFileItemFactory();
+ final DiskFileItemFactory factory =3D new DiskFileItemFact=
ory();
factory.setSizeThreshold(1);
factory.setRepository(new File(savePath));
=
- ServletFileUpload upload =3D new ServletFileUpload(factory=
);
+ final ServletFileUpload upload =3D new ServletFileUpload(f=
actory);
=
- List items =3D upload.parseRequest(req);
+ final List items =3D upload.parseRequest(req);
=
- Iterator iter =3D items.iterator();
+ final Iterator iter =3D items.iterator();
while (iter.hasNext()) {
- DiskFileItem item =3D (DiskFileItem) iter.next();
+ final DiskFileItem item =3D (DiskFileItem) iter.next();
=
if (item.isFormField()) {
- String name =3D item.getFieldName();
- List v ;
+ final String name =3D item.getFieldName();
+ final List v ;
if (params.containsKey(name)) {
v =3D (List) params.get(name);
} else {
v =3D new ArrayList();
params.put(name,v);
}
- v.add(item.getString());
+ v.add(item.getString(encoding));
} else {
if (item.getSize() > 0) {
files.put(item.getStoreLocation().getName(), i=
tem);
@@ -137,14 +165,23 @@
return params.keySet();
}
=
+ public Map getParameterMap () {
+ return params;
+ }
+
+ public void setParameterMap(Map params) {
+ this.params =3D params;
+ }
+
/**
* Return the values of a parameter
*
* @param paramName the name of the parameter
* @return the values of a paramater as a String Array
*/
- public String[] getParameterValues (String paramName) {
- List list =3D ((List) params.get(paramName));
+ public String[] getParameterValues (final String paramName) {
+ final List list =3D ((List) params.get(paramName));
+ if (list =3D=3D null) return null;
String[] res =3D new String[list.size()];
list.toArray(res);
return res;
@@ -167,6 +204,10 @@
return ((DiskFileItem) files.get(n)).getName();
}
=
+ public String getFormFieldName(String n) {
+ return ((DiskFileItem) files.get(n)).getFieldName();
+ }
+
public String getFileContentType(String n) {
return ((DiskFileItem) files.get(n)).getContentType();
}
@@ -207,15 +248,15 @@
return;
}
=
- StringTokenizer tokenizer =3D new StringTokenizer(req.getQueryStri=
ng(),
+ final StringTokenizer tokenizer =3D new StringTokenizer(req.getQue=
ryString(),
"&");
while (tokenizer.hasMoreTokens()) {
- String param =3D tokenizer.nextToken();
+ final String param =3D tokenizer.nextToken();
int pos =3D param.indexOf("=3D");
if (pos > 0) {
- String name =3D param.substring(0, pos);
- String value =3D param.substring(pos + 1, param.length());
- List v ;
+ final String name =3D param.substring(0, pos);
+ final String value =3D param.substring(pos + 1, param.leng=
th());
+ final List v ;
if (params.containsKey(name)) {
v =3D (List) params.get(name);
} else {
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list