com.sap.ip.collaboration.core.api.util.text

Class TextBundle

java.lang.Object
  extended by com.sap.ip.collaboration.core.api.util.text.TextBundle
All Implemented Interfaces:
Serializable

public class TextBundle
extends Object
implements Serializable

Root class for internationalized text bundles with different text lengths.

This class is used by subclassing it. The idea is to have one class per resource bundle file. The subclass defines the new text keys. The default behavior is to load the corresponding resource bundle file by adding "Resources" to the name of the class.

e.g. if the subclass of TextBundle is called com.sapportals.pct.example.MyTextBundle, the corresponding resource bundle property file has the name com.sapportals.pct.example.MyTextBundleResources and it ends with .properties, _en.properties, etc.

This behavior can be replaced constructing the class with a ResourceBundleReader.

The Textbundle class can cache texts. A set of texts for one language that was read once might not be read again by the same TextBundle object. For efficient caching do not recreate the same TextBundle object multiple times. The caching does not work across multiple TextBundle objects that use the same texts.

The texts inside the resource bundle are formatted with the java MessageFormat class. This allows locale specific formatting and filling of place holders.

This class supports retrieving a text in different lengths. This is achieved by adding extensions to the message keys. If a message has the message key "myKey", the short version is stored under "myKey", the medium version under "myKeyMedium" and the long version under "myKeyLong".

This allows for instance a GUI to retrieve a text of the appropriate length type.

There is no fix definition of the text lengths. The three text length types are only a hint. The idea is of cause that short <= medium <= long is true.

There is a fallback mechanism for long texts onto the shorter variant if the resource bundle does not contain the longer versions.

There is an optional fallback onto a technical constructed name if there is no resource bundle at all. The normal behavior is to throw a MissingResourceException

Copyright: Copyright (c) 2002 Company: SAP Portals

See Also:
Serialized Form

Field Summary
static int LONG
          length type for long text
static String LONG_EXTENSION
          extension that is added to a text key to get a long text
static int MEDIUM
          length type for medium text
static String MEDIUM_EXTENSION
          extension that is added to a text key to get a medium text
static int SHORT
          length type for short text
static String SHORT_EXTENSION
          extension that is added to a text key to get a short text
 
Constructor Summary
TextBundle()
          constructs a new TextBundle.
TextBundle(IResourceBundleReader aResourceBundleReader)
          constructs a new TextBundle with a separate resource bundle reader
TextBundle(String resourceBundleName)
          constructs a new TextBundle.
TextBundle(String resourceBundleName, ClassLoader classLoader)
          constructs a new TextBundle.
 
Method Summary
 String getLongText(String aTextKey, Locale aLocale)
          convenience method returning the a long text
 String getLongText(String aTextKey, Locale aLocale, boolean fallback)
          convenience method returning the a long text
 String getLongText(String aTextKey, Object[] textParameters, Locale aLocale)
          convenience method returning the a long text with text parameters
 String getLongText(String aTextKey, Object[] textParameters, Locale aLocale, boolean fallback)
          convenience method returning the a long text with text parameters
 String getMediumText(String aTextKey, Locale aLocale)
          convenience method returning the a medium text
 String getMediumText(String aTextKey, Locale aLocale, boolean fallback)
          convenience method returning the a medium text
 String getMediumText(String aTextKey, Object[] textParameters, Locale aLocale)
          convenience method returning the a medium text with text parameters
 String getMediumText(String aTextKey, Object[] textParameters, Locale aLocale, boolean fallback)
          convenience method returning the a medium text with text parameters
 String getShortText(String aTextKey, Locale aLocale)
          convenience method returning the a short text
 String getShortText(String aTextKey, Locale aLocale, boolean fallback)
          convenience method returning the a short text
 String getShortText(String aTextKey, Object[] textParameters, Locale aLocale)
          convenience method returning the a short text
 String getShortText(String aTextKey, Object[] textParameters, Locale aLocale, boolean fallback)
          convenience method returning the a short text with text parameters
 IText getText(String aTextKey)
          returns a text object representing the text.
 IText getText(String aTextKey, Object[] textParameters)
          returns a text object representing the text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHORT_EXTENSION

public static final String SHORT_EXTENSION
extension that is added to a text key to get a short text

See Also:
Constant Field Values

MEDIUM_EXTENSION

public static final String MEDIUM_EXTENSION
extension that is added to a text key to get a medium text

See Also:
Constant Field Values

LONG_EXTENSION

public static final String LONG_EXTENSION
extension that is added to a text key to get a long text

See Also:
Constant Field Values

SHORT

public static final int SHORT
length type for short text

See Also:
Constant Field Values

MEDIUM

public static final int MEDIUM
length type for medium text

See Also:
Constant Field Values

LONG

public static final int LONG
length type for long text

See Also:
Constant Field Values
Constructor Detail

TextBundle

public TextBundle()
constructs a new TextBundle. ResourceBundles are read by adding "Resources" to the class name and loading property files via the classpath


TextBundle

public TextBundle(String resourceBundleName)
constructs a new TextBundle. ResourceBundles are read with the given resource bundle name and loading property files via the classpath

Parameters:
resourceBundleName - name of the resourceBundle

TextBundle

public TextBundle(String resourceBundleName,
                  ClassLoader classLoader)
