[jboss-svn-commits] JBL Code SVN: r5603 - labs/kosmos/trunk/src/java/hu/midori/kosmos/portlet/taglib
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Aug 8 11:27:05 EDT 2006
Author: aron.gombas
Date: 2006-08-08 11:27:03 -0400 (Tue, 08 Aug 2006)
New Revision: 5603
Modified:
labs/kosmos/trunk/src/java/hu/midori/kosmos/portlet/taglib/AgeTag.java
Log:
Fix for getting the locale as Locale, not as String from pageContext
Modified: labs/kosmos/trunk/src/java/hu/midori/kosmos/portlet/taglib/AgeTag.java
===================================================================
--- labs/kosmos/trunk/src/java/hu/midori/kosmos/portlet/taglib/AgeTag.java 2006-08-08 14:57:05 UTC (rev 5602)
+++ labs/kosmos/trunk/src/java/hu/midori/kosmos/portlet/taglib/AgeTag.java 2006-08-08 15:27:03 UTC (rev 5603)
@@ -30,30 +30,42 @@
private String time;
/** Localized string resources. */
private static ResourceBundle res;
-
+
/** Sets the millisecond of the "birth" value used for computing the age. */
public void setTime(String time) {
this.time = time;
}
@Override
- public int doStartTag() throws JspException {
- res = ResourceBundle.getBundle("kosmos-taglib", new Locale((String)Config.find(pageContext, Config.FMT_LOCALE)));
+ public int doStartTag() throws JspException {
+ // get locale
+ Locale locale = null;
+ Object localeDefinition = Config.find(pageContext, Config.FMT_LOCALE);
+ if(localeDefinition.getClass().getName().equals(String.class.getName()))// FIXME should we use "instanceof"?
+ locale = new Locale((String) localeDefinition);
+ else if(localeDefinition.getClass().getName().equals(Locale.class.getName()))
+ locale = (Locale) localeDefinition;
+ else
+ return SKIP_BODY;
+
+ res = ResourceBundle.getBundle("kosmos-taglib", locale);
+
+ // convert
long milliseconds = Long.parseLong(time);
long value = 0;
String unit = null;
- long minutes = milliseconds / (60*1000);
+ long minutes = milliseconds / (60*1000);
if(minutes < 2*60) {
value = minutes;
unit = res.getString("age.minutes");
- } else {
+ } else {
long hours = minutes / 60;
if(hours < 48) {
value = hours;
unit = res.getString("age.hours");
- } else {
+ } else {
long days = hours / 24;
if(days < 3*7) {
value = days;
@@ -67,22 +79,22 @@
long months = days / 30;
if(months < 24) {
value = months;
- unit = res.getString("age.months");
- } else {
- value = months / 12;
+ unit = res.getString("age.months");
+ } else {
+ value = months / 12;
unit = res.getString("age.years");
}
}
}
}
}
-
+
try {
pageContext.getOut().print(String.format("%s %s", NumberFormat.getIntegerInstance().format(value), unit));
} catch(IOException ex) {
throw new JspException(ex);
}
-
+
return SKIP_BODY;
}
}
More information about the jboss-svn-commits
mailing list