details:   https://code.openbravo.com/erp/devel/pi/rev/a8b0a0331ab8
changeset: 20749:a8b0a0331ab8
user:      Shankar Balachandran <shankar.balachandran <at> openbravo.com>
date:      Wed Jul 17 11:20:46 2013 +0530
summary:   Fixes Issue 0024112: Problem with Cyrillic characters and attachments

Encoded the file name in the content-disposition based on the browser.
Set the character encoding to utf-8.

diffstat:

 src/org/openbravo/erpCommon/businessUtility/TabAttachments.java |  23 +++++++--
 1 files changed, 18 insertions(+), 5 deletions(-)

diffs (66 lines):

diff -r 93daf5858a3b -r a8b0a0331ab8 
src/org/openbravo/erpCommon/businessUtility/TabAttachments.java
--- a/src/org/openbravo/erpCommon/businessUtility/TabAttachments.java   Tue Jul 
16 14:25:28 2013 +0200
+++ b/src/org/openbravo/erpCommon/businessUtility/TabAttachments.java   Wed Jul 
17 11:20:46 2013 +0530
@@ -23,11 +23,13 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.Writer;
+import java.net.URLEncoder;
 import java.sql.Connection;
 import java.util.HashMap;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
+import javax.mail.internet.MimeUtility;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -194,7 +196,7 @@
         response.sendRedirect(strDireccion + request.getServletPath());
     } else if (vars.commandIn("DISPLAY_DATA")) {
       final String strFileReference = vars.getStringParameter("inpcFileId");
-      printPageFile(response, vars, strFileReference);
+      printPageFile(response, vars, strFileReference, request);
     } else if (vars.getCommand().contains("GET_MULTIPLE_RECORDS_OB3")) {
       printPageFileMultiple(response, vars);
     } else if (vars.commandIn("DEFAULT")) {
@@ -225,7 +227,7 @@
       printPageEdit(response, vars, strTab, strWindow, key, "");
     } else if (vars.commandIn("DISPLAY_DATA")) {
       final String strFileReference = 
vars.getRequiredStringParameter("inpcFileId");
-      printPageFile(response, vars, strFileReference);
+      printPageFile(response, vars, strFileReference, request);
     } else if (vars.commandIn("CHECK")) {
       final String tabId = vars.getStringParameter("inpTabId");
       final String inpKey = vars.getStringParameter("inpKey");
@@ -548,7 +550,7 @@
   }
 
   private void printPageFile(HttpServletResponse response, VariablesSecureApp 
vars,
-      String strFileReference) throws IOException, ServletException {
+      String strFileReference, HttpServletRequest request) throws IOException, 
ServletException {
     String fileDir = null;
     final TabAttachmentsData[] data = TabAttachmentsData.selectEdit(this, 
strFileReference);
     if (data == null || data.length == 0)
@@ -566,8 +568,19 @@
       response.setContentType("application/txt");
     else
       response.setContentType(data[0].datatypeContent);
-    response.setHeader("Content-Disposition",
-        "attachment; filename=\"" + data[0].name.replace("\"", "\\\"") + "\"");
+    response.setCharacterEncoding("UTF-8");
+    String userAgent = request.getHeader("user-agent");
+    if (userAgent.contains("MSIE")) {
+      response.setHeader(
+          "Content-Disposition",
+          "attachment; filename=\""
+              + URLEncoder.encode(data[0].name.replace("\"", "\\\""), "utf-8") 
+ "\"");
+    } else {
+      response.setHeader(
+          "Content-Disposition",
+          "attachment; filename=\""
+              + MimeUtility.encodeWord(data[0].name.replace("\"", "\\\""), 
"utf-8", "Q") + "\"");
+    }
 
     f.dumpFile(response.getOutputStream());
     response.getOutputStream().flush();

------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to