Copyright 2009,2010, Lapetus Systems Ltd. (All rights reserved)

com.lapetus_ltd.api.common
Class TLptsCharSetLocaleUtil

java.lang.Object
  extended by com.lapetus_ltd.api.common.TLptsCharSetLocaleUtil

public class TLptsCharSetLocaleUtil
extends java.lang.Object

Class Description : Provides services for CharSet and locale functionality.

This factory provides the ability to get charset lists and actual charset objects.
Furthermore, it allows for locale functionality and listening. In other words, all classes wishing to be informed of
locale changes need to register as locale listeners ILptsLogListener using addLocaleListener(ILptsCharSetLocaleListener).

$LastChangedRevision: 1191 $
$LastChangedDate:: 2010-11-18 15:53:39#$


Field Summary
static java.lang.String NO_CHARSET_TRANSLATION
          Used as the default for CHARSET processing
 
Method Summary
static void addLocaleListener(ILptsCharSetLocaleListener listener)
          Adds an implementation of the ILptsCharSetLocaleListener interface to be informed of locale changes.
static java.nio.charset.Charset getCharSet(java.lang.String charsetName)
          Gets the actual charset by its name(See Charset).
static java.util.Set<java.lang.String> getCharsetNameList()
          Gets a list of all the charset names on the current system.
static java.util.Locale getCurrentLocale()
          Gets Current Application Locale.
static java.lang.String getStringWithCharset(byte[] ccsBytes, java.lang.String charSet)
          Returns a string that is encoded with the supplied charset.
static void removeLocaleListener(ILptsCharSetLocaleListener listener)
          Remove an implementation of the ILptsCharSetLocaleListener interface from the listener list.
static boolean setLocale(java.lang.String language, java.lang.String country)
          Sets the default system locale to the language and country specified.
static void zI()
          Obfuscated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_CHARSET_TRANSLATION

public static final java.lang.String NO_CHARSET_TRANSLATION
Used as the default for CHARSET processing

See Also:
Constant Field Values
Method Detail

addLocaleListener

public static void addLocaleListener(ILptsCharSetLocaleListener listener)
Adds an implementation of the ILptsCharSetLocaleListener interface to be informed of locale changes.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : N/A

Notes : No duplication policy.
Any other instantiation of the added ILptsCharSetLocaleListener interface in the listener list is removed
before this addition.
This means that there are never any duplications in the list, and the implementor will only be informed
once of the change of locale.

Example :
Notes :

 

TLptsCharSetLocaleUtil.addLocaleListener(new ILptsCharSetLocaleListener() { public void localeHasChanged(String country, String language) { if (country.equalsIgnoreCase ("de") && language.equalsIgnoreCase("de")) System.out.println("Oops! I don't know any German."); } }

Parameters:
listener - An implementation of the ILptsCharSetLocaleListener interface.

getCharSet

public static java.nio.charset.Charset getCharSet(java.lang.String charsetName)
Gets the actual charset by its name(See Charset).

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : Yes

Notes :
Get the names of all lists from getCharsetNameList and
then use one to load the actual charset with this function.

Please note that this is normally not required as most functions that deal with
charsets take the string value of the charset name as a parameter.

Example :

 JComboBox combo = new JComboBox();
 DefaultComboBoxModel dlm = new DefaultComboBoxModel();
 for (String charset : TLptsCharSetLocaleUtil.getCharsetNameList())
   if (!charset.equalsIgnoreCase(TLptsCharSetLocaleUtil.NO_CHARSET_TRANSLATION))
     dlm.addElement(charset);
 combo.setModel(dlm);
 ...
 private comboActionPerformed()
 {
   Charset charset = TLptsCharSetLocaleUtil.getCharSet(combo.getSelectedItem());
 }
 

Parameters:
charsetName - The name of the charset. Could be retrieved from getCharsetNameList()
Returns:
Returns the actual charset, or null if it is not found.

getCharsetNameList

public static java.util.Set<java.lang.String> getCharsetNameList()
Gets a list of all the charset names on the current system.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : No, in worst case an empty set.

Notes :
This list also contains an entry called "Default". This is not a supported CHARSET.
It is used by db-JAPI to mean that a database charset should not be set.
In other words, the charset that is in the database should be used for data processing. (like with MS SQL which automatically encodes strings)
The database default is represented by a variable called NO_CHARSET_TRANSLATION.
The example below excludes it from the combo box list.

Example :

 

JComboBox combo = new JComboBox(); DefaultComboBoxModel dlm = new DefaultComboBoxModel(); for (String charset : TLptsCharSetLocaleUtil.getCharsetNameList()) if (!charset.equalsIgnoreCase(TLptsCharSetLocaleUtil.NO_CHARSET_TRANSLATION)) dlm.addElement(charset); combo.setModel(dlm);

Returns:
A list of all the charsets in the system.

getCurrentLocale

public static java.util.Locale getCurrentLocale()
Gets Current Application Locale.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : No

Notes :

Example :

 

Locale loc = TLptsCharSetLocaleUtil.getCurrentLocale(); System.out.println(loc.getCountry()); System.out.println(loc.getLanguage());

Result (in our case) :GB en

Returns:
current locale

getStringWithCharset

public static java.lang.String getStringWithCharset(byte[] ccsBytes,
                                                    java.lang.String charSet)
Returns a string that is encoded with the supplied charset.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : No

Notes : if NO_CHARSET_TRANSLATION is set as the charset an empty string is returned.

Example :

 

byte[] firstColumnBytes = rowset.getBytes(1); String uftString = TLptsCharSetLocaleUtil.getStringWithCharset(firstColumnBytes,"UTF-8"); System.out.print("The UTF-8 string for the bytes of column 1 is " + utfString);

Parameters:
ccsBytes - An array of bytes to be encoded.
charSet - The name of the charset to use for encoding. Could be retrieved from getCharsetNameList()
Returns:
Returns the encoded string or an empty string in any other case.

removeLocaleListener

public static void removeLocaleListener(ILptsCharSetLocaleListener listener)
Remove an implementation of the ILptsCharSetLocaleListener interface from the listener list.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : N/A

Notes : This only has meaning if an implementation has previously been added to the list.

Example :

 

boolean alwaysReturnsFalse = TLptsCharSetLocaleUtil.removeLocaleListener(new ILptsCharSetLocaleListener() { public void localeHasChanged(String country, String language) { // some code here that will never be executed. } }

Parameters:
listener - An implementation of the ILptsCharSetLocaleListener interface.

setLocale

public static boolean setLocale(java.lang.String language,
                                java.lang.String country)
Sets the default system locale to the language and country specified.

See http://java.sun.com/developer/technicalArticles/J2SE/locale/ for a list of codes.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : N/A

Notes :

A DEBUG log is generated on the successful completion of this function.

Furthermore, all listeners are informed of the locale change, if successful.

Example :

 

boolean doesThisLocaleExist = TLptsCharSetLocaleUtil.setLocale("en","gb"); Result : normally true.

Parameters:
country - A case insensitive value for the country code (ie : "gb" or "GB" or "Gb" for Great Britain)
language - A case insensitive value for the language code (ie : "en" or ""eN" for English)
Returns:
Returns true if the language and country codes were found in the supported locales.

zI

public static void zI()
Obfuscated.



Copyright 2009,2010, Lapetus Systems Ltd. (All rights reserved)