Date, Time und DateTime

* Korrektur für Time.java, wodurch für ein Time-Widget kein korrektes bebop-Tag erzeugt wurde
 * XML-Formatter für Date, Time und DateTime verwenden nun die DispatcherHelper.getNegotiatedLocale()-Methode

git-svn-id: https://svn.libreccm.org/ccm/trunk@798 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2011-03-26 19:11:20 +00:00
parent f2a7fb18c6
commit e65baec411
4 changed files with 31 additions and 39 deletions

View File

@ -250,7 +250,7 @@ public class Time extends Widget implements BebopConstants {
/** The XML tag for this derived class of Widget. */ /** The XML tag for this derived class of Widget. */
@Override @Override
protected String getElementTag() { protected String getElementTag() {
return "BEBOP_TIME"; return BEBOP_TIME;
} }
@Override @Override

View File

@ -18,7 +18,7 @@
*/ */
package com.arsdigita.xml.formatters; package com.arsdigita.xml.formatters;
import com.arsdigita.kernel.Kernel; import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.xml.Formatter; import com.arsdigita.xml.Formatter;
import java.util.Locale; import java.util.Locale;
import java.util.Date; import java.util.Date;
@ -28,6 +28,9 @@ import java.text.DateFormat;
* An alternate formatter for java.util.Date objects, * An alternate formatter for java.util.Date objects,
* outputing the date in 'medium' format. The time * outputing the date in 'medium' format. The time
* is ommitted. * is ommitted.
*
* @author unkknown
* @author Sören Bernstein
*/ */
public class DateFormatter implements Formatter { public class DateFormatter implements Formatter {
@ -41,20 +44,12 @@ public class DateFormatter implements Formatter {
return m_config; return m_config;
} }
@Override
public String format(Object value) { public String format(Object value) {
Date date = (Date)value; Date date = (Date)value;
Locale locale; Locale locale = DispatcherHelper.getNegotiatedLocale();
if (getConfig().getLocale() != null) {
locale = new Locale(m_config.getLocale());
} else {
locale = Kernel.getContext().getLocale();
}
if (locale == null) {
locale = Locale.ENGLISH;
}
DateFormat format = DateFormat.getDateInstance DateFormat format = DateFormat.getDateInstance
(DateFormat.MEDIUM, locale); (DateFormat.MEDIUM, locale);

View File

@ -18,7 +18,7 @@
*/ */
package com.arsdigita.xml.formatters; package com.arsdigita.xml.formatters;
import com.arsdigita.kernel.Kernel; import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.xml.Formatter; import com.arsdigita.xml.Formatter;
import java.util.Locale; import java.util.Locale;
import java.util.Date; import java.util.Date;
@ -27,21 +27,17 @@ import java.text.DateFormat;
/** /**
* The default formatter for java.util.Date objects, outputing the date in * The default formatter for java.util.Date objects, outputing the date in
* 'medium' format and the time in 'short' format. * 'medium' format and the time in 'short' format.
*
* @author unknown
* @author Sören Bernstein
*/ */
public class DateTimeFormatter implements Formatter { public class DateTimeFormatter implements Formatter {
@Override
public String format(Object value) { public String format(Object value) {
Date date = (Date)value; Date date = (Date) value;
Locale locale; Locale locale = DispatcherHelper.getNegotiatedLocale();
DateFormatterConfig dfc = DateFormatter.getConfig();
if (dfc.getLocale() != null) {
locale = new Locale(dfc.getLocale());
} else {
locale = Kernel.getContext().getLocale();
}
if (locale == null) {
locale = Locale.ENGLISH;
}
DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
DateFormat.SHORT, locale); DateFormat.SHORT, locale);

View File

@ -18,7 +18,7 @@
*/ */
package com.arsdigita.xml.formatters; package com.arsdigita.xml.formatters;
import com.arsdigita.kernel.Kernel; import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.xml.Formatter; import com.arsdigita.xml.Formatter;
import java.util.Locale; import java.util.Locale;
import java.util.Date; import java.util.Date;
@ -28,18 +28,19 @@ import java.text.DateFormat;
* An alternate formatter for java.util.Date objects, * An alternate formatter for java.util.Date objects,
* outputing the date in 'medium' format. The time * outputing the date in 'medium' format. The time
* is ommitted. * is ommitted.
*
* @author unknown
* @author Sören Bernstein
*/ */
public class TimeFormatter implements Formatter { public class TimeFormatter implements Formatter {
@Override
public String format(Object value) { public String format(Object value) {
Date date = (Date)value; Date date = (Date) value;
Locale locale = Kernel.getContext().getLocale(); Locale locale = DispatcherHelper.getNegotiatedLocale();
if (locale == null) {
locale = Locale.ENGLISH; DateFormat format = DateFormat.getTimeInstance(DateFormat.SHORT, locale);
}
DateFormat format = DateFormat.getTimeInstance
(DateFormat.SHORT, locale);
return format.format(date); return format.format(date);
} }