portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggol...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/services/resources JetspeedResources.java
Date Tue, 10 Sep 2002 02:01:27 GMT
ggolden     2002/09/09 19:01:27

  Modified:    src/java/org/apache/jetspeed/services/resources
                        JetspeedResources.java
  Log:
  When overriding settings in the JetspeedResources.properties (and TurbineResources.properties),
we might want to set a value with our
  site's setting, a value that is also set in the standard jr.p and tr.p distribution files.
 It's nice to be able to use these files unchanged so we can keep up easily
  with Jetspeed development.
  
  If the value we are setting is a string, this already works - the first value set to
  the property is used, so we can just do our settings before the standard files
  are read in.
  
  If the value we are setting is a boolean, long, float, double, or int, this doesn't work
- we get class cast exceptions.
  
  JetspeedSecurity, which is used by Jetspeed code to access the configuration values, now
catches these class cast exceptions, and also takes the calls to getString.  If there's an
array of values, it will use the first one (it's the combination of the array of values that
mess up the reading without this).
  
  Note: this only works for Jetspeed properties - turbine properties don't use this
  code.  Only string properties can be overridden by setting your site values first
  for turbine properties.
  
  Note: This code would be best deep inside turbine, but can live here till Turbine
  handles these cases.
  
  Revision  Changes    Path
  1.13      +322 -2    jakarta-jetspeed/src/java/org/apache/jetspeed/services/resources/JetspeedResources.java
  
  Index: JetspeedResources.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/resources/JetspeedResources.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- JetspeedResources.java	26 Jul 2002 01:47:21 -0000	1.12
  +++ JetspeedResources.java	10 Sep 2002 02:01:27 -0000	1.13
  @@ -55,16 +55,22 @@
   package org.apache.jetspeed.services.resources;
   
   import org.apache.turbine.services.resources.TurbineResources;
  +import org.apache.turbine.util.Log;
   
   /**
    * This class defines the Jetspeed properties keys.
    * All properties can be retrieved using TurbineResources or JetspeedResources
  - * directly
  + * directly.
  + *
  + * This class also overrides the covers for many of the get routines.  It handles the cases
  + * where we want a single value, perhaps as a boolean or float, but the configuration may
have
  + * an array of values.  In these cases, we let the first value override all the others
and use it.
    *
    * @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
    * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
    * @author <a href="mailto:tom@PIsoftware.com">Tom Adams</a>
    * @author <a href="mailto:kimptoc_mail@yahoo.com">Chris Kimpton</a>
  + * @author <a href="mailto:ggolden@apache.org">Glenn R. Golden</a>
    * @version $Id$
    */
   public class JetspeedResources extends TurbineResources {
  @@ -156,7 +162,321 @@
        */
       public static final String PATH_PANEL_KEY = "select-panel";        
   
  +    /**
  +     * The purpose of this method is to get the configuration resource
  +     * with the given name as a boolean value.
  +     *
  +     * @param name The resource name.
  +     * @return The value of the named resource as a boolean.
  +     */
  +    public static boolean getBoolean(String name)
  +    {
  +        try
  +        {
  +            return TurbineResources.getBoolean (name);
  +        }
  +        catch (ClassCastException e)
  +        {
  +            // get the possible list
  +            String[] values = getStringArray(name);
  +            
  +            // try again with the first
  +            if ((values != null) && (values.length > 0))
  +                return new Boolean(values[0]).booleanValue();
  +
  +            // otherwise, just throw the exception
  +            throw e;
  +        }
  +    }
  +
  +    /**
  +     * The purppose of this method is to get the configuration
  +     * resource with the given name as a boolean value, or a default
  +     * value.
  +     *
  +     * @param name The resource name.
  +     * @param def The default value of the resource.
  +     * @return The value of the named resource as a boolean.
  +     */
  +    public static boolean getBoolean(String name,
  +                                     boolean def)
  +    {
  +        try
  +        {
  +            return TurbineResources.getBoolean(name, def);
  +        }
  +        catch (ClassCastException e)
  +        {
  +            // get the possible list
  +            String[] values = getStringArray(name);
  +            
  +            // try again with the first
  +            if ((values != null) && (values.length > 0))
  +                return new Boolean(values[0]).booleanValue();
  +
  +            // otherwise, just throw the exception
  +            throw e;
  +        }
  +    }
  +
  +    /**
  +     * The purpose of this method is to get the configuration resource
  +     * with the given name as a double.
  +     *
  +     * @param name The resoource name.
  +     * @return The value of the named resource as double.
  +     */
  +    public static double getDouble(String name)
  +    {
  +        try
  +        {
  +            return TurbineResources.getDouble(name);
  +        }
  +        catch (ClassCastException e)
  +        {
  +            // get the possible list
  +            String[] values = getStringArray(name);
  +            
  +            // try again with the first
  +            if ((values != null) && (values.length > 0))
  +                return Double.parseDouble(values[0]);
  +
  +            // otherwise, just throw the exception
  +            throw e;
  +        }
  +    }
  +
  +    /**
  +     * The purpose of this method is to get the configuration resource
  +     * with the given name as a double, or a default value.
  +     *
  +     * @param name The resource name.
  +     * @param def The default value of the resource.
  +     * @return The value of the named resource as a double.
  +     */
  +    public static double getDouble(String name,
  +                                   double def)
  +    {
  +        try
  +        {
  +            return TurbineResources.getDouble(name, def);
  +        }
  +        catch (ClassCastException e)
  +        {
  +            // get the possible list
  +            String[] values = getStringArray(name);
  +            
  +            // try again with the first
  +            if ((values != null) && (values.length > 0))
  +                return Double.parseDouble(values[0]);
  +
  +            // otherwise, just throw the exception
  +            throw e;
  +        }
  +    }
  +
  +    /**
  +     * The purpose of this method is to get the configuration resource
  +     * with the given name as a float.
  +     *
  +     * @param name The resource name.
  +     * @return The value of the resource as a float.
  +     */
  +    public static float getFloat(String name)
  +    {
  +        try
  +        {
  +            return TurbineResources.getFloat(name);
  +        }
  +        catch (ClassCastException e)
  +        {
  +            // get the possible list
  +            String[] values = getStringArray(name);
  +            
  +            // try again with the first
  +            if ((values != null) && (values.length > 0))
  +                return Float.parseFloat(values[0]);
  +
  +            // otherwise, just throw the exception
  +            throw e;
  +        }
  +    }
  +
  +    /**
  +     * The purpose of this method is to get the configuration resource
  +     * with the given name as a float, or a default value.
  +     *
  +     * @param name The resource name.
  +     * @param def The default value of the resource.
  +     * @return The value of the resource as a float.
  +     */
  +    public static float getFloat(String name,
  +                                 float def)
  +    {
  +        try
  +        {
  +            return TurbineResources.getFloat(name, def);
  +        }
  +        catch (ClassCastException e)
  +        {
  +            // get the possible list
  +            String[] values = getStringArray(name);
  +            
  +            // try again with the first
  +            if ((values != null) && (values.length > 0))
  +                return Float.parseFloat(values[0]);
  +
  +            // otherwise, just throw the exception
  +            throw e;
  +        }
  +    }
  +
  +    /**
  +     * The purpose of this method is to get the configuration resource
  +     * with the given name as an integer.
  +     *
  +     * @param name The resource name.
  +     * @return The value of the resource as an integer.
  +     */
  +    public static int getInt(String name)
  +    {
  +        try
  +        {
  +            return TurbineResources.getInt(name);
  +        }
  +        catch (ClassCastException e)
  +        {
  +            // get the possible list
  +            String[] values = getStringArray(name);
  +            
  +            // try again with the first
  +            if ((values != null) && (values.length > 0))
  +                return Integer.parseInt(values[0]);
  +
  +            // otherwise, just throw the exception
  +            throw e;
  +        }
  +    }
  +
  +    /**
  +     * The purpose of this method is to get the configuration resource
  +     * with the given name as an integer, or a default value.
  +     *
  +     * @param name The resource name.
  +     * @param def The default value of the resource.
  +     * @return The value of the resource as an integer.
  +     */
  +    public static int getInt(String name,
  +                             int def)
  +    {
  +        try
  +        {
  +            return TurbineResources.getInt(name, def);
  +        }
  +        catch (ClassCastException e)
  +        {
  +            // get the possible list
  +            String[] values = getStringArray(name);
  +            
  +            // try again with the first
  +            if ((values != null) && (values.length > 0))
  +                return Integer.parseInt(values[0]);
  +
  +            // otherwise, just throw the exception
  +            throw e;
  +        }
  +    }
  +
  +    /**
  +     * The purpose of this method is to get the configuration resource
  +     * with the given name as a long.
  +     *
  +     * @param name The resource name.
  +     * @return The value of the resource as a long.
  +     */
  +    public static long getLong(String name)
  +    {
  +        try
  +        {
  +            return TurbineResources.getLong(name);
  +        }
  +        catch (ClassCastException e)
  +        {
  +            // get the possible list
  +            String[] values = getStringArray(name);
  +            
  +            // try again with the first
  +            if ((values != null) && (values.length > 0))
  +                return Long.parseLong(values[0]);
  +
  +            // otherwise, just throw the exception
  +            throw e;
  +        }
  +    }
  +
  +    /**
  +     * The purpose of this method is to get the configuration resource
  +     * with the given name as a long, or a default value.
  +     *
  +     * @param name The resource name.
  +     * @param def The default value of the resource.
  +     * @return The value of the resource as a long.
  +     */
  +    public static long getLong(String name,
  +                               long def)
  +    {
  +        try
  +        {
  +            return TurbineResources.getLong(name, def);
  +        }
  +        catch (ClassCastException e)
  +        {
  +            // get the possible list
  +            String[] values = getStringArray(name);
  +            
  +            // try again with the first
  +            if ((values != null) && (values.length > 0))
  +                return Long.parseLong(values[0]);
  +
  +            // otherwise, just throw the exception
  +            throw e;
  +        }
  +    }
   
  +    /**
  +     * The purpose of this method is to get the configuration resource
  +     * with the given name as a string.
  +     *
  +     * @param name The resource name.
  +     * @return The value of the resource as a string.
  +     */
  +    public static String getString(String name)
  +    {
  +        // get the possible list
  +        String[] values = getStringArray(name);
  +        if ((values != null) && (values.length > 0))
  +            return values[0];
   
  +        return TurbineResources.getString(name);
  +    }
   
  +    /**
  +     * The purpose of this method is to get the configuration resource
  +     * with the given name as a string, or a default value.
  +     *
  +     * @param name The resource name.
  +     * @param def The default value of the resource.
  +     * @return The value of the resource as a string.
  +     */
  +    public static String getString(String name,
  +                                   String def)
  +    {
  +        // get the possible list
  +        String[] values = getStringArray(name);
  +        if ((values != null) && (values.length > 0))
  +            return values[0];
  +
  +        return TurbineResources.getString(name, def);
  +    }
   }
  +
  
  
  

--
To unsubscribe, e-mail:   <mailto:jetspeed-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:jetspeed-dev-help@jakarta.apache.org>


Mime
View raw message