You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by nb...@apache.org on 2006/03/11 19:43:49 UTC
svn commit: r385127 -
/jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/generic/DateTool.java
Author: nbubna
Date: Sat Mar 11 10:43:48 2006
New Revision: 385127
URL: http://svn.apache.org/viewcvs?rev=385127&view=rev
Log:
make default date format configurable via toolbox definition
Modified:
jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/generic/DateTool.java
Modified: jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/generic/DateTool.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/generic/DateTool.java?rev=385127&r1=385126&r2=385127&view=diff
==============================================================================
--- jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/generic/DateTool.java (original)
+++ jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/generic/DateTool.java Sat Mar 11 10:43:48 2006
@@ -25,6 +25,7 @@
import java.util.Date;
import java.util.Calendar;
import java.util.Locale;
+import java.util.Map;
import java.util.TimeZone;
@@ -52,12 +53,11 @@
* <key>date</key>
* <scope>application</scope>
* <class>org.apache.velocity.tools.generic.DateTool</class>
+ * <parameter name="format" value="yyyy-M-d"/>
* </tool>
* </pre></p>
*
- * <p>This tool is entirely threadsafe, and has no instance members.
- * It may be used in any scope (request, session, or application).
- * As such, the methods are highly interconnected, and overriding
+ * <p>The methods of this tool are highly interconnected, and overriding
* key methods provides an easy way to create subclasses that use
* a non-default format, calendar, locale, or timezone.</p>
*
@@ -70,12 +70,19 @@
/**
* The default format to be used when none is specified.
- *
* @since VelocityTools 1.1
*/
public static final String DEFAULT_FORMAT = "default";
/**
+ * The key used for specifying a default format via toolbox params.
+ * @since VelocityTools 1.3
+ */
+ public static final String DEFAULT_FORMAT_KEY = "format";
+
+ private String format = DEFAULT_FORMAT;
+
+ /**
* Default constructor.
*/
public DateTool()
@@ -83,6 +90,21 @@
// do nothing
}
+ /**
+ * Looks for a default format value in the given params.
+ * @since VelocityTools 1.3
+ */
+ public void configure(Map params)
+ {
+ ValueParser parser = new ValueParser(params);
+ String format = parser.getString(DEFAULT_FORMAT_KEY);
+ if (format != null)
+ {
+ setFormat(format);
+ }
+ }
+
+
// ------------------------- system date access ------------------
@@ -168,18 +190,28 @@
* is specified. This implementation gives a 'default' date-time format.
* Subclasses may override this to provide a different default format.
*
- * <p>NOTE: At some point in the future it may be feasible to configure
- * this value via the toolbox definition, but at present, it is not possible
- * to specify custom tool configurations there. For now you should just
- * override this in a subclass to have a different default.</p>
+ * <p>This can now be configured via the toolbox definition.
+ * Add a <code><parameter name="format" value="short"/><code>
+ * to your date tool configuration.</p>
*
* @since VelocityTools 1.1
*/
public String getFormat()
{
- return DEFAULT_FORMAT;
+ return format;
}
+ /**
+ * Sets the default format for this instance. This is protected,
+ * because templates ought not to be using it; hat would not
+ * be threadsafe so far as templates are concerned.
+ *
+ * @since VelocityTools 1.3
+ */
+ protected void setFormat(String format)
+ {
+ this.format = format;
+ }
// ------------------------- date value access ---------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org