You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by he...@apache.org on 2003/02/28 13:06:52 UTC
cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/services/upload BaseUploadService.java TurbineUpload.java UploadService.java
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 {@link
+ * UploadService}. This reports whether the Parameter parser
+ * should allow "automatic" uploads if it is submitted to
+ * Turbine.
+ *
+ * @return The value of 'automatic' property of {@link
+ * 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 {@link
- * 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 {@link
- * 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 {@link
+ * 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 {@link
+ * UploadService}.
+ */
+ public static boolean getAutomatic()
+ {
+ // Short circuit evaluation of the && operator!
+ return isAvailable() && getService().getAutomatic();
+ }
/**
* <p> Retrieves the value of 'size.max' property of {@link
* 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 {@link #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 {@link
+ * UploadService}.
+ *
+ * @return The value of 'automatic' property of {@link
+ * UploadService}.
+ */
+ boolean getAutomatic();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org
Re: cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/services/upload BaseUploadService.java TurbineUpload.java UploadService.java
Posted by "Henning P. Schmiedehausen" <hp...@intermeta.de>.
henning@apache.org writes:
> +import org.apache.turbine.services.InstantiationException;
[...]
> - catch (org.apache.turbine.services.InstantiationException ie)
> + catch (InstantiationException ie)
Quinton, idid you do the style cleanups with some IDE (JBuilder?)?
If yes, please make sure that the import threshold is set to "first
usage". We always import all needed classes unless there is a name
clash everywhere in the code base and starting to use fully qualified
names in the code without good reason isn't necessary IMHO.
Regards
Henning
--
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen INTERMETA GmbH
hps@intermeta.de +49 9131 50 654 0 http://www.intermeta.de/
Java, perl, Solaris, Linux, xSP Consulting, Web Services
freelance consultant -- Jakarta Turbine Development -- hero for hire
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org