jon         01/11/14 14:00:24

  Modified:    conf     TurbineResources.properties
               conf/master TurbineResources.master
               src/java/org/apache/turbine/services/rundata
                        DefaultTurbineRunData.java
  Log:
  these are some changes regarding the i18n support in turbine. things are
  not perfect yet, but they are getting better and are definitely better
  than they were before. clearly no one is using T3 for i18n yet other than
  me because the old code just wouldn't have worked. :-(
  
  Revision  Changes    Path
  1.14      +8 -1      jakarta-turbine-3/conf/TurbineResources.properties
  
  Index: TurbineResources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/conf/TurbineResources.properties,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- TurbineResources.properties       2001/09/24 17:43:19     1.13
  +++ TurbineResources.properties       2001/11/14 22:00:23     1.14
  @@ -1,5 +1,5 @@
   # -------------------------------------------------------------------
  -# $Id: TurbineResources.properties,v 1.13 2001/09/24 17:43:19 jmcnally Exp $
  +# $Id: TurbineResources.properties,v 1.14 2001/11/14 22:00:23 jon Exp $
   #
   # This is the configuration file for Turbine.
   #
  @@ -240,6 +240,8 @@
   
   
services.RunDataService.classname=org.apache.turbine.services.rundata.TurbineRunDataService
   services.PullService.classname=org.apache.turbine.services.pull.TurbinePullService
  +## Needed by the RunData Service
  
+services.MimeTypeService.classname=org.apache.fulcrum.mimetype.TurbineMimeTypeService
   
   # -------------------------------------------------------------------
   # 
  @@ -350,6 +352,11 @@
   
services.RunDataService.default.run.data=org.apache.turbine.services.rundata.DefaultTurbineRunData
   services.RunDataService.default.parameter.parser=org.apache.turbine.ParameterParser
   
services.RunDataService.default.cookie.parser=org.apache.fulcrum.util.parser.DefaultCookieParser
  +
  +## Needed by DefaultTurbineRunData
  +locale.default.language=en
  +locale.default.country=US
  +locale.default.charset=8859_1
   
   # -------------------------------------------------------------------
   # 
  
  
  
  1.10      +8 -1      jakarta-turbine-3/conf/master/TurbineResources.master
  
  Index: TurbineResources.master
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/conf/master/TurbineResources.master,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TurbineResources.master   2001/09/24 17:43:19     1.9
  +++ TurbineResources.master   2001/11/14 22:00:24     1.10
  @@ -1,5 +1,5 @@
   # -------------------------------------------------------------------
  -# $Id: TurbineResources.master,v 1.9 2001/09/24 17:43:19 jmcnally Exp $
  +# $Id: TurbineResources.master,v 1.10 2001/11/14 22:00:24 jon Exp $
   #
   # This is the configuration file for Turbine.
   #
  @@ -240,6 +240,8 @@
   
   
services.RunDataService.classname=org.apache.turbine.services.rundata.TurbineRunDataService
   services.PullService.classname=org.apache.turbine.services.pull.TurbinePullService
  +## Needed by the RunData Service
  
+services.MimeTypeService.classname=org.apache.fulcrum.mimetype.TurbineMimeTypeService
   
   # -------------------------------------------------------------------
   # 
  @@ -350,6 +352,11 @@
   
services.RunDataService.default.run.data=org.apache.turbine.services.rundata.DefaultTurbineRunData
   services.RunDataService.default.parameter.parser=org.apache.turbine.ParameterParser
   
services.RunDataService.default.cookie.parser=org.apache.fulcrum.util.parser.DefaultCookieParser
  +
  +## Needed by DefaultTurbineRunData
  +locale.default.language=en
  +locale.default.country=US
  +locale.default.charset=8859_1
   
   # -------------------------------------------------------------------
   # 
  
  
  
  1.6       +118 -136  
