lacam.language
Class Dictionary

java.lang.Object
  extended bylacam.language.Dictionary

public class Dictionary
extends java.lang.Object

This class represents the dictionary of the whole system.
Using a Properties it can store and load easy to write language packs, which just need to follow the Syntax Properties can read and use the in DictionaryConstants described keys to overwrite default values set in DefaultDictionary

Author:
Dimitrij Zub

Field Summary
static java.util.Properties FACTOR_TYPE_MAP
           
static java.lang.String PLACEHOLDER_PLUGIN_HOME
          The placeholder which will be replaced by the plugins name
static java.lang.String PLACEHOLDER_SCRIPTS_HOME
           
static java.lang.String PLACEHOLDER_SYSTEM_HOME
           
static java.lang.String PLACEHOLDER_USER_HOME
           
static java.lang.String PLACEHOLDER_USER_NAME
           
 
Constructor Summary
Dictionary()
           
 
Method Summary
static java.util.Properties addPluginLanguagePack(java.io.InputStream language_pack_stream)
          Adds a plugin language pack to the default dictionary
static java.util.Properties addPluginLanguagePack(java.util.Properties plugin_pack)
          Adds a plugin language pack to the default dictionary
static void addPluginLanguagePack(java.util.Properties default_dictionary, java.lang.String language_pack_loc)
          Adds a plugin language pack to the systems dictionary.
static java.lang.String getExpression(java.lang.String key)
          Use this method to access expression stored in the dictionary
static java.lang.String getExpression(java.lang.String key, java.lang.Object[] values)
          Formats the expression found for the key with the values given in values.
static java.lang.String getExpression(java.lang.String key, java.lang.String default_value)
          Returns the expression defined through the key key and returns default_value if expression was found
static java.lang.String getExpression(java.lang.String key, java.lang.String default_expression, java.lang.Object[] values)
          Formats the expression found for the key with the values given in values and uses default_expresion if no expression was found for the key.
static java.lang.String getHelpPath(java.lang.String key, java.lang.String plugin_loc)
           
static java.util.Locale getLocale()
           
static boolean loadLanguagePack()
          Reloads the default language pack of the system
static boolean loadLanguagePack(java.lang.String file)
          Sets the default langauge pack to file and reloads the language pack
static java.lang.String parseLocalizedString(java.lang.String definition)
          Parses the localized String out of the given definition list.
static void removePluginLanguagePack(java.util.Properties plugin_pack)
          Deprecated.  
static java.lang.String replacePlaceholders(java.lang.String expression, java.lang.String plugin_name)
          Replaces possible system placeholders in the String expression.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FACTOR_TYPE_MAP

public static java.util.Properties FACTOR_TYPE_MAP

PLACEHOLDER_PLUGIN_HOME

public static final java.lang.String PLACEHOLDER_PLUGIN_HOME
The placeholder which will be replaced by the plugins name

See Also:
Constant Field Values

PLACEHOLDER_SYSTEM_HOME

public static final java.lang.String PLACEHOLDER_SYSTEM_HOME
See Also:
Constant Field Values

PLACEHOLDER_SCRIPTS_HOME

public static final java.lang.String PLACEHOLDER_SCRIPTS_HOME
See Also:
Constant Field Values

PLACEHOLDER_USER_HOME

public static final java.lang.String PLACEHOLDER_USER_HOME
See Also:
Constant Field Values

PLACEHOLDER_USER_NAME

public static final java.lang.String PLACEHOLDER_USER_NAME
See Also:
Constant Field Values
Constructor Detail

Dictionary

public Dictionary()
Method Detail

loadLanguagePack

public static boolean loadLanguagePack(java.lang.String file)
Sets the default langauge pack to file and reloads the language pack

Parameters:
file - the path to the file
See Also:
loadLanguagePack()

addPluginLanguagePack

public static java.util.Properties addPluginLanguagePack(java.io.InputStream language_pack_stream)
Adds a plugin language pack to the default dictionary

Parameters:
language_pack_stream - the stream pointing at the language pack
See Also:
Properties.load(java.io.InputStream)

