org.apache.poi.util
Class LocaleUtil

java.lang.Object
  extended by org.apache.poi.util.LocaleUtil

public final class LocaleUtil
extends java.lang.Object

This utility class is used to set locale and time zone settings beside of the JDK internal Locale.setDefault(Locale) and TimeZone.setDefault(TimeZone) methods, because the locale/time zone specific handling of certain office documents - maybe for different time zones / locales ... - shouldn't affect other java components. The settings are saved in a ThreadLocal, so they only apply to the current thread and can't be set globally.


Field Summary
static java.nio.charset.Charset CHARSET_1252
          Default encoding for unknown byte encodings of native files (at least it's better than to rely on a platform dependent encoding for legacy stuff ...)
static java.util.TimeZone TIMEZONE_UTC
          Excel doesn't store TimeZone information in the file, so if in doubt, use UTC to perform calculations
 
Method Summary
static java.util.Calendar getLocaleCalendar()
           
static java.util.Calendar getLocaleCalendar(int year, int month, int day)
          Convenience method - month is 0-based as in java.util.Calendar
static java.util.Calendar getLocaleCalendar(int year, int month, int day, int hour, int minute, int second)
          Convenience method - month is 0-based as in java.util.Calendar
static java.util.Calendar getLocaleCalendar(java.util.TimeZone timeZone)
           
static java.lang.String getLocaleFromLCID(int lcid)
          Decode the language ID from LCID value
static java.util.Locale getUserLocale()
           
static java.util.TimeZone getUserTimeZone()
           
static void resetUserLocale()
           
static void resetUserTimeZone()
          Clear the thread-local user time zone.
static void setUserLocale(java.util.Locale locale)
          Sets default user locale.
static void setUserTimeZone(java.util.TimeZone timezone)
          As time zone information is not stored in any format, it can be set before any date calculations take place.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIMEZONE_UTC

public static final java.util.TimeZone TIMEZONE_UTC
Excel doesn't store TimeZone information in the file, so if in doubt, use UTC to perform calculations


CHARSET_1252

public static final java.nio.charset.Charset CHARSET_1252
Default encoding for unknown byte encodings of native files (at least it's better than to rely on a platform dependent encoding for legacy stuff ...)

Method Detail

setUserTimeZone

public static void setUserTimeZone(java.util.TimeZone timezone)
As time zone information is not stored in any format, it can be set before any date calculations take place. This setting is specific to the current thread.

Parameters:
timezone - the timezone under which date calculations take place

getUserTimeZone

public static java.util.TimeZone getUserTimeZone()
Returns:
the time zone which is used for date calculations. If not set, returns TimeZone.getDefault().

resetUserTimeZone

public static void resetUserTimeZone()
Clear the thread-local user time zone.


setUserLocale

public static void setUserLocale(java.util.Locale locale)
Sets default user locale. This setting is specific to the current thread.


getUserLocale

public static java.util.Locale getUserLocale()
Returns:
the default user locale. If not set, returns Locale.getDefault().

resetUserLocale

public static void resetUserLocale()

getLocaleCalendar

public static java.util.Calendar getLocaleCalendar()
Returns:
a calendar for the user locale and time zone

getLocaleCalendar

public static java.util.Calendar getLocaleCalendar(int year,
                                                   int month,
                                                   int day)
Convenience method - month is 0-based as in java.util.Calendar

Parameters:
year -
month -
day -
Returns:
a calendar for the user locale and time zone, and the given date

getLocaleCalendar

public static java.util.Calendar getLocaleCalendar(int year,
                                                   int month,
                                                   int day,
                                                   int hour,
                                                   int minute,
                                                   int second)
Convenience method - month is 0-based as in java.util.Calendar

Parameters:
year -
month -
day -
hour -
minute -
second -
Returns:
a calendar for the user locale and time zone, and the given date

getLocaleCalendar

public static java.util.Calendar getLocaleCalendar(java.util.TimeZone timeZone)
Returns:
a calendar for the user locale and time zone

getLocaleFromLCID

public static java.lang.String getLocaleFromLCID(int lcid)
Decode the language ID from LCID value

Parameters:
lcid - the LCID value
Returns:
the locale/language ID