jakarta-turbine-3/src/java/org/apache/turbine/services/rundata/DefaultTurbineRunData.java
  
  Index: DefaultTurbineRunData.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/services/rundata/DefaultTurbineRunData.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultTurbineRunData.java        2001/11/13 06:19:09     1.5
  +++ DefaultTurbineRunData.java        2001/11/14 22:00:24     1.6
  @@ -70,6 +70,7 @@
   import org.apache.fulcrum.security.util.AccessControlList;
   import org.apache.fulcrum.pool.Recyclable;
   import org.apache.fulcrum.pool.RecyclableSupport;
  +import org.apache.fulcrum.localization.Localization;
   import org.apache.fulcrum.mimetype.TurbineMimeTypes;
   import org.apache.fulcrum.security.entity.User;
   import org.apache.fulcrum.template.TurbineTemplate;
  @@ -96,7 +97,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Jon S. Stevens</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Bernie Hoeneisen</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Rall</a>
  - * @version $Id: DefaultTurbineRunData.java,v 1.5 2001/11/13 06:19:09 jmcnally Exp $
  + * @version $Id: DefaultTurbineRunData.java,v 1.6 2001/11/14 22:00:24 jon Exp $
    */
   public class DefaultTurbineRunData
       extends RecyclableSupport
  @@ -300,73 +301,6 @@
       }
   
       /**
  -     * Gets the default locale defined by properties named
  -     * "locale.default.lang" and "locale.default.country".
  -     *
  -     * @return the default locale or null.
  -     */
  -    protected static Locale getDefaultLocale()
  -    {
  -        if (!defaultLocaleChecked)
  -        {
  -            /* Get the default locale and cache it in a static variable. */
  -            String lang = 
Turbine.getConfiguration().getString("locale.default.language");
  -            String country = 
Turbine.getConfiguration().getString("locale.default.country");
  -            if (lang != null)
  -            {
  -                defaultLocale = country != null ?
  -                    new Locale(lang,country) : new Locale(lang,"");
  -            }
  -            else if (country != null)
  -            {
  -                defaultLocale = new Locale("",country);
  -            }
  -            else
  -            {
  -                defaultLocale = null;
  -            }
  -            defaultLocaleChecked = true;
  -        }
  -        return defaultLocale;
  -    }
  -
  -    /**
  -     * Gets the default charset defined by a property named
  -     * "locale.default.charset" or by the specified locale.
  -     * If the specified locale is null, the default locale is applied.
  -     *
  -     * @param locale the locale of the charset.
  -     * @return the name of the default charset or null.
  -     */
  -    protected String getDefaultCharSet()
  -    {
  -        if (!defaultCharSetChecked)
  -        {
  -            /* Get the default charset and cache it in a static variable. */
  -            defaultCharSet = Turbine.getConfiguration().
  -                getString("locale.default.charset");
  -            defaultCharSetChecked = true;
  -        }
  -
  -        String charset = defaultCharSet;
  -        if (charset == null)
  -        {
  -            /* Default charset isn't specified, get the locale specific one. */
  -            Locale locale = this.locale;
  -            if (locale == null)
  -            {
  -                locale = getDefaultLocale();
  -            }
  -            if ((locale != null) &&
  -                !locale.equals(Locale.US))
  -            {
  -                charset = TurbineMimeTypes.getCharSet(locale);
  -            }
  -        }
  -        return charset;
  -    }
  -
  -    /**
        * Constructs a run data object.
        */
       public DefaultTurbineRunData()
  @@ -460,18 +394,6 @@
        */
       public CookieParser getCookies()
       {
  -        // Parse the cookies first, if not yet done.
  -        
  -        /*
  -        
  -        if ((this.cookies != null) &&
  -            (this.cookies.getRunData() != this))
  -        {
  -            this.cookies.setRunData(this);
  -        }
  -        
  -        */
  -        
           return this.cookies;
       }
   
  @@ -552,9 +474,9 @@
        */
       public boolean hasAction()
       {
  -        return ( this.action != null &&
  +        return (this.action != null &&
                    this.action.length() > 0 &&
  -                 !this.action.equalsIgnoreCase("null") );
  +                 !this.action.equalsIgnoreCase("null"));
       }
   
       /**
  @@ -574,7 +496,7 @@
        *
        * @param action a atring.
        */
  -    public void setAction (String action )
  +    public void setAction (String action)
       {
           this.action = action;
       }
  @@ -614,7 +536,7 @@
        *
        * @param title a string.
        */
  -    public void setTitle (String title )
  +    public void setTitle (String title)
       {
           this.title = title;
       }
  @@ -627,7 +549,7 @@
       public boolean userExists()
       {
           user = getUserFromSession();
  -        return ( user != null );
  +        return (user != null);
       }
   
       /**
  @@ -680,7 +602,7 @@
               // (i.e. make a temporary anonymous user).
               return (proxy == null ? null : (User) proxy.getListener());
           }
  -        catch ( ClassCastException e )
  +        catch (ClassCastException e)
           {
               Category category = Category.getInstance(
                   "org.apache.turbine.services.rundata.DefaultTurbineRunData");
  @@ -716,7 +638,7 @@
           {
               session.removeValue(User.SESSION_KEY);
           }
  -        catch ( Exception e )
  +        catch (Exception e)
           {
               return false;
           }
  @@ -736,7 +658,7 @@
               // If the acl isn't yet defined, return null
               return (acl == null ? null : acl);
           }
  -        catch ( ClassCastException e )
  +        catch (ClassCastException e)
           {
               return null;
           }
  @@ -754,7 +676,7 @@
           {
               session.removeValue(AccessControlList.SESSION_KEY);
           }
  -        catch ( Exception e )
  +        catch (Exception e)
           {
               return false;
           }
  @@ -814,7 +736,7 @@
           throws IOException
       {
           // Check to see if null first.
  -        if ( this.out == null )
  +        if (this.out == null)
           {
               setOut(res.getWriter());
           }
  @@ -823,32 +745,102 @@
       }
   
       /**
  +     * Sets the print writer.
  +     *
  +     * @param out a print writer.
  +     */
  +    protected void setOut(PrintWriter out)
  +    {
  +        this.out = out;
  +    }
  +
  +    /**
  +     * Gets the default locale defined by properties named
  +     * "locale.default.lang" and "locale.default.country".
  +     * If neither property is defined, it will use the Local.getDefault()
  +     * method to return the appropriate Locale for the installed JVM.
  +     *
  +     * @return the default locale.
  +     */
  +    protected static Locale getDefaultLocale()
  +    {
  +        if (!defaultLocaleChecked)
  +        {
  +            /* Get the default locale and cache it in a static variable. */
  +            String lang = Turbine.getConfiguration()
  +                .getString("locale.default.language");
  +            String country = Turbine.getConfiguration()
  +                .getString("locale.default.country");
  +            if (lang != null)
  +            {
  +                defaultLocale = country != null ?
  +                    new Locale(lang,country) : new Locale(lang,"");
  +            }
  +            else if (country != null)
  +            {
  +                defaultLocale = new Locale("",country);
  +            }
  +            else
  +            {
  +                defaultLocale = Locale.getDefault();
  +            }
  +            defaultLocaleChecked = true;
  +        }
  +        return defaultLocale;
  +    }
  +
  +    /**
  +     * Gets the default charset defined by a property named
  +     * "locale.default.charset" or by the default Locale.
  +     *
  +     * @return the name of the default charset.
  +     */
  +    protected String getDefaultCharSet()
  +    {
  +        if (!defaultCharSetChecked)
  +        {
  +            /* Get the default charset and cache 
  +               it in a static variable. */
  +            defaultCharSet = Turbine.getConfiguration().
  +                getString("locale.default.charset");
  +
  +            if (defaultCharSet == null)
  +            {
  +                /* Default charset isn't specified, 
  +                   get the locale specific one. */
  +                Locale locale = getDefaultLocale();
  +                defaultCharSet = TurbineMimeTypes.getCharSet(locale);
  +            }
  +            defaultCharSetChecked = true;
  +        }
  +        return defaultCharSet;
  +    }
  +
  +    /**
        * Gets the locale. If it has not already been defined with
  -     * setLocale(), then  properties named "locale.default.lang"
  -     * and "locale.default.country" are checked from the Resource
  -     * Service and the corresponding locale is returned. If these
  -     * properties are undefined, JVM's default locale is returned.
  +     * setLocale(), then the Localization service is used to determine
  +     * the right Locale based on the HttpServletRequest. If that is
  +     * not possible, then the getDefaultLocale() method is used.
        *
  -     * @return the locale.
  +     * @return the Locale.
        */
       public Locale getLocale()
       {
  -        Locale locale = this.locale;
           if (locale == null)
           {
  -            locale = getDefaultLocale();
  +            locale = Localization.getLocale(getRequest());
               if (locale == null)
               {
  -                locale = Locale.getDefault();
  +                locale = getDefaultLocale();
               }
           }
           return locale;
       }
   
       /**
  -     * Sets the locale.
  +     * Sets the Locale.
        *
  -     * @param locale the new locale.
  +     * @param locale the new Locale.
        */
       public void setLocale(Locale locale)
       {
  @@ -857,21 +849,29 @@
   
       /**
        * Gets the charset. If it has not already been defined with
  -     * setCharSet(), then a property named "locale.default.charset"
  -     * is checked from the Resource Service and returned. If this
  -     * property is undefined, the default charset of the locale
  -     * is returned. If the locale is undefined, null is returned.
  +     * setCharSet(). It will then try to get the getDefaultCharSet().
  +     * If that isn't defined, then the Localization/Mimetype service is 
  +     * used to determine the right charset based on the 
  +     * HttpServletRequest. Please note that this ordering is still up
  +     * in the air and may change in the near future as more testing is done. 
  +     * The issue is that sometimes, even though the Locale
  +     * is dynamic, the charset should always be 8859_1. So, the current
  +     * ordering allows us to just define things as always being 8859_1 which
  +     * may or may not be correct.
        *
  -     * @return the name of the charset or null.
  +     * @return the charset.
        */
       public String getCharSet()
       {
  -        String charset = this.charSet;
  -        if (charset == null)
  +        if (charSet == null)
           {
  -            charset = getDefaultCharSet();
  +            charSet = getDefaultCharSet();
  +            if (charSet == null)
  +            {
  +                charSet = TurbineMimeTypes.getCharSet(getLocale());
  +            }
           }
  -        return charset;
  +        return charSet;
       }
   
       /**
  @@ -900,22 +900,14 @@
           String ct = this.contentType;
           if (ct != null)
           {
  -            String charset = this.charSet;
  -            if (charset == null)
  +            if (ct.startsWith("text/"))
               {
  -                if (ct.startsWith("text/"))
  +                String charset = getCharSet();
  +                if (charset != null)
                   {
  -                    charset = getDefaultCharSet();
  -                    if (charset != null)
  -                    {
  -                        ct += "; charset=" + charset;
  -                    }
  +                    ct += "; charset=" + charset;
                   }
               }
  -            else
  -            {
  -                ct += "; charset=" + charset;
  -            }
           }
           else
           {
  @@ -1033,7 +1025,7 @@
        */
       public String getRemoteAddr()
       {
  -        if ( this.remoteAddr == null )
  +        if (this.remoteAddr == null)
           {
               this.remoteAddr = this.getRequest().getRemoteAddr();
           }
  @@ -1048,7 +1040,7 @@
        */
       public String getRemoteHost()
       {
  -        if ( this.remoteHost == null )
  +        if (this.remoteHost == null)
           {
               this.remoteHost = this.getRequest().getRemoteHost();
           }
  @@ -1063,9 +1055,9 @@
        */
       public String getUserAgent()
       {
  -        if ( this.userAgent == null )
  +        if (this.userAgent == null)
           {
  -            this.userAgent = this.getRequest().getHeader( "User-Agent" );
  +            this.userAgent = this.getRequest().getHeader("User-Agent");
           }
   
           return this.userAgent;
  @@ -1079,7 +1071,7 @@
       {
           user = getUserFromSession();
   
  -        if ( user != null )
  +        if (user != null)
           {
               user.setLastAccessDate();
               user.incrementAccessCounter();
  @@ -1247,16 +1239,6 @@
       // ********************
       // Miscellanous setters
       // ********************
  -
  -    /**
  -     * Sets the print writer.
  -     *
  -     * @param out a print writer.
  -     */
  -    protected void setOut(PrintWriter out)
  -    {
  -        this.out = out;
  -    }
   
       /**
        * Sets the cached server scheme that is stored in the server data.
  
  
  

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

Reply via email to