com.sap.localization

Class LocalizableTextFormatter

java.lang.Object
  extended bycom.sap.localization.LocalizableTextFormatter
All Implemented Interfaces:
Localizable, LocalizableText, Serializable
Direct Known Subclasses:
VSIServiceMessage

public class LocalizableTextFormatter
extends Object
implements LocalizableText

The LocalizableTextFormatter object is an implementation of the LocalizableText interface.

This class provides the infrastructure to enable the retrieval of translated text to any desired locale/time zone in a distributed environment. With the use of a LocalizableTextFormatter object, the user can set the needed information in a language neutral way. When the information is needed to be displayed to a user, the object can be formatted into the locale/time zone of the user. Typical uses will be to hold error and exception information, GUI screen information and so forth.

The formatting can be done either locally or remotely/centrally. That means it is possible that the resource bundles are kept centrally in a server environment and that LocalizableTextFormatter object can be sent across system boundaries without localization. The client can localize the text with its own locale and time zone at a particular time. Whether the localization is done locally or centrally is transparent to the user.

Note: Currently, central localization is not supported.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class com.sap.localization.LocalizableText
LocalizableText.Key0, LocalizableText.Key1, LocalizableText.Key2, LocalizableText.Key3, LocalizableText.Key4, LocalizableText.Key5, LocalizableText.Key6, LocalizableText.Msg
 
Field Summary
 
Fields inherited from interface com.sap.localization.Localizable
defaultLocale
 
Constructor Summary
LocalizableTextFormatter()
          Simple constructor for LocalizableTextFormatter.
LocalizableTextFormatter(ResourceAccessor resourceAccessor, LocalizableText.Msg msg)
          Constructor with specified resource accessor, key and format arguments.
LocalizableTextFormatter(ResourceAccessor resourceAccessor, String patternKey)
          Constructor with specified resource accessor and key.
LocalizableTextFormatter(ResourceAccessor resourceAccessor, String patternKey, Object[] args)
          Constructor with specified resource accessor, key and format arguments.
LocalizableTextFormatter(ResourceAccessor resourceAccessor, String patternKey, Object[] args, String applicationName)
          Constructor with specified resource accessor, key, default text and name of the formatting bean.
 
Method Summary
 void clearCache()
          Removes the cached localized message.
 void clearLocalizableTextFormatter()
          Restores the initial state.
static LocalizableText.Key0 createKey0(String key)
          Creates message key.
static LocalizableText.Key1 createKey1(String key)
          Creates message key.
static LocalizableText.Key2 createKey2(String key)
          Creates message key.
static LocalizableText.Key3 createKey3(String key)
          Creates message key.
static LocalizableText.Key4 createKey4(String key)
          Creates message key.
static LocalizableText.Key5 createKey5(String key)
          Creates message key.
static LocalizableText.Key6 createKey6(String key)
          Creates message key.
 void finallyLocalize()
          Finally localize the message text.
 void finallyLocalize(Locale loc)
          Finally localize the message text.
 void finallyLocalize(Locale loc, TimeZone tZone)
          Finally localize the message text.
 void finallyLocalize(TimeZone tZone)
          Finally localize the message text.
 String format()
          Returns the message text.
 String format(Locale loc)
          Returns the message text.
 String format(Locale loc, TimeZone tZone)
          Returns the message text.
 String format(TimeZone tZone)
          Returns the message text.
static String formatString(ResourceAccessor resourceAccessor, LocalizableText.Msg msg)
          Formats a specified message with the default locale and time zone.
static String formatString(ResourceAccessor resourceAccessor, LocalizableText.Msg msg, Locale loc, TimeZone timeZone)
          Formats a specified message.
static String formatString(ResourceAccessor resourceAccessor, String patternKey)
          Formats a specified message.
static String formatString(ResourceAccessor resourceAccessor, String patternKey, Object[] args)
          Formats a specified message.
