svn commit: r1078818 - in /lenya/branches/BRANCH_2_1_X/src: java/org/apache/lenya/cms/cocoon/components/modules/input/DateConverterModule.java webapp/lenya/config/cocoon-xconf/input-modules/date-iso8601-rfc822.xconf
[email protected] Mon, 07 Mar 2011 15:50:08 -0000
| Newsgroups | gmane.comp.cms.lenya.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: andreas
Date: Mon Mar 7 15:50:08 2011
New Revision: 1078818
URL: http://svn.apache.org/viewvc?rev=1078818&view=rev
Log:
Set locale for DateConverterModule.
Modified:
lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DateConverterModule.java
lenya/branches/BRANCH_2_1_X/src/webapp/lenya/config/cocoon-xconf/input-modules/date-iso8601-rfc822.xconf
Modified: lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DateConverterModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DateConverterModule.java?rev=1078818&r1=1078817&r2=1078818&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DateConverterModule.java (original)
+++ lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DateConverterModule.java Mon Mar 7 15:50:08 2011
@@ -19,46 +19,52 @@ package org.apache.lenya.cms.cocoon.comp
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Locale;
import java.util.Map;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.components.modules.input.AbstractInputModule;
+import org.apache.commons.lang.LocaleUtils;
/**
- * The DateConverterModule converts a date string from one format into
- * another format.
- * The conversion is defined by the nested elements <src-pattern/> and
- * <pattern/> of the module declaration.
- *
+ * The DateConverterModule converts a date string from one format into another format. The
+ * conversion is defined by the nested elements <src-pattern/> and <pattern/> of the
+ * module declaration.
+ *
*/
public class DateConverterModule extends AbstractInputModule implements ThreadSafe {
- public Object getAttribute(String name, Configuration modeConf, Map objectModel) throws ConfigurationException {
-
+ public Object getAttribute(String name, Configuration modeConf,
+ @SuppressWarnings("rawtypes") Map objectModel) throws ConfigurationException {
+
String srcPattern = (String) this.settings.get("src-pattern");
String pattern = (String) this.settings.get("pattern");
-
+ String locale = (String) this.settings.get("locale");
+
if (modeConf != null) {
srcPattern = modeConf.getChild("src-pattern").getValue(srcPattern);
pattern = modeConf.getChild("pattern").getValue(pattern);
+ locale = modeConf.getChild("locale").getValue(locale);
}
- if (srcPattern==null) {
+ if (srcPattern == null) {
throw new ConfigurationException("Source date pattern not specified.");
}
- if (pattern==null) {
+ if (pattern == null) {
throw new ConfigurationException("Date pattern not specified.");
}
-
+
try {
- SimpleDateFormat srcFormat = new SimpleDateFormat(srcPattern);
- SimpleDateFormat format = new SimpleDateFormat(pattern);
+ final SimpleDateFormat srcFormat = new SimpleDateFormat(srcPattern);
+ final Locale loc = (locale == null) ? Locale.getDefault() : LocaleUtils
+ .toLocale(locale);
+ final SimpleDateFormat format = new SimpleDateFormat(pattern, loc);
Date date = srcFormat.parse(name);
return format.format(date);
} catch (Exception e) {
- throw new ConfigurationException("Could not convert date: "+name, e);
+ throw new ConfigurationException("Could not convert date: " + name, e);
}
}
}
Modified: lenya/branches/BRANCH_2_1_X/src/webapp/lenya/config/cocoon-xconf/input-modules/date-iso8601-rfc822.xconf
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/webapp/lenya/config/cocoon-xconf/input-modules/date-iso8601-rfc822.xconf?rev=1078818&r1=1078817&r2=1078818&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/webapp/lenya/config/cocoon-xconf/input-modules/date-iso8601-rfc822.xconf (original)
+++ lenya/branches/BRANCH_2_1_X/src/webapp/lenya/config/cocoon-xconf/input-modules/date-iso8601-rfc822.xconf Mon Mar 7 15:50:08 2011
@@ -16,14 +16,10 @@
limitations under the License.
-->
-<!-- $Id: usecases-workflow-deactivate.xconf 348547 2005-11-23 20:13:01Z chestnut $ -->
-<!--
- This file defines the publication specific use-cases
--->
-
<xconf xpath="/cocoon/input-modules" unless="/cocoon/input-modules/component-instance[@name = 'date-iso8601-rfc822']">
<component-instance name="date-iso8601-rfc822" logger="core.modules.input" class="org.apache.lenya.cms.cocoon.components.modules.input.DateConverterModule">
<src-pattern>yyyy-MM-dd HH:mm:ss Z</src-pattern>
- <pattern>EEE, dd MMM yyyy HH:mm:ss Z</pattern>
+ <pattern>EEE, d MMM yyyy HH:mm:ss Z</pattern>
+ <locale>en_US</locale>
</component-instance>
</xconf>