You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by se...@apache.org on 2003/11/10 04:49:37 UTC
cvs commit: jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/validator DateStringValidator.java
seade 2003/11/09 19:49:37
Modified: intake/xdocs changes.xml
intake/src/java/org/apache/fulcrum/intake/model Field.java
intake/src/java/org/apache/fulcrum/intake/validator
DateStringValidator.java
Log:
Porting changes from Turbine:
Intake now provides $group.foo.StringValue which DateStrng uses to provide the formatted date Strng value.
DateString will use the "formatn" (where n >= 1) rules to parse the input and then the "format" rule to format it.
Thanks to Colin Chalmers for contributing to this patch.
Revision Changes Path
1.4 +10 -0 jakarta-turbine-fulcrum/intake/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/intake/xdocs/changes.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- changes.xml 16 Oct 2003 12:26:55 -0000 1.3
+++ changes.xml 10 Nov 2003 03:49:37 -0000 1.4
@@ -3,6 +3,7 @@
<properties>
<title>Fulcrum Intake</title>
<author email="epugh@upstate.com">Eric Pugh</author>
+ <author email="seade@backstagetech.com.au">Scott Eade</author>
</properties>
<body>
@@ -20,6 +21,15 @@
rules no longer attempt to execute the remaining rules when no
input is provided. A minLength > 0 rule is no longer synonymous
with required=true. Patch originally supplied by Colin Chalmers
+ </action>
+ <action dev="seade" type="fix">
+ Intake was fixed so that DateString will use the "formatn" (where n
+ >= 1) rules to parse the input and then the "format" rule to format
+ it (the "format" rule is also used to parse the date if there are no
+ "formatn" rules or they are not able to parse it). In order to
+ retrieve the correctly formatted DateString value you need to use
+ <em>$group.foo.StringValue</em> rather than <em>$group.foo.Value</em>
+ (you can do this for all values, not just DateString).
</action>
</release>
1.3 +16 -1 jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/model/Field.java
Index: Field.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/model/Field.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Field.java 26 Sep 2003 16:32:32 -0000 1.2
+++ Field.java 10 Nov 2003 03:49:37 -0000 1.3
@@ -995,4 +995,19 @@
return (StringUtils.isEmpty(maxSize) ? "" : maxSize);
}
+ /**
+ * Gets the String representation of the Value. This is basically a wrapper
+ * method for the toString method which doesn't seem to show anything on
+ * screen if accessed from Template. Name is also more in line with getValue
+ * method which returns the actual Object.
+ * This is useful for displaying correctly formatted data such as dates,
+ * such as 18/11/1968 instead of the toString dump of a Date Object.
+ *
+ * @return the String Value
+ */
+ public String getStringValue()
+ {
+ return this.toString();
+ }
+
}
1.2 +23 -6 jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/validator/DateStringValidator.java
Index: DateStringValidator.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/validator/DateStringValidator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DateStringValidator.java 26 Sep 2003 13:52:25 -0000 1.1
+++ DateStringValidator.java 10 Nov 2003 03:49:37 -0000 1.2
@@ -77,7 +77,7 @@
* <td> </td></tr>
* <tr><td>formatx</td><td>see SimpleDateFormat javadoc</td>
* <td> </td></tr>
- * <tr><td colspan=3>where x is >= 0 to specify multiple date
+ * <tr><td colspan=3>where x is >= 1 to specify multiple date
* formats. Only one format rule should have a message</td></tr>
* <tr><td>flexible</td><td>true, as long as DateFormat can parse the date,
* allow it, and false</td>
@@ -88,6 +88,7 @@
* @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
* @author <a href="mailto:Colin.Chalmers@maxware.nl">Colin Chalmers</a>
* @author <a href="mailto:jh@byteaction.de">Jürgen Hoffmann</a>
+* @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
* @version $Id$
*/
public class DateStringValidator
@@ -155,7 +156,7 @@
dateFormats.add(constraint.getValue());
setDateFormatMessage(constraint.getMessage());
- }
+ }
if (StringUtils.isEmpty(dateFormatMessage))
{
@@ -209,8 +210,11 @@
}
/**
- * Parses the String s according to the rules/formats for this
- * validator.
+ * Parses the String s according to the rules/formats for this validator.
+ * The formats provided by the "formatx" rules (where x is >= 1) are
+ * used <strong>before</strong> the "format" rules to allow for a display
+ * format that includes a 4 digit year, but that will parse the date using
+ * a format that accepts 2 digit years.
*
* @throws ParseException indicates that the string could not be
* parsed into a date.
@@ -225,7 +229,7 @@
throw new ParseException("Input string was null", -1);
}
- for (int i = 0; i < dateFormats.size() && date == null; i++)
+ for (int i = 1; i < dateFormats.size() && date == null; i++)
{
sdf.applyPattern((String) dateFormats.get(i));
@@ -237,7 +241,20 @@
{
// ignore
}
+ }
+
+ if (date == null)
+ {
+ sdf.applyPattern((String) dateFormats.get(0));
+ try
+ {
+ date = sdf.parse(s);
+ }
+ catch (ParseException e)
+ {
+ // ignore
+ }
}
if (date == null && df != null)
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org