henning     2003/02/28 04:06:52

  Modified:    src/java/org/apache/turbine/services/upload
                        BaseUploadService.java TurbineUpload.java
                        UploadService.java
  Log:
  Cleaned up the handling of getAutomatic() to be in line with all the
  other methods. Added a new isAvailable() method to the facade to be
  able to determine whether a service is really configured.
  
  Revision  Changes    Path
  1.4       +23 -1     
jakarta-turbine-2/src/java/org/apache/turbine/services/upload/BaseUploadService.java
  
  Index: BaseUploadService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/upload/BaseUploadService.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BaseUploadService.java    12 Feb 2003 17:50:16 -0000      1.3
  +++ BaseUploadService.java    28 Feb 2003 12:06:52 -0000      1.4
  @@ -183,4 +183,26 @@
           return ServletUtils.expandRelative(config, tmpPath);
   
       }
  +
  +    /**
  +     * Retrieves the value of the 'automatic' property of [EMAIL PROTECTED]
  +     * UploadService}. This reports whether the Parameter parser
  +     * should allow "automatic" uploads if it is submitted to
  +     * Turbine.
  +     *
  +     * @return The value of 'automatic' property of [EMAIL PROTECTED]
  +     * UploadService}.
  +     */
  +    public boolean getAutomatic()
  +    {
  +        String auto = 
  +            getConfiguration().getString(
  +                UploadService.AUTOMATIC_KEY,
  +                UploadService.AUTOMATIC_DEFAULT).toLowerCase();
  +
  +        // True, yes, 1 is "true", everything else is "false".
  +        return auto.equals("true") 
  +            || auto.equals("yes") 
  +            || auto.equals("1");
  +    }
   }
  
  
  
  1.4       +29 -21    
jakarta-turbine-2/src/java/org/apache/turbine/services/upload/TurbineUpload.java
  
  Index: TurbineUpload.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/upload/TurbineUpload.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TurbineUpload.java        12 Feb 2003 17:50:16 -0000      1.3
  +++ TurbineUpload.java        28 Feb 2003 12:06:52 -0000      1.4
  @@ -56,7 +56,9 @@
   
   import javax.servlet.http.HttpServletRequest;
   
  +import org.apache.turbine.services.InstantiationException;
   import org.apache.turbine.services.TurbineServices;
  +
   import org.apache.turbine.util.ParameterParser;
   import org.apache.turbine.util.TurbineException;
   
  @@ -87,40 +89,46 @@
       }
   
       /**
  -     * <p> Retrieves the value of 'automatic' property of [EMAIL PROTECTED]
  -     * UploadService}.
  +     * Checks whether an Upload Service is configured. 
  +     * This method is safe to call even with no Upload
  +     * service installed.
        *
  -     * @return The value of 'automatic' property of [EMAIL PROTECTED]
  -     * UploadService}.
  +     * @return True if an upload Service is configured
        */
  -    public static boolean getAutomatic()
  +    public static boolean isAvailable()
       {
           UploadService upload = null;
           try
           {
               upload = getService();
           }
  -        catch (org.apache.turbine.services.InstantiationException ie)
  +        catch (InstantiationException ie)
           {
               // If the service couldn't be instantiated, it obviously
  -            // can't be used for automatic uploading.
  -            return false;
  -        }
  -        String auto = upload.getProperties()
  -                .getProperty(UploadService.AUTOMATIC_KEY,
  -                        UploadService.AUTOMATIC_DEFAULT.toString())
  -                .toLowerCase();
  -        if (auto.equals("true") || auto.equals("yes") || auto.equals("1"))
  -        {
  -            return true;
  -        }
  -        if (auto.equals("false") || auto.equals("no") || auto.equals("0"))
  -        {
  +            // isn't configured.
               return false;
           }
  -        return UploadService.AUTOMATIC_DEFAULT.booleanValue();
  +        return true;
       }
   
  +
  +    /**
  +     * Retrieves the value of the 'automatic' property of [EMAIL PROTECTED]
  +     * UploadService}. This reports whether the Upload Service
  +     * is available and (if yes), the Parameter parser should
  +     * allow "automatic" uploads if it is submitted to Turbine.
  +     *
  +     * This method is safe to call even with no Upload Service
  +     * configured.
  +     *
  +     * @return The value of 'automatic' property of [EMAIL PROTECTED]
  +     * UploadService}.
  +     */
  +    public static boolean getAutomatic()
  +    {
  +        // Short circuit evaluation of the && operator!
  +        return isAvailable() && getService().getAutomatic();
  +    }
       /**
        * <p> Retrieves the value of 'size.max' property of [EMAIL PROTECTED]
        * UploadService}.
  
  
  
  1.5       +11 -2     
jakarta-turbine-2/src/java/org/apache/turbine/services/upload/UploadService.java
  
  Index: UploadService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/upload/UploadService.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- UploadService.java        12 Feb 2003 17:50:16 -0000      1.4
  +++ UploadService.java        28 Feb 2003 12:06:52 -0000      1.5
  @@ -131,7 +131,7 @@
        * request by calling [EMAIL PROTECTED] #parseRequest(HttpServletRequest,
               * ParameterParser, String) parseRequest} manually.
        */
  -    static final Boolean AUTOMATIC_DEFAULT = Boolean.FALSE;
  +    static final String AUTOMATIC_DEFAULT = "false";
   
       /**
        * The request parameter name for overriding 'repository' property
  @@ -222,4 +222,13 @@
        * @return The repository.
        */
       String getRepository();
  +
  +    /**
  +     * <p> Retrieves the value of 'automatic' property of [EMAIL PROTECTED]
  +     * UploadService}.
  +     *
  +     * @return The value of 'automatic' property of [EMAIL PROTECTED]
  +     * UploadService}.
  +     */
  +    boolean getAutomatic();
   }
  
  
  

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

Reply via email to