Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SEAMINTL-8 Support JDK TimeZone in addition to Joda DateTimeZone
Add support for JDK TimeZone classes and provide a clearer distinction between it and Joda DateTimeZone classes
- Loading branch information
1 parent
0d9544a
commit b1861af
Showing
25 changed files
with
1,015 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
api/src/main/java/org/jboss/seam/international/jdktimezone/ForwardingTimeZone.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.seam.international.jdktimezone; | ||
|
||
import java.util.Date; | ||
import java.util.Locale; | ||
import java.util.TimeZone; | ||
|
||
/** | ||
* Delegating TimeZone. | ||
* | ||
* @author Ken Finnigan | ||
*/ | ||
public abstract class ForwardingTimeZone extends TimeZone | ||
{ | ||
/** | ||
* Abstract getter for the delegate | ||
* | ||
* @return The delegate | ||
*/ | ||
protected abstract TimeZone delegate(); | ||
|
||
protected ForwardingTimeZone(String id) | ||
{ | ||
super(); | ||
setID(id); | ||
} | ||
|
||
@Override | ||
public int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds) | ||
{ | ||
return delegate().getOffset(era, year, month, day, dayOfWeek, milliseconds); | ||
} | ||
|
||
@Override | ||
public int getOffset(long date) | ||
{ | ||
return delegate().getOffset(date); | ||
} | ||
|
||
@Override | ||
public int getRawOffset() | ||
{ | ||
return delegate().getRawOffset(); | ||
} | ||
|
||
@Override | ||
public String getID() | ||
{ | ||
return delegate().getID(); | ||
} | ||
|
||
@Override | ||
public String getDisplayName(boolean daylight, int style, Locale locale) | ||
{ | ||
return delegate().getDisplayName(daylight, style, locale); | ||
} | ||
|
||
@Override | ||
public int getDSTSavings() | ||
{ | ||
return delegate().getDSTSavings(); | ||
} | ||
|
||
@Override | ||
public boolean useDaylightTime() | ||
{ | ||
return delegate().useDaylightTime(); | ||
} | ||
|
||
@Override | ||
public boolean inDaylightTime(Date date) | ||
{ | ||
return delegate().inDaylightTime(date); | ||
} | ||
|
||
@Override | ||
public boolean hasSameRules(TimeZone other) | ||
{ | ||
return delegate().hasSameRules(other); | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return delegate().hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) | ||
{ | ||
return delegate().equals(obj); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return delegate().toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
impl/src/main/java/org/jboss/seam/international/datetimezone/AvailableDateTimeZones.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.seam.international.datetimezone; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Produces; | ||
|
||
import org.jboss.seam.international.datetimezone.ForwardingDateTimeZone; | ||
import org.joda.time.DateTimeZone; | ||
|
||
/** | ||
* <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 | ||
*/ | ||
@ApplicationScoped | ||
public class AvailableDateTimeZones | ||
{ | ||
private static final String TIMEZONE_ID_PREFIXES = "^(Africa|America|Asia|Atlantic|Australia|Europe|Indian|Pacific)/.*"; | ||
|
||
@Produces | ||
private List<ForwardingDateTimeZone> dateTimeZones = null; | ||
|
||
@SuppressWarnings("unchecked") | ||
@PostConstruct | ||
public void init() | ||
{ | ||
dateTimeZones = new ArrayList<ForwardingDateTimeZone>(); | ||
final Set timeZoneIds = DateTimeZone.getAvailableIDs(); | ||
for (Object object : timeZoneIds) | ||
{ | ||
String id = (String) object; | ||
if (id.matches(TIMEZONE_ID_PREFIXES)) | ||
{ | ||
final DateTimeZone dtz = DateTimeZone.forID(id); | ||
dateTimeZones.add(new ForwardingDateTimeZone(id) | ||
{ | ||
@Override | ||
protected DateTimeZone delegate() | ||
{ | ||
return dtz; | ||
} | ||
}); | ||
} | ||
} | ||
Collections.sort(dateTimeZones, new Comparator<ForwardingDateTimeZone>() | ||
{ | ||
public int compare(final ForwardingDateTimeZone a, final ForwardingDateTimeZone b) | ||
{ | ||
return a.getID().compareTo(b.getID()); | ||
} | ||
}); | ||
dateTimeZones = Collections.unmodifiableList(dateTimeZones); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
.../src/main/java/org/jboss/seam/international/datetimezone/DefaultDateTimeZoneProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.seam.international.datetimezone; | ||
|
||
import java.io.Serializable; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Instance; | ||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
|
||
import org.jboss.logging.Logger; | ||
import org.jboss.seam.international.datetimezone.ForwardingDateTimeZone; | ||
import org.jboss.seam.international.timezone.DefaultTimeZoneConfig; | ||
import org.joda.time.DateTimeZone; | ||
|
||
/** | ||
* Default DateTimeZone of the application. If configuration of the default DateTimeZone is found that will be used, otherwise | ||
* the JVM default TimeZone. | ||
* | ||
* @author Ken Finnigan | ||
*/ | ||
|
||
@ApplicationScoped | ||
public class DefaultDateTimeZoneProducer implements Serializable | ||
{ | ||
private static final long serialVersionUID = 6181892144731122500L; | ||
|
||
@Inject | ||
@DefaultTimeZoneConfig | ||
private Instance<String> defaultTimeZoneId; | ||
|
||
private final Logger log = Logger.getLogger(DefaultDateTimeZoneProducer.class); | ||
|
||
@Produces | ||
@Named | ||
private DateTimeZone defaultDateTimeZone = null; | ||
|
||
@PostConstruct | ||
public void init() | ||
{ | ||
if (!defaultTimeZoneId.isUnsatisfied()) | ||
{ | ||
try | ||
{ | ||
String id = defaultTimeZoneId.get(); | ||
DateTimeZone dtz = DateTimeZone.forID(id); | ||
defaultDateTimeZone = constructTimeZone(dtz); | ||
} | ||
catch (IllegalArgumentException e) | ||
{ | ||
log.warn("DefaultDateTimeZoneProducer: Default TimeZone Id of " + defaultTimeZoneId + " was not found"); | ||
} | ||
} | ||
if (null == defaultDateTimeZone) | ||
{ | ||
DateTimeZone dtz = DateTimeZone.getDefault(); | ||
defaultDateTimeZone = constructTimeZone(dtz); | ||
} | ||
} | ||
|
||
private ForwardingDateTimeZone constructTimeZone(final DateTimeZone dtz) | ||
{ | ||
return new ForwardingDateTimeZone(dtz.getID()) | ||
{ | ||
@Override | ||
protected DateTimeZone delegate() | ||
{ | ||
return dtz; | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.