static String formatString(ResourceAccessor resourceAccessor, String patternKey, Object[] args, Locale loc, TimeZone timeZone)
          Formats a specified message.
 String getApplicationName()
          Getter method for name of the formatting enterprise bean
 Object[] getArguments()
          Getter method for the format arguments.
 String getCacheEntry()
          Getter method for the cached entry.
 Locale getLocale()
          Getter method for the locale.
 String getPatternKey()
          Getter method for the pattern key.
 ResourceAccessor getResourceAccessor()
          Getter method for the resource accessor.
 String getResourceBundleName()
          Getter method for the resource bundle name.
 TimeZone getTimeZone()
          Getter method for the time zone.
 boolean isCacheSetting()
          Returns whether caching is activated.
 boolean isFinallySetting()
          Returns whether the finally setting is activated.
 boolean isLocalFormat()
          Returns whether local formatting is enabled.
 void setApplicationName(String applicationName)
          Setter method for name of the formatting enterprise bean
 void setArguments(Object[] obj)
          Setter method for the format arguments.
 void setCacheSetting(boolean setting)
          Determines the cache setting.
 void setLocale(Locale locale)
          Setter method for the locale.
 void setLocalFormat(boolean local)
          Setter method for local formatting mode.
 void setPatternKey(String patternKey)
          Setter method for the pattern key.
 void setResourceAccessor(ResourceAccessor resAccessor)
          Setter method for the resource accessor.
 void setTimeZone(TimeZone timeZone)
          Setter method for the time zone.
 String toString()
          Gets the localized string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LocalizableTextFormatter

public LocalizableTextFormatter()
Simple constructor for LocalizableTextFormatter.


LocalizableTextFormatter

public LocalizableTextFormatter(ResourceAccessor resourceAccessor,
                                String patternKey)
Constructor with specified resource accessor and key.

Parameters:
resourceAccessor - resource accessor
patternKey - key used as index in the resource bundle

LocalizableTextFormatter

public LocalizableTextFormatter(ResourceAccessor resourceAccessor,
                                String patternKey,
                                Object[] args)
Constructor with specified resource accessor, key and format arguments.

Parameters:
resourceAccessor - resource accessor
patternKey - key used as index in the resource bundle
args - format objects

LocalizableTextFormatter

public LocalizableTextFormatter(ResourceAccessor resourceAccessor,
                                String patternKey,
                                Object[] args,
                                String applicationName)
Constructor with specified resource accessor, key, default text and name of the formatting bean.

Parameters:
resourceAccessor - resource accessor
patternKey - key used as index in the resource bundle
args - format arguments
applicationName - name of the formatting bean

LocalizableTextFormatter

public LocalizableTextFormatter(ResourceAccessor resourceAccessor,
                                LocalizableText.Msg msg)
Constructor with specified resource accessor, key and format arguments.

Parameters:
resourceAccessor - resource accessor
msg - message containing message key and arguments
Method Detail

formatString

public static String formatString(ResourceAccessor resourceAccessor,
                                  String patternKey)
                           throws LocalizationException
Formats a specified message. Default locale and time zone are used.

Parameters:
resourceAccessor - resource accessor
patternKey - message key
Returns:
formatted message
Throws:
LocalizationException - if an error occurred

formatString

public static String formatString(ResourceAccessor resourceAccessor,
                                  String patternKey,
                                  Object[] args)
                           throws LocalizationException
Formats a specified message. Default locale and time zone are used.

Parameters:
resourceAccessor - resource accessor
patternKey - message key
args - message parameters
Returns:
formatted message
Throws:
LocalizationException - if an error occurred

formatString

public static String formatString(ResourceAccessor resourceAccessor,
                                  String patternKey,
                                  Object[] args,
                                  Locale loc,
                                  TimeZone timeZone)
                           throws LocalizationException
Formats a specified message.

Parameters:
resourceAccessor - resource accessor
patternKey - message key
args - message parameters
loc - locale
timeZone - time zone
Returns:
formatted message
Throws:
LocalizationException - if an error occurred

formatString

public static String formatString(ResourceAccessor resourceAccessor,
                                  LocalizableText.Msg msg)
                           throws LocalizationException
Formats a specified message with the default locale and time zone.

Parameters:
resourceAccessor - resource accessor
msg - message containing key and arguments
Returns:
formatted message
Throws:
LocalizationException - if an error occurred

formatString

