com.tecnick.tmxjavabridge
Class TMXResourceBundle

java.lang.Object
  extended by java.util.ResourceBundle
      extended by com.tecnick.tmxjavabridge.TMXResourceBundle
All Implemented Interfaces:
java.io.Serializable

public class TMXResourceBundle
extends java.util.ResourceBundle
implements java.io.Serializable

Reads resource text data directly from a TMX (XML) file.

First, the TMXResourceBundle class instantiates itself with two parameters: a TMX file name and a target language name. Then, using a DOM parser, it reads all of a translation unit's properties for the key information and specified language data and populates a hashtable with them.

TMX info: http://www.lisa.org/tmx/

Implementation notes

You instantiate the TMXResourceBundle class in a program to read data from a TMX file. Once the class is instantiated, it reads all the data in a TMX file and loads into a DOM tree. Then it populates a hashtable so the handleGetObject() method can be called to find text information based on a key just as a standard ResourceBundle class does.
Instantiating the TMXResouceBundle class is the same as instantiating the PropertyResourceBundle class. First you obtain a system language code (e.g.: from a locale's information). In TMX the value of the attribute must be one of the ISO language identifiers (a two- or three-letter code) or one of the standard locale identifiers (a two- or three-letter language code, a dash, and a two-letter region code).

Copyright (c) 2004-2006 Tecnick.com S.r.l (www.tecnick.com) Via Ugo Foscolo n.19 - 09045 Quartu Sant'Elena (CA) - ITALY www.tecnick.com - info@tecnick.com
Project homepage: http://tmxjavabridge.sourceforge.net
License: http://www.gnu.org/copyleft/lesser.html LGPL

Version:
1.1.008
Author:
Nicola Asuni [www.tecnick.com].
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.ResourceBundle
java.util.ResourceBundle.Control
 
Field Summary
protected  java.util.Hashtable hashcontents
          The hastable that will contain data loaded from XML
protected  int numberOfItems
          Number of translation units (tu) items
protected  java.util.Vector vectOfItems
          Vector to store tu items keys
 
Fields inherited from class java.util.ResourceBundle
parent
 
Constructor Summary
TMXResourceBundle(java.lang.String xmlfile, java.lang.String language)
          TMX to Hashtable conversion.
TMXResourceBundle(java.lang.String xmlfile, java.lang.String language, java.lang.String cachefile)
          TMX to Hashtable conversion.
 
Method Summary
 java.util.Enumeration getKeys()
          Define getKeys method
 int getNumberOfItems()
          Returns the number of translation units
 java.lang.String getString(java.lang.String key, java.lang.String def)
          Get key value, return default if void.
 java.lang.Object handleGetObject(java.lang.String key)
          handleGetObject implementation
 org.w3c.dom.Document parseXmlFile(java.lang.String filename, boolean validating)
          Parses an XML file and returns a DOM document.
 
Methods inherited from class java.util.ResourceBundle
clearCache, clearCache, containsKey, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, handleKeySet, keySet, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hashcontents

protected java.util.Hashtable hashcontents
The hastable that will contain data loaded from XML


numberOfItems

protected int numberOfItems
Number of translation units (tu) items


vectOfItems

protected java.util.Vector vectOfItems
Vector to store tu items keys

Constructor Detail

TMXResourceBundle

public TMXResourceBundle(java.lang.String xmlfile,
                         java.lang.String language)
TMX to Hashtable conversion. Reads XML and store data in HashTable.

Parameters:
xmlfile - the TMX (XML) file to read, supports also URI resources or JAR resources
language - ISO language identifier (a two- or three-letter code)

TMXResourceBundle

public TMXResourceBundle(java.lang.String xmlfile,
                         java.lang.String language,
                         java.lang.String cachefile)
TMX to Hashtable conversion. Reads XML and store data in HashTable. NOTE: you must manually delete the cachefile to refresh its content.

Parameters:
xmlfile - the TMX (XML) file to read, supports also URI resources or JAR resources
language - ISO language identifier (a two- or three-letter code)
cachefile - name of the file used to store cache data for the specified language
Method Detail

parseXmlFile

public org.w3c.dom.Document parseXmlFile(java.lang.String filename,
                                         boolean validating)
Parses an XML file and returns a DOM document.

Parameters:
filename - the name of XML file
validating - If true, the contents is validated against the DTD specified in the file.
Returns:
the parsed document

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String def)
Get key value, return default if void.

Parameters:
key - name of key
def - default value
Returns:
parameter value or default

handleGetObject

public final java.lang.Object handleGetObject(java.lang.String key)
                                       throws java.util.MissingResourceException
handleGetObject implementation

Specified by:
handleGetObject in class java.util.ResourceBundle
Parameters:
key - the resource key
Returns:
the content associated to the specified key
Throws:
java.util.MissingResourceException

getNumberOfItems

public int getNumberOfItems()
Returns the number of translation units

Returns:
number of Items

getKeys

public java.util.Enumeration getKeys()
Define getKeys method

Specified by:
getKeys in class java.util.ResourceBundle
Returns:
item elements