[seam-commits] Seam SVN: r10214 - in trunk/src/main/org/jboss/seam: international and 1 other directory.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Wed Mar 25 17:32:35 EDT 2009
Author: dan.j.allen
Date: 2009-03-25 17:32:34 -0400 (Wed, 25 Mar 2009)
New Revision: 10214
Added:
trunk/src/main/org/jboss/seam/international/TimeZoneWrapper.java
trunk/src/main/org/jboss/seam/international/TimeZones.java
Modified:
trunk/src/main/org/jboss/seam/international-2.1.xsd
Log:
JBSEAM-3089
Added: trunk/src/main/org/jboss/seam/international/TimeZoneWrapper.java
===================================================================
--- trunk/src/main/org/jboss/seam/international/TimeZoneWrapper.java (rev 0)
+++ trunk/src/main/org/jboss/seam/international/TimeZoneWrapper.java 2009-03-25 21:32:34 UTC (rev 10214)
@@ -0,0 +1,102 @@
+package com.jboss.seam.international;
+
+import java.util.Date;
+import java.util.TimeZone;
+
+/**
+ * A wrapper around a TimeZone that provides a more convenience interface to
+ * access the time zone information in the UI, in particular in the options of
+ * a select menu.
+ *
+ * @author Dan Allen
+ */
+public class TimeZoneWrapper extends TimeZone
+{
+ private static final int MILLISECONDS_PER_HOUR = 1000 * 60 * 60;
+
+ private TimeZone timeZone;
+
+ public TimeZoneWrapper(TimeZone tz) {
+ timeZone = tz;
+ setID(tz.getID());
+ }
+
+ @Override
+ public void setID(String id) {
+ super.setID(id);
+ timeZone = TimeZone.getTimeZone(id);
+ }
+
+ public String getId() {
+ return timeZone.getID();
+ }
+
+ public String getLabel() {
+ StringBuilder label = new StringBuilder(50);
+ label.append(getId().replace("_", " "));
+ label.append(" (GMT");
+ label.append(timeZone.getRawOffset() > 0 ? "+" : "-");
+ if (Math.abs(timeZone.getRawOffset()) < MILLISECONDS_PER_HOUR * 10) {
+ label.append("0");
+ }
+ label.append(Math.abs(timeZone.getRawOffset())/MILLISECONDS_PER_HOUR);
+ label.append(":00)");
+ return label.toString();
+ }
+
+ public TimeZone getTimeZone() {
+ return timeZone;
+ }
+
+ @Override
+ public int getOffset(int era, int year, int month, int day, int dayOfWeek, int millis) {
+ return timeZone.getOffset(era, year, month, day, dayOfWeek, millis);
+ }
+
+ @Override
+ public void setRawOffset(int offset) {
+ timeZone.setRawOffset(offset);
+ }
+
+ @Override
+ public int getRawOffset() {
+ return timeZone.getRawOffset();
+ }
+
+ @Override
+ public boolean useDaylightTime() {
+ return timeZone.useDaylightTime();
+ }
+
+ @Override
+ public boolean inDaylightTime(Date date) {
+ return timeZone.inDaylightTime(date);
+ }
+
+ @Override
+ public Object clone() {
+ return timeZone.clone();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final TimeZoneWrapper other = (TimeZoneWrapper) obj;
+ if (timeZone != other.timeZone && (timeZone == null || !timeZone.equals(other.timeZone))) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 7;
+ hash = 79 * hash + (timeZone != null ? timeZone.hashCode() : 0);
+ return hash;
+ }
+}
Added: trunk/src/main/org/jboss/seam/international/TimeZones.java
===================================================================
--- trunk/src/main/org/jboss/seam/international/TimeZones.java (rev 0)
+++ trunk/src/main/org/jboss/seam/international/TimeZones.java 2009-03-25 21:32:34 UTC (rev 10214)
@@ -0,0 +1,71 @@
+package com.jboss.seam.international;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.TimeZone;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.Unwrap;
+import org.jboss.seam.annotations.Create;
+
+/**
+ * <p>Seam component that provides a list of time zones, limited to time zones
+ * with IDs in the form Continent/Place, excluding deprecated three-letter time
+ * zone IDs. The time zones returned have a fixed offset from UTC, which takes
+ * daylight savings time into account. For example, Europe/Amsterdam is UTC+1;
+ * in winter this is GMT+1 and in summer GMT+2.</p>
+ *
+ * <p>The time zone objects returned are wrapped in an implementation of
+ * TimeZone that provides a more friendly interface for accessing the time zone
+ * information. In particular, this type provides a more bean-friend property
+ * for the time zone id (id than ID) and provides a convenience property named
+ * label that formats the time zone for display in the UI. This wrapper can be
+ * disabled by setting the component property wrap to false.</p>
+ *
+ * @author Peter Hilton, Lunatech Research
+ * @author Dan Allen
+ */
+ at Scope(ScopeType.APPLICATION)
+ at Name("org.jboss.seam.international.timeZones")
+public class TimeZones
+{
+ private static final String TIMEZONE_ID_PREFIXES =
+ "^(Africa|America|Asia|Atlantic|Australia|Europe|Indian|Pacific)/.*";
+
+ private boolean wrap = true;
+
+ private List<TimeZone> timeZones = null;
+
+ @Create
+ public void init() {
+ timeZones = new ArrayList<TimeZone>();
+ final String[] timeZoneIds = TimeZone.getAvailableIDs();
+ for (final String id : timeZoneIds) {
+ if (id.matches(TIMEZONE_ID_PREFIXES)) {
+ timeZones.add(wrap ? new TimeZoneWrapper(TimeZone.getTimeZone(id)) : TimeZone.getTimeZone(id));
+ }
+ }
+ Collections.sort(timeZones, new Comparator<TimeZone>() {
+ public int compare(final TimeZone a, final TimeZone b) {
+ return a.getID().compareTo(b.getID());
+ }
+ });
+ }
+
+ @Unwrap
+ public List<TimeZone> getTimeZones() {
+ return timeZones;
+ }
+
+ public boolean isWrap() {
+ return wrap;
+ }
+
+ public void setWrap(boolean wrap) {
+ this.wrap = wrap;
+ }
+}
Modified: trunk/src/main/org/jboss/seam/international-2.1.xsd
===================================================================
--- trunk/src/main/org/jboss/seam/international-2.1.xsd 2009-03-25 19:44:41 UTC (rev 10213)
+++ trunk/src/main/org/jboss/seam/international-2.1.xsd 2009-03-25 21:32:34 UTC (rev 10214)
@@ -56,4 +56,17 @@
<xs:attribute name="cookie-enabled" type="components:boolean" />
</xs:attributeGroup>
+ <xs:element name="time-zones">
+ <xs:annotation>
+ <xs:documentation>The time zones provider component</xs:documentation>
+ </xs:annotation>
+ <xs:complexType mixed="true">
+ <xs:attributeGroup ref="components:attlist.component"/>
+ <xs:attributeGroup ref="international:attlist.timeZones"/>
+ </xs:complexType>
+ </xs:element>
+ <xs:attributeGroup name="attlist.timeZones">
+ <xs:attribute name="wrap" type="components:boolean" />
+ </xs:attributeGroup>
+
</xs:schema>
More information about the seam-commits
mailing list