public static String formatString(ResourceAccessor resourceAccessor,
                                  LocalizableText.Msg msg,
                                  Locale loc,
                                  TimeZone timeZone)
                           throws LocalizationException
Formats a specified message.

Parameters:
resourceAccessor - resource accessor
msg - message containing key and arguments
loc - locale
timeZone - time zone
Returns:
formatted message
Throws:
LocalizationException - if an error occurred

format

public String format(Locale loc)
              throws LocalizationException
Returns the message text. Localization is done with the specified locale and the current time zone. If the finallyLocalize method was called before, the already localized message is returned. If the cache setting was activated, the cached value is returned (if existent and the cached version corresponds with the specified locale).

Specified by:
format in interface LocalizableText
Parameters:
loc - locale
Returns:
localized message text as unicode string
Throws:
LocalizationException - if an error occurred
See Also:
LocalizableText.format()

format

public String format(TimeZone tZone)
              throws LocalizationException
Returns the message text. Localization is done with the specified time zone and the current locale. If the finallyLocalize method was called before, the already localized message is returned. If the cache setting was activated, the cached value is returned (if existent and the cached version corresponds with the specified time zone).

Specified by:
format in interface LocalizableText
Parameters:
tZone - time zone
Returns:
localized message text as unicode string
Throws:
LocalizationException - if an error occurred
See Also:
LocalizableText.format()

format

public String format(Locale loc,
                     TimeZone tZone)
              throws LocalizationException
Returns the message text. Localization is done with the specified time zone and locale. If the finallyLocalize method was called before, the already localized message is returned. If the cache setting was activated, the cached value is returned (if existent and the cached version corresponds with the specified time zone and locale).

Specified by:
format in interface LocalizableText
Parameters:
loc - locale
tZone - time zone
Returns:
localized message text as unicode string
Throws:
LocalizationException - if an error occurred
See Also:
LocalizableText.format()

format

public String format()
              throws LocalizationException
Returns the message text. Localization is done with the specified locale and time zone. If the finallyLocalize method was called before, the already localized message is returned. If the cache setting was activated, the cached value is returned (if existent).

Specified by:
format in interface LocalizableText
Returns:
localized message text as unicode string
Throws:
LocalizationException - if an error occurred
See Also:
LocalizableText.format()

finallyLocalize

public void finallyLocalize()
                     throws LocalizationException
Finally localize the message text. The ability to do localization on demand gets lost.

Specified by:
finallyLocalize in interface LocalizableText
Throws:
LocalizationException - if an error occurred
See Also:
LocalizableText.finallyLocalize()

finallyLocalize

public void finallyLocalize(Locale loc)
                     throws LocalizationException
Finally localize the message text. The ability to do localization on demand gets lost.

Specified by:
finallyLocalize in interface LocalizableText
Parameters:
loc - locale
Throws:
LocalizationException - if an error occurred
See Also:
LocalizableText.finallyLocalize()

finallyLocalize

public void finallyLocalize(TimeZone tZone)
                     throws LocalizationException
Finally localize the message text. The ability to do localization on demand gets lost.

Specified by:
finallyLocalize in interface LocalizableText
Parameters:
tZone - timeZone
Throws:
LocalizationException - if an error occurred
See Also:
LocalizableText.finallyLocalize()

finallyLocalize

public void finallyLocalize(Locale loc,
                            TimeZone tZone)
                     throws LocalizationException
Finally localize the message text. The ability to do localization on demand gets lost.

Specified by:
finallyLocalize in interface LocalizableText
Parameters:
loc - locale
tZone - time zone
Throws:
LocalizationException - if an error occurred
See Also:
LocalizableText.finallyLocalize()

setLocale

public void setLocale(Locale locale)
Setter method for the locale. If a format argument is an instance of LocalizableText, the locale setting is propagated.

Specified by:
setLocale in interface Localizable
Parameters:
locale - used for local-sensitive formatting.
See Also:
Localizable.setLocale(Locale)

getLocale

public Locale getLocale()
Getter method for the locale.

Specified by:
getLocale in interface Localizable
Returns:
the specified locale or null
See Also:
Localizable.getLocale()

setTimeZone