getExpression

public static java.lang.String getExpression(java.lang.String key,
                                             java.lang.String default_value)
Returns the expression defined through the key key and returns default_value if expression was found

Parameters:
key - the key to the expression
default_value - the default return value if nothing found
See Also:
DictionaryConstants

getExpression

public static java.lang.String getExpression(java.lang.String key,
                                             java.lang.String default_expression,
                                             java.lang.Object[] values)
Formats the expression found for the key with the values given in values and uses default_expresion if no expression was found for the key.

Parameters:
key - The key to access the needed value in the dictionary
default_expression - The default value if no value could be found
values - The values to use for replacing
Returns:
The formated expression found for key (or the default value if no value for key was found) with values inserted
See Also:
MessageFormat, getExpression(String, String)

getExpression

public static java.lang.String getExpression(java.lang.String key,
                                             java.lang.Object[] values)
Formats the expression found for the key with the values given in values.

Parameters:
key - The key to access the needed value in the dictionary
values - The values to use for replacing
Returns:
The formated expression found for key (or the default value if no value for key was found) with values inserted
See Also:
MessageFormat, getExpression(String, String)

getExpression

public static java.lang.String getExpression(java.lang.String key)
Use this method to access expression stored in the dictionary

Parameters:
key - the key to the expression
Returns:
The value (if any) for the given key
See Also:
getExpression(String, String), DictionaryConstants, Properties.getProperty(java.lang.String)

loadLanguagePack

public static boolean loadLanguagePack()
Reloads the default language pack of the system

See Also:
loadLanguagePack(String)

addPluginLanguagePack

public static void addPluginLanguagePack(java.util.Properties default_dictionary,
                                         java.lang.String language_pack_loc)
Adds a plugin language pack to the systems dictionary.
Uses the default_dictionary parameter as the default dictionary of the plugin and overwrites the values of the default_dictionary with values of the found in the dictionary found at language_pack_loc.

Parameters:
default_dictionary - The default dictionary of the plugin
language_pack_loc - The language pack wich should be loaded to overwrite default values

addPluginLanguagePack

public static java.util.Properties addPluginLanguagePack(java.util.Properties plugin_pack)
Adds a plugin language pack to the default dictionary

Parameters:
plugin_pack - the plugins language pack

removePluginLanguagePack

public static void removePluginLanguagePack(java.util.Properties plugin_pack)
Deprecated.  

Removes a plugin language from the default dictionary

Parameters:
plugin_pack - the plugins language pack

parseLocalizedString

public static java.lang.String parseLocalizedString(java.lang.String definition)
Parses the localized String out of the given definition list. The definition list should be formated matching the pattern <locale>?"<uri>";. If no local is given ("";) the system takes this as default string.

Example:

DE?"file:///${plugin_home}/language/german.lp";"http://www.my_home.uk/uk.lp"

defines that the plugin has 2 language packs. If the systems locale is DE the language pack at the location "file:///${plugin_home}/language/german.lp" will be chosen. If the systems local is amy other the language pack will be downloaded (if allowed) from http://www.my_home.uk/uk.lp.

Parameters:
definition - The definition list
Returns:
Localized substring

getHelpPath

public static java.lang.String getHelpPath(java.lang.String key,
                                           java.lang.String plugin_loc)
Parameters:
key - The key to find the help file path in the dictionary
plugin_loc - The location of the Plugin
Returns:
The url of the help file

getLocale

public static java.util.Locale getLocale()
Returns:
the currently set locale

replacePlaceholders

public static java.lang.String replacePlaceholders(java.lang.String expression,
                                                   java.lang.String plugin_name)
Replaces possible system placeholders in the String expression.
Possible placeholders are
${plugin_home}The home folder of the calling plugin
${system_home}The systems home folder @link System#getProperty(java.lang.String)
${scripts_home}The folder where the systems scripts can be found as *.dtd and *.xslt
${user_home}The current users home directory
${user_name}The current users name

Parameters:
expression - The expression in which the placeholders should be replaced
plugin_name - The calling Plugins name
Returns:
The expression, where placeholdes have been replaced