larryi      01/12/31 14:26:34

  Modified:    src/share/org/apache/tomcat/modules/generators
                        StaticInterceptor.java
  Log:
  In preparation for Japanese resource strings, allow a character set for
  directory listings other than ISO-8859-1.
  
  Submitted by: Kazuhiro Kazama
  
  Some attributes and handling was added so locale and character set
  used for directory listings can be configured.
  
  Revision  Changes    Path
  1.17      +61 -8     
jakarta-tomcat/src/share/org/apache/tomcat/modules/generators/StaticInterceptor.java
  
  Index: StaticInterceptor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/generators/StaticInterceptor.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- StaticInterceptor.java    20 Dec 2001 03:38:36 -0000      1.16
  +++ StaticInterceptor.java    31 Dec 2001 22:26:34 -0000      1.17
  @@ -76,6 +76,8 @@
    */
   public class StaticInterceptor extends BaseInterceptor {
       int realFileNote=-1;
  +    boolean useAcceptLanguage=true;
  +    String charset=null;
   
       public StaticInterceptor() {
       }
  @@ -94,6 +96,14 @@
        this.listings = listings;
       }
   
  +    public void setUseAcceptLanguage(boolean use) {
  +        useAcceptLanguage=use;
  +    }
  +
  +    public void setUseCharset(String charset) {
  +        this.charset=charset;
  +    }
  +
       public void engineInit(ContextManager cm) throws TomcatException {
        //      if( debug>0 ) log("Engine init " );
        
  @@ -120,6 +130,8 @@
        dirHandler.setNoteId( realFileNote );
        dirHandler.setContext( ctx );
        dirHandler.setModule( this );
  +        dirHandler.setUseAcceptLanguage(useAcceptLanguage);
  +        dirHandler.setCharset(charset);
        if (listings)
            ctx.addServlet( dirHandler );
       }
  @@ -396,7 +408,10 @@
       int realFileNote;
       int sbNote=0;
       Context context;
  -    
  +    Locale defLocale=null;
  +    String defCharset=null;
  +    StringManager defSM=null;
  +
       DirHandler() {
        //      setOrigin( Handler.ORIGIN_INTERNAL );
        name="tomcat.dirHandler";
  @@ -409,16 +424,49 @@
       public void setContext(Context ctx) {
        this.context=ctx;
       }
  +
  +    public void setUseAcceptLanguage(boolean use) {
  +        if( use ) {
  +            defLocale=null;
  +            defSM=null;
  +        } else {
  +            defLocale=Locale.getDefault();
  +            defSM=StringManager.
  +                    getManager("org.apache.tomcat.resources",defLocale);
  +        }
  +    }
  +
  +    public void setCharset(String charset) {
  +        defCharset=charset;
  +    }
       
       public void doService(Request req, Response res)
        throws Exception
       {
  -     // this is how get locale is implemented. Ugly, but it's in
  -     // the next round of optimizations
  -     String acceptL=req.getMimeHeaders().getHeader( "Accept-Language");
  -     Locale locale=AcceptLanguage.getLocale(acceptL);;
  -     StringManager sm=StringManager.
  -         getManager("org.apache.tomcat.resources",locale);
  +        Locale locale;
  +        StringManager sm;
  +        String charset=null;
  +
  +        // if default locale not specified, use Accept-Language header
  +        if( defLocale == null) {
  +            // this is how get locale is implemented. Ugly, but it's in
  +            // the next round of optimizations
  +            String acceptL=req.getMimeHeaders().getHeader( "Accept-Language");
  +            locale=AcceptLanguage.getLocale(acceptL);
  +            sm=StringManager.
  +                getManager("org.apache.tomcat.resources",locale);
  +        } else {
  +            locale=defLocale;
  +            sm=defSM;
  +        }
  +
  +        if( defCharset != null ) {
  +            if( "locale".equals(defCharset))
  +                charset=LocaleToCharsetMap.getCharset(locale);
  +            else
  +                charset=defCharset;
  +        }
  +
        DateFormat dateFormat =
            new SimpleDateFormat(datePattern,locale );
   
  @@ -468,7 +516,12 @@
        }
   
        if (! inInclude) {
  -         res.setContentType("text/html");
  +           if (charset == null || charset.equalsIgnoreCase("ISO-8859-1"))
  +               res.setContentType("text/html");
  +           else {
  +               res.setContentType("text/html; charset=" + charset);
  +               res.setUsingWriter(true);
  +           }
            buf.write("<html>\r\n");
            buf.write("<head>\r\n");
            buf.write("<title>");
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to