Re: xsl transformation and special characters

Morten,

Here's the bit... indeed it's dirty.
     protected static String convertStringBytes ( String source ) {
         if ( source == null ) return null;
         StringBuffer buff = new StringBuffer ( source.length() );
         try {
             java.io.Reader reader = new java.io.InputStreamReader(
                 new DirtyStringBytesInputStream(source), "UTF8" );
             int q =0;
             while ( ( q = reader.read() ) != -1 ) buff.append((char) q);
         } catch(Exception ex) {ex.printStackTrace();}
		// nothing can happen...
         return buff.toString();
     }


     public static void main(String[] args) {
         System.out.println( convertStringBytes( args[0]));
     }

         private static class DirtyStringBytesInputStream
		extends InputStream {

             public DirtyStringBytesInputStream(String s) {
                 this.source = s;
                 this.leng = s.length();
             }

             private String source;
             private int leng;
             private int pos;

             public int read() {
                 if ( pos >= leng ) return -1;
                 return (byte) source.charAt(pos++);
             }

         } // class DirtyUTF8Reader


(it should be rewritten with pooling of the StringBuffer and 
InputStreamReader...)
Which server are you using btw ?
If a servlet setting a header is a matter of response.setHeader...
As of the browser settings, I would keep this untouched if you intend to 
deploy this to the world...

Paul


Morten Andersen wrote:
> So what you're suggesting is:
> 
> Paul:
> pipe these request.getParameter() through a UTF-8 
> java.io.InputStreamReader and we are now able to accept russian, math, 
> and just about anything Unicode 3 in our forms.
> 
>         String math = request.getParameter("param");
>         StringBuffer sb = new StringBuffer();
>         InputStream is = new InputStream();
>         is.read(math.getBytes());
>         InputStreamReader isr = new InputStreamReader(is);
>         ...
> 
> David:
> 1) To change browser settings to auto-select
> 2) Changing the http header from the server-side. (How do I do that?)
> 3) Apply a solution like Paul's... to solve tomcat-bugs.
> 
> I tryed to change the browser settings with no luck, so I'll try Paul's 
> solution even though it seems to be bad coding...
> 
>  Thanks
> 
> Morten Andersen
> Master of applied mathematics and computer science
> Research assistant (in e-learning)
> 
> The Maersk Institute of Production technology at Southern Danish 
> University www.mip.sdu.dk
> Campusvej 55
> DK-5230 Odense M
> Denmark
> +45 6550-3654
> Jabber id: hat@jabber.dk

Received on Friday, 4 July 2003 16:17:21 UTC