Hi!

Brilliant - I have to try that. I ended up doing a hack in the DisplayTag
v1.0 to force latin1 (ISO8859-1) on all Excel-exports, but while it is sort
of working, it is not the right way to go about this, and it comes with some
drawbacks.

Thanks,

         Henrik


On 7/6/07, Frantz D. <[EMAIL PROTECTED]> wrote:


I have found a solution :-) !

After a little investigation in the displaytag source code, I can say
there
is no way to export a CSV file encoded with a different charset from the
JSP.

But I make it possible with the help of this little path :
First I have written a custom Excel specific CSV view extending the
default
one as following :

ExcelCSVView class :
--------------------------------------
package org.displaytag.export;

import java.io.IOException;
import java.io.Writer;
import javax.servlet.jsp.JspException;
import org.apache.commons.lang.StringUtils;

public class ExcelCSVView extends CsvView {

        public String getRowEnd() {
                return "\r\n";  //Windows end of line
        }

        public String getCellEnd() {
                return ";";     //Excel default cell separator (for
french)
        }

        public String getMimeType() {
                return "text/csv; charset=cp1252"; //uses the Windows
Latin-1 superset
encoding
        }

        protected String escapeColumnValue(Object value) {
                String stringValue = StringUtils.trim(value.toString());
                if (!StringUtils.containsNone(stringValue, new
char[]{'\n', ';' })) {
                        //double '"' as escape sequence for included quote
symbols
                        return "\"" + StringUtils.replace(stringValue,
"\"", "\"\"") + "\"";
                }
                return stringValue;
        }
}
------------------------------------

and then, I have added this line in my "displaytag.properties" file :
export.csv.class=org.displaytag.export.ExcelCSVView

and patched the org.displaytag.filter.ExportDelegate class as following :

--- ExportDelegate.java
+++ ExportDelegate.java
@@ -112,124 +112,131 @@
         String characterEncoding = wrapper.getCharacterEncoding();
         String wrappedContentType = wrapper.getContentType();

         if (wrappedContentType != null &&
wrappedContentType.indexOf("charset") > -1)
         {
              // charset is already specified (see #921811)
              characterEncoding =
StringUtils.substringAfter(wrappedContentType, "charset=");
         }

+        //the target encoding is already specified in contentType :
+        if( contentType.indexOf("charset") > -1)
+        {
+             characterEncoding=StringUtils.substringAfter(contentType,
"charset=");
+             contentType = contentType.substring(0,
contentType.indexOf(';')).trim();
+        }
+
         if (characterEncoding != null && contentType.indexOf("charset")
==
-1) //$NON-NLS-1$
         {
             contentType += "; charset=" + characterEncoding;
//$NON-NLS-1$
         }

That's all.

--Frantz

--
View this message in context:
http://www.nabble.com/Export-in-different-content-type-than-the-page-tf3870606.html#a11460141
Sent from the DisplayTag - General mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
displaytag-user mailing list
displaytag-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-user

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
displaytag-user mailing list
displaytag-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-user

Reply via email to