You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by br...@apache.org on 2007/01/17 18:43:02 UTC
svn commit: r497095 - in
/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor:
FormattingDateConvertor.java FormattingDateConvertorBuilder.java
Author: bruno
Date: Wed Jan 17 09:42:59 2007
New Revision: 497095
URL: http://svn.apache.org/viewvc?view=rev&rev=497095
Log:
formatting date convertor: added support for a new attribute timeStyle to be able to configure the time style preference (short, medium, ...) separate from the date style.
Modified:
cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java
cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertorBuilder.java
Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java?view=diff&rev=497095&r1=497094&r2=497095
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java (original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java Wed Jan 17 09:42:59 2007
@@ -48,6 +48,7 @@
public class FormattingDateConvertor implements Convertor {
/** See {@link #setStyle}. */
private int style;
+ private int timeStyle = -1;
/** See {@link #setVariant}. */
private String variant;
/** Locale-specific formatting patterns. */
@@ -98,15 +99,16 @@
protected SimpleDateFormat getDateFormat(Locale locale) {
SimpleDateFormat dateFormat = null;
+ int timeStyle = this.timeStyle != -1 ? this.timeStyle : style;
if (this.variant.equals(DATE)) {
//dateFormat = I18nSupport.getInstance().getDateFormat(style, locale);
dateFormat = (SimpleDateFormat)DateFormat.getDateInstance(style, locale);
} else if (this.variant.equals(TIME)) {
//dateFormat = I18nSupport.getInstance().getTimeFormat(style, locale);
- dateFormat = (SimpleDateFormat)DateFormat.getTimeInstance(style, locale);
+ dateFormat = (SimpleDateFormat)DateFormat.getTimeInstance(timeStyle, locale);
} else if (this.variant.equals(DATE_TIME)) {
//dateFormat = I18nSupport.getInstance().getDateTimeFormat(style, style, locale);
- dateFormat = (SimpleDateFormat)DateFormat.getDateTimeInstance(style, style, locale);
+ dateFormat = (SimpleDateFormat)DateFormat.getDateTimeInstance(style, timeStyle, locale);
}
String pattern = (String)localizedPatterns.get(locale);
@@ -134,6 +136,15 @@
*/
public void setStyle(int style) {
this.style = style;
+ }
+
+ /**
+ * Sets the style for times, if not specified it defaults to the same style as for dates.
+ *
+ * @param style one of the constants FULL, LONG, MEDIUM or SHORT defined in the {@link Date} class.
+ */
+ public void setTimeStyle(int style) {
+ this.timeStyle = style;
}
public void setVariant(String variant) {
Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertorBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertorBuilder.java?view=diff&rev=497095&r1=497094&r2=497095
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertorBuilder.java (original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertorBuilder.java Wed Jan 17 09:42:59 2007
@@ -38,16 +38,18 @@
String style = configElement.getAttribute("style");
if (!style.equals("")) {
- if (style.equals("short"))
- convertor.setStyle(DateFormat.SHORT);
- else if (style.equals("medium"))
- convertor.setStyle(DateFormat.MEDIUM);
- else if (style.equals("long"))
- convertor.setStyle(DateFormat.LONG);
- else if (style.equals("full"))
- convertor.setStyle(DateFormat.FULL);
- else
+ int parsedStyle = parseDateTimeStyle(style);
+ if (parsedStyle == -1)
throw new Exception("Invalid value \"" + style + "\" for style attribute at " + DomHelper.getLocation(configElement));
+ convertor.setStyle(parsedStyle);
+ }
+
+ String timeStyle = configElement.getAttribute("timeStyle");
+ if (!timeStyle.equals("")) {
+ int parsedStyle = parseDateTimeStyle(timeStyle);
+ if (parsedStyle == -1)
+ throw new Exception("Invalid value \"" + timeStyle + "\" for timeStyle attribute at " + DomHelper.getLocation(configElement));
+ convertor.setTimeStyle(parsedStyle);
}
String variant = configElement.getAttribute("variant");
@@ -90,5 +92,18 @@
}
return convertor;
+ }
+
+ private int parseDateTimeStyle(String style) {
+ if (style.equals("short"))
+ return DateFormat.SHORT;
+ else if (style.equals("medium"))
+ return DateFormat.MEDIUM;
+ else if (style.equals("long"))
+ return DateFormat.LONG;
+ else if (style.equals("full"))
+ return DateFormat.FULL;
+ else
+ return -1;
}
}