constructs a new TextBundle. ResourceBundles are read with the given resource bundle name and loading property files via the classpath

Parameters:
resourceBundleName - name of the resourceBundle
classLoader - classloader of package which contains the resource bundle

TextBundle

public TextBundle(IResourceBundleReader aResourceBundleReader)
constructs a new TextBundle with a separate resource bundle reader

Method Detail

getShortText

public String getShortText(String aTextKey,
                           Locale aLocale)
convenience method returning the a short text

Parameters:
aTextKey - key for the text
aLocale - the locale for the text
Returns:
locale specific text
Throws:
MissingResourceException - if the text key is missing

getShortText

public String getShortText(String aTextKey,
                           Locale aLocale,
                           boolean fallback)
convenience method returning the a short text

Parameters:
aTextKey - key for the text
aLocale - the locale for the text
fallback - true, if a technical name should be contructed when
Returns:
locale specific text
Throws:
MissingResourceException - if the text key is missing and fallback is disabled

getShortText

public String getShortText(String aTextKey,
                           Object[] textParameters,
                           Locale aLocale)
convenience method returning the a short text

Parameters:
aTextKey - key for the text
textParameters - object array with parameters for the text
aLocale - the locale for the text
Returns:
locale specific text
Throws:
MissingResourceException - if the text key is missing

getShortText

public String getShortText(String aTextKey,
                           Object[] textParameters,
                           Locale aLocale,
                           boolean fallback)
convenience method returning the a short text with text parameters

Parameters:
aTextKey - key for the text
textParameters - object array with parameters for the text
aLocale - the locale for the text
fallback - true, if a technical name should be contructed when
Returns:
locale specific text
Throws:
MissingResourceException - if the text key is missing and fallback is disabled

getMediumText

public String getMediumText(String aTextKey,
                            Locale aLocale)
convenience method returning the a medium text

Parameters:
aTextKey - key for the text
aLocale - the locale for the text
Returns:
locale specific text
Throws:
MissingResourceException - if the text key is missing

getMediumText

public String getMediumText(String aTextKey,
                            Locale aLocale,
                            boolean fallback)
convenience method returning the a medium text

Parameters:
aTextKey - key for the text
aLocale - the locale for the text
fallback - true, if a technical name should be contructed when
Returns:
locale specific text
Throws:
MissingResourceException - if the text key is missing and fallback is disabled

getMediumText

public String getMediumText(String aTextKey,
                            Object[] textParameters,
                            Locale aLocale)
convenience method returning the a medium text with text parameters

Parameters:
aTextKey - key for the text
textParameters - object array with parameters for the text
aLocale - the locale for the text
Returns:
locale specific text
Throws:
MissingResourceException - if the text key is missing

getMediumText

public String getMediumText(String aTextKey,
                            Object[] textParameters,
                            Locale aLocale,
                            boolean fallback)
convenience method returning the a medium text with text parameters

Parameters:
aTextKey - key for the text
textParameters - object array with parameters for the text
aLocale - the locale for the text
fallback - true, if a technical name should be contructed when
Returns:
locale specific text
Throws:
MissingResourceException - if the text key is missing and fallback is disabled

getLongText

public String getLongText(String aTextKey,
                          Locale aLocale)
convenience method returning the a long text

Parameters:
aTextKey - key for the text
aLocale - the locale for the text
Returns:
locale specific text
Throws:
MissingResourceException - if the text key is missing

getLongText

public String getLongText(String aTextKey,
                          Locale aLocale,
                          boolean fallback)
convenience method returning the a long text

Parameters:
aTextKey - key for the text
aLocale - the locale for the text
fallback - true, if a technical name should be contructed when
Returns:
locale specific text
Throws:
MissingResourceException - if the text key is missing and fallback is disabled

getLongText

public String getLongText(String aTextKey,
                          Object[] textParameters,
                          Locale aLocale)
convenience method returning the a long text with text parameters

Parameters:
aTextKey - key for the text
textParameters - object array with parameters for the text
aLocale - the locale for the text
Returns:
locale specific text
Throws:
MissingResourceException - if the text key is missing

getLongText

public String getLongText(String aTextKey,
                          Object[] textParameters,
                          Locale aLocale,
                          boolean fallback)
convenience method returning the a long text with text parameters

Parameters:
aTextKey - key for the text
textParameters - object array with parameters for the text
aLocale - the locale for the text
fallback - true, if a technical name should be contructed when
Returns:
locale specific text
Throws:
MissingResourceException - if the text key is missing and fallback is disabled

getText

public IText getText(String aTextKey)
returns a text object representing the text. The text object can be used for internalization and formatting. The text has no text parameters

Parameters:
aTextKey - key for the text
Returns:
new text object for that text

getText

public IText getText(String aTextKey,
                     Object[] textParameters)
returns a text object representing the text. The text object can be used for internalization and formatting.

Parameters:
aTextKey - key for the text
textParameters - object array with parameters for the text
Access Rights

This class can be accessed from:


SC DC Public Part ACH
[sap.com] KMC-WPC [sap.com] tc/kmc/wpc/wpcfacade api EP-PIN-WPC-WCM
[sap.com] KMC-CM [sap.com] tc/km/frwk api EP-KM-CM
[sap.com] KMC-COLL [sap.com] tc/kmc/coll/util api EP-KM-COL


Copyright 2011 SAP AG Complete Copyright Notice