2 Replies Latest reply on Oct 11, 2009 11:58 AM by bobyang

    The filename property of <e:workbook> is not mail-safe

    bobyang

      If the filename property of <e:workbook/> is not mail-safe, the file name prompted by the browser will be irrecognizable when the file name is Chinese or any character encoding other than the ascii.


      The java EE api MimeUtility.encodeText() will resolve this problem.


      Now I have to encode the file name string before set it to the filename property like:



      MimeUtility.encodeText(filename);

      It's nice if seam developer could add this mail-safe encoding call in the seam-excel code. If the filename is ascii then the MimeUtility.encodeText() will bypass the string to be encoded, see also the Java EE reference page MimeUitlity .


      There are 2 places need such encoding:




      org.jboss.seam.document.DocumentStorePhaseListener.sendContent()
      org.jboss.seam.document.DocumentStoreServlet.doWork()
        • 1. Re: The filename property of <e:workbook> is not mail-safe
          bobyang

          And it is a bug of jboss-seam-excel ?
          Can I submit is as a bug?


          Cheers! : )

          • 2. Re: The filename property of <e:workbook> is not mail-safe
            bobyang

            Forget it. It is not a bug. The implementation of the <e:workbook/> filename property is fine.


            Because, I found there is no standard way to specify the Content-Disposition header value.
            The encode of the content-disposition header value can only be ASCII. If the file name is non-ascii, then there is no portable way to encode it.


            The Content-Disposition is defined in RFC2183, the header encoding is defined in RFC2047 and RFC2231.
            In short, IE does not support RFC2231 but obey the RFC2047 well. While the Firefox does not obey the RFC2047 well but it support RFC2231.
            So there is not a portable way to support non-ASCII character encoding of Content-Disposition header value, you have to use different encoding method for different browser.
            Especially, there is no way to encode non-ASCII for the Safari.
            See this link for detail information.


            Below is my solution for Firefox and IE.



            1. Use FacesContext to get User-Agent.

            2. If the User-Agent contains 'MSIE' then the filename = new String(origFileName.getBytes(”GB18030″), “ISO8859-1″);

            3. For other case, the filename = MimeUtility.encodeText(origFileName);



            Cheers!