public void setTimeZone(TimeZone timeZone)
Setter method for the time zone. If a format argument is an instance of LocalizableText, the time zone setting is propagated.

Specified by:
setTimeZone in interface Localizable
Parameters:
timeZone - used for determining the local date and time.
See Also:
Localizable.setTimeZone(TimeZone)

getTimeZone

public TimeZone getTimeZone()
Getter method for the time zone.

Specified by:
getTimeZone in interface Localizable
Returns:
timeZone used for determining the local date and time. If calendar is null, returns default time zone
See Also:
Localizable.getTimeZone()

setApplicationName

public void setApplicationName(String applicationName)
Setter method for name of the formatting enterprise bean

Parameters:
applicationName - name of the formatting enterprise bean

getApplicationName

public String getApplicationName()
Getter method for name of the formatting enterprise bean

Returns:
name of the formatting enterprise bean

getResourceBundleName

public String getResourceBundleName()
Getter method for the resource bundle name.

Returns:
the specified resource bundle name

setPatternKey

public void setPatternKey(String patternKey)
Setter method for the pattern key.

Parameters:
patternKey - the message catalog key

getPatternKey

public String getPatternKey()
Getter method for the pattern key.

Returns:
the specified pattern key.

setArguments

public void setArguments(Object[] obj)
Setter method for the format arguments.

Parameters:
obj - format arguments

getArguments

public Object[] getArguments()
Getter method for the format arguments.

Returns:
the specified format arguments

setResourceAccessor

public void setResourceAccessor(ResourceAccessor resAccessor)
Setter method for the resource accessor.

Parameters:
resAccessor - resource accessor

getResourceAccessor

public ResourceAccessor getResourceAccessor()
Getter method for the resource accessor.

Returns:
resource accessor

setCacheSetting

public void setCacheSetting(boolean setting)
Determines the cache setting. If the setting is set true, caching is activated; otherwise caching is disabled and the cache is cleared.

Parameters:
setting - true, if caching should be enabled

isCacheSetting

public boolean isCacheSetting()
Returns whether caching is activated.

Returns:
true if caching is activated; otherwise false

setLocalFormat

public void setLocalFormat(boolean local)
Setter method for local formatting mode.

Parameters:
local - true, if the local formatting mode should be enabled; otherwise false

isLocalFormat

public boolean isLocalFormat()
Returns whether local formatting is enabled.

Returns:
true, if local formatting is activated; otherwise false

isFinallySetting

public boolean isFinallySetting()
Returns whether the finally setting is activated.

Returns:
true if the finally setting is activated; otherwise false

clearCache

public void clearCache()
Removes the cached localized message.


clearLocalizableTextFormatter

public void clearLocalizableTextFormatter()
Restores the initial state.


getCacheEntry

public String getCacheEntry()
Getter method for the cached entry.

Returns:
the cached entry or null

toString

public String toString()
Gets the localized string. Possible exceptions are caught.


createKey0

public static LocalizableText.Key0 createKey0(String key)
Creates message key. The corresponding message has no arguments.

Parameters:
key - message key
Returns:
key object

createKey1

public static LocalizableText.Key1 createKey1(String key)
Creates message key. The corresponding message has exactly one argument.

Parameters:
key - message key
Returns:
key object

createKey2

public static LocalizableText.Key2 createKey2(String key)
Creates message key. The corresponding message has exactly two arguments.

Parameters:
key - message key
Returns:
key object

createKey3

public static LocalizableText.Key3 createKey3(String key)
Creates message key. The corresponding message has exactly three arguments.

Parameters:
key - message key
Returns:
key object

createKey4

public static LocalizableText.Key4 createKey4(String key)
Creates message key. The corresponding message has exactly four arguments.

Parameters:
key - message key
Returns:
key object

createKey5

public static LocalizableText.Key5 createKey5(String key)
Creates message key. The corresponding message has exactly five arguments.

Parameters:
key - message key
Returns:
key object

createKey6

public static LocalizableText.Key6 createKey6(String key)
Creates message key. The corresponding message has exactly six arguments.

Parameters:
key - message key
Returns:
key object


Copyright 2006 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. MaxDB is a trademark of MySQL AB, Sweden. SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.