upidiff.i18n
Class Catalog

java.lang.Object
  |
  +--upidiff.i18n.Catalog

public final class Catalog
extends Object

This class represents a language catalog.

Author:
bmeurer

Nested Class Summary
private  class Catalog.CatalogFilenameFilter
          Filename filter for catalog files.
 
Field Summary
private  Language[] availableLanguages
          List of available languages.
private  Language currentLanguage
          Currently selected language.
private static Catalog instance
          Global Catalog instance.
private  List listeners
          List of CatalogListeners.
private  ResourceBundle resource
          The language catalog backend.
 
Constructor Summary
private Catalog()
          Constructs a new Catalog object.
 
Method Summary
 void addCatalogListener(CatalogListener listener)
          Registers a CatalogListener.
 Language[] getAvailableLanguages()
          Queries the available languages.
 Language getCurrentLanguage()
          Returns the currently selected language.
static Catalog getInstance()
          Returns a reference to the global Catalog instance.
 String getString(String identifier)
          Queries the catalog string for the given identifer.
 boolean hasString(String identifier)
          Checks if the given identifer is present in the catalog.
private  String[] lookupCatalogFiles(String resourcePath)
          Looks up the install catalog files.
 void removeCatalogListener(CatalogListener listener)
          Unregisters a CatalogListener.
 void setCurrentLanguage(Language language)
          Sets the language to be used by the Catalog.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

availableLanguages

private Language[] availableLanguages
List of available languages. An array of available languages found on the system. A language is available if both a language catalog file is found and the locale for that language is known by the Java runtime environment.

See Also:
getAvailableLanguages()

currentLanguage

private Language currentLanguage
Currently selected language.

See Also:
getCurrentLanguage()

listeners

private List listeners
List of CatalogListeners.

See Also:
addCatalogListener(upidiff.i18n.CatalogListener), removeCatalogListener(upidiff.i18n.CatalogListener)

resource

private ResourceBundle resource
The language catalog backend. The language catalog files itself are loaded through the ResourceBundle class.

See Also:
ResourceBundle

instance

private static Catalog instance
Global Catalog instance.

See Also:
getInstance()
Constructor Detail

Catalog

private Catalog()
         throws NoLanguagesFound
Constructs a new Catalog object. This constructor is private because only one instance of Catalog is allowed per process. It would not make much sense to have several catalogs in one process. Use getInstance() to obtain a reference to the global Catalog instance.

Throws:
NoLanguagesFound - This exception is thrown if no language catalogs can be found, neither in the system nor in the Jar archive.
See Also:
getInstance()
Method Detail

lookupCatalogFiles

private String[] lookupCatalogFiles(String resourcePath)
Looks up the install catalog files.

Parameters:
resourcePath - Resource path to the directory that contains the catalog files.
Returns:
An array of catalog filenames.

getInstance

public static Catalog getInstance()
                           throws NoLanguagesFound
Returns a reference to the global Catalog instance. This returns a reference to the global Catalog instance. If no global instance exists yet, a new instance is created.

Returns:
The global Catalog instance.
Throws:
NoLanguagesFound - This exception is thrown if no language catalogs can be found, neither in the system nor in the Jar archive.
See Also:
instance

getAvailableLanguages

public Language[] getAvailableLanguages()
Queries the available languages. Returns an array of available languages found on the system. A language is available if both a language catalog file is found and the locale for that language is known by the Java runtime environment.

Returns:
The available languages.

getCurrentLanguage

public Language getCurrentLanguage()
Returns the currently selected language.

Returns:
The currently selected language.

setCurrentLanguage

public void setCurrentLanguage(Language language)
                        throws InvalidLanguage
Sets the language to be used by the Catalog. If the language was changed successfully, all CatalogListeners are notified that the current language was changed.

Parameters:
language - The new language to set.
Throws:
InvalidLanguage - This exception is thrown if the supplied Language was not valid or if the language catalog file could not be loaded due to some system error (e.g. the user could have deleted the language catalog file). In this case the current language is not changed.

getString

public String getString(String identifier)
Queries the catalog string for the given identifer. If there was no catalog string found for the given identifier, the identifier itself is returned.

Parameters:
identifier - Unique identifier for a catalog string.
Returns:
The catalog string for the given identifier.

hasString

public boolean hasString(String identifier)
Checks if the given identifer is present in the catalog.

Parameters:
identifier - Unique identifer for a catalog string.
Returns:
true if the catalog string is present, else false.

addCatalogListener

public void addCatalogListener(CatalogListener listener)
Registers a CatalogListener. If the current language is changed due to a call to setCurrentLanguage() all registered CatalogListeners will be notifed.

Parameters:
listener - New CatalogListener to register.
See Also:
removeCatalogListener(upidiff.i18n.CatalogListener)

removeCatalogListener

public void removeCatalogListener(CatalogListener listener)
Unregisters a CatalogListener.

Parameters:
listener - CatalogListener to unregister.
See Also:
addCatalogListener(upidiff.i18n.CatalogListener)