ariba.util.core
Class ResourceService

java.lang.Object
  extended by ariba.util.core.ResourceService

public class ResourceService
extends java.lang.Object

The fundamental API to resolving localized resources. Subclassers should implement the get* primitives based on specific resource resolution strategies.


Nested Class Summary
static interface ResourceService.Localizer
           
static interface ResourceService.PseudoLocalizer
           
static class ResourceService.ResourceLocation
          Is an enumerated type representing the locations where string resources may be found under the string resource base URL.
 
Field Summary
 java.net.URL baseURL
          The base URL for resolving resources
static java.lang.String EmbeddedSubstitutionsFlag
           
static java.util.Locale LocaleOfLastResort
          Locale of last resort.
static java.lang.String NlsTag
          Prefix for resource keys.
static java.lang.String ReportTemplatesDirectory
          Reports Template directory.
 
Constructor Summary
ResourceService(java.net.URL baseURL, java.util.Locale defaultLocale)
          Creates a new ResourceService with the given base URL and default locale.
ResourceService(java.net.URL stringBaseURL, java.net.URL baseURL, java.util.Locale defaultLocale)
           
 
Method Summary
static ResourceService.PseudoLocalizer _getPseudoLocalizer()
           
static void _setPseudoLocalizer(ResourceService.PseudoLocalizer pl)
           
 void cacheImageMap(java.util.Map imageMap, java.util.Locale locale)
          Puts the imageMap in the cache under the given locale.
 void cacheStringTable(java.lang.String path, java.util.Locale locale, java.util.Map stringTable, StringTableProcessor processor)
          Allows you to prepopulate the string table cache.
 void cacheStringTable(java.lang.String path, java.util.Map stringTable)
          Allows you to prepopulate the string table cache.
static ResourceService checkForService()
          Returns a reference to the shared ResourceService.
 void clearCache()
          Allows you to "reboot" the Resource Manager, so you don't have to shut down everything just to reload a string resource that's changed on disk.
static void createLocalizedMap(java.util.Map table, java.util.Locale locale)
          If a Map contains a string starting with an '@', it is assumed to be a localized string key which is localized using the localizedCompositeKey().
 java.lang.Object descendAndLocalizeObject(java.lang.Object object, java.util.Locale locale)
          Traverses an object (if it is an Map, List, or String), and for all strings that start with '@', replaces it with a localized string for the specified locale, using the method getLocalizedCompositeKey(java.lang.String, java.util.Locale).
 java.lang.Object descendAndLocalizeObject(java.lang.Object object, java.util.Locale locale, ResourceService.Localizer localizer)
          Traverses an object (if it is an Map, List, or String), and for all strings that start with '@', replaces it with a localized string for the specified locale, using the method getLocalizedCompositeKey(java.lang.String, java.util.Locale).
 java.lang.String findResourceURL(java.lang.String filename, java.util.Locale locale)
          Returns the url string of file for the given locale
 java.util.Set<java.lang.String> getAllStringTableNames(java.util.Locale locale)
          Returns the set of all string table names that exist and may contain resources for the specified locale.
 java.lang.String getDefaultImagesRoot()
          Returns the defaultImagesRoot.
 java.util.Locale getDefaultLocale()
          Returns the default locale.
 StringTableProcessor getDefaultStringTableProcessor()
           
 java.util.Locale getLocale()
          Returns the "default" locale that clients should use.
 java.util.List getLocales()
          This is to add a backdoor to ResourceService for Inspector to get a list of Locale UniqueName Strings
 java.lang.String getLocalizedCompositeFormat(java.lang.String string, java.util.Locale locale, boolean displayWarning, boolean defaulting)
           
 java.lang.String getLocalizedCompositeKey(java.lang.String string, java.util.Locale locale)
          If the specified string starts with an '@', it is assummed to be a composed localized string key (the string table and key are concatenated, separated by a slash (e.g.
 java.lang.String getLocalizedCompositeKey(java.lang.String string, java.util.Locale locale, boolean displayWarning)
          If the specified string starts with an '@', it is assummed to be a composed localized string key (the string table and key are concatenated, separated by a slash (e.g.
 java.lang.String getLocalizedCompositeKey(java.lang.String string, java.util.Locale locale, boolean displayWarning, boolean defaulting)
          If the specified string starts with an '@', it is assummed to be a composed localized string key (the string table and key are concatenated, separated by a slash (e.g.
 java.lang.String getLocalizedCompositeKey(java.lang.String string, java.util.Locale locale, boolean displayWarning, boolean defaulting, boolean resolveDynamicKeys)
          If the specified string starts with an '@', it is assummed to be a composed localized string key (the string table and key are concatenated, separated by a slash (e.g.
 java.lang.String getLocalizedFormat(java.lang.String stringTable, java.lang.String key, java.util.Locale locale)
          Lookup a localized string for the specified locale.
 java.lang.String getLocalizedFormat(java.lang.String stringTable, java.lang.String key, java.util.Locale locale, boolean displayWarning, boolean defaultingLocale, boolean defaultingSystem)
          Lookup a localized string for the specified locale.
 java.lang.String getLocalizedHelpPath(java.lang.String helpPath)
          Returns the path of the root of the help system for this service's locale.
 java.lang.String getLocalizedHelpPath(java.lang.String helpPath, java.util.Locale locale)
          Returns the path of the root of the help system for the specified locale.
 java.lang.String getLocalizedImagePath(java.lang.String path)
          Returns a localized image path in the service's locale.
 java.lang.String getLocalizedImagePath(java.lang.String path, java.util.Locale locale)
          Returns a localized image path in the specified locale.
 java.lang.String getLocalizedString(java.lang.String stringTable, java.lang.String key)
          Lookup a localized string for this service's locale, which is obtained by calling getLocale().
 java.lang.String getLocalizedString(java.lang.String stringTable, java.lang.String key, java.util.Locale locale)
          Lookup a localized string for the specified locale.
 java.lang.String getLocalizedString(java.lang.String stringTable, java.lang.String key, java.util.Locale locale, boolean displayWarning)
          Lookup a localized string for the specified locale.
 java.lang.String getLocalizedString(java.lang.String stringTable, java.lang.String key, java.util.Locale locale, boolean displayWarning, boolean defaultingLocale)
          Lookup a localized string for the specified locale.
 java.lang.String getLocalizedString(java.lang.String stringTable, java.lang.String key, java.util.Locale locale, boolean displayWarning, boolean defaultingLocale, boolean defaultingSystem)
          Lookup a localized string for the specified locale.
 java.util.Locale getOverrideLocale()
          This is to add a backdoor to ResourceService to allow docs and QA folks to force the HTML UI to render in a certain locale.
 boolean getOverrideLocaleOn()
          This is to add a backdoor to ResourceService to allow docs and QA folks to force the HTML UI to render in a certain locale.
 java.util.Locale getRestrictedLocale(java.util.Locale locale)
          Get a locale that is guaranteed to be available to the realm.
 java.util.List<java.util.Locale> getSearchDirs(java.util.Locale givenLocale, boolean defaulting)
          Returns list of directories to search for the given locale.
static ResourceService getService()
          Returns a reference to the shared ResourceService.
static java.lang.String getString(java.lang.String stringTable, java.lang.String key)
          A convenience using the service() and the locale, which is obtained by calling getLocale().
static java.lang.String getString(java.lang.String stringTable, java.lang.String key, java.util.Locale locale)
          A convenience using the service() and the specified locale.
static java.lang.String getString(java.lang.String stringTable, java.lang.String key, java.util.Locale locale, boolean displayWarning)
          A convenience using the service(), the specified locale, and whether to display a warning if not found.
static java.lang.String getString(java.lang.String stringTable, java.lang.String key, java.lang.String optionalKeyPrefix, java.util.Locale locale)
          A convenience using the service() and the specified locale.
 java.lang.String helpDirectoryForLocale(java.util.Locale locale)
          Returns the locale directory that contains help for the specified locale.
 java.util.Map imageMap(java.util.Locale locale)
          Returns an image map localized in the specified locale.
static boolean isNlsKey(java.lang.String str)
          A convenience for checking if a given string is a resource key.
 java.lang.String[] parseCompositeKey(java.lang.String compositeKey)
          Break a composite key into its parts.
static void popOverlayForTable(java.lang.String tableName, java.lang.String prev)
          Pop a previously pushed overlay from the thread state
static java.lang.String pushOverlayForTable(java.lang.String tableName, java.lang.String overlayTableName)
          Called by app code to push an "overlay" resource file for a particular file onto the current thread state.
static void registerDynamicTableName(java.lang.String tableName)
          Called by app code at initialization to register resource files ("tables") that may later be overlaid via pushOverlayForTable()
 void registerStringProcessor(StringTableProcessor processor)
          register string processor.
 java.lang.String reportTemplateDirectoryForLocale(java.util.Locale locale)
          Returns the locale directory that contains reports template for the specified locale.
static ResourceService serviceCouldBeNull()
          Returns pointer to shared ResourceService.
 void setDefaultLocale(java.util.Locale locale)
          Sets the default locale.
 void setLocales(java.util.List locales)
          This is to add a backdoor to ResourceService for LocaleID to set a list of Locale UniqueNames
 void setOverrideLocale(java.util.Locale overrideLocale)
          This is to add a backdoor to ResourceService to allow docs and QA folks to force the HTML UI to render in a certain locale.
 void setOverrideLocaleOn(boolean overrideLocaleOn)
          This is to add a backdoor to ResourceService to allow docs and QA folks to force the HTML UI to render in a certain locale.
static void setService(ResourceService service)
          Sets up the shared ResourceService.
static java.lang.String string(java.lang.String stringTable, java.lang.String key)
          Deprecated. Replaced by getString(String, String)
static java.lang.String string(java.lang.String stringTable, java.lang.String key, java.util.Locale locale)
          Deprecated. Replaced by getString(String, String, Locale)
 java.util.Map stringTable(java.lang.String path, java.util.Locale locale)
          Returns a string table with the specified path in the specified locale.
 java.util.Map stringTable(java.lang.String path, java.util.Locale locale, boolean defaultingSystem)
          Returns a string table with the specified path in the specified locale.
 java.util.Map stringTable(java.lang.String path, java.util.Locale locale, StringTableProcessor processor)
          Returns a string table with the specified path in the specified locale.
 java.util.Map stringTable(java.lang.String path, java.util.Locale locale, StringTableProcessor processor, boolean defaultingLocale)
          Returns a string table with the specified path in the specified locale.
 java.util.Map stringTable(java.lang.String path, java.util.Locale locale, StringTableProcessor processor, boolean defaultingLocale, boolean defaultingSystem)
          Returns a string table with the specified path in the specified locale.
 java.util.Map stringTableContent(java.lang.String path, java.util.Locale locale, boolean defaultingLocale, boolean defaultingSystem)
          Returns a flat string table with the specified path in the specified locale.
 java.util.Map stringTableContent(java.lang.String path, java.util.Locale locale, StringTableProcessor processor, boolean defaultingLocale, boolean defaultingSystem)
          Returns a string table with the specified path in the specified locale.
static java.lang.String translateDynamicString(java.lang.String string, java.util.Locale locale)
          Called on strings that may need further (contextual / dynamic) evaluation.
 void unsetLocalizedString(java.util.List listKeysToUnset, java.lang.String stringTableName, java.util.Locale locale)
          Updates the designated resource file's by deleting the resources pointed by the keys stored in listOfKeysToUnset.
 void verifyCSV(java.io.InputStream resourceStream, java.lang.String filePath)
          Verifies that the supplied resourceStream is a stream on a file that may legitimately be considered a CSV resource file.
 void writeStringTable(java.lang.String stringTableName, java.util.Locale locale, java.io.InputStream inputStream)
          Updates the designated resource file with contents of inputStream
 void writeStringTable(java.lang.String stringTableName, java.util.Locale locale, java.util.Map updates)
          Updates the designated resource file with the objects stored in the given Map Important: The caller is responsible for the synchronization on the file (using GlobalLocking for instance)
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NlsTag

public static final java.lang.String NlsTag
Prefix for resource keys.

See Also:
Constant Field Values

EmbeddedSubstitutionsFlag

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

ReportTemplatesDirectory

public static final java.lang.String ReportTemplatesDirectory
Reports Template directory. Value is "reporttemplates".

See Also:
Constant Field Values

LocaleOfLastResort

public static final java.util.Locale LocaleOfLastResort
Locale of last resort. Value is "en", "US", "".


baseURL

public java.net.URL baseURL
The base URL for resolving resources

Constructor Detail

ResourceService

public ResourceService(java.net.URL baseURL,
                       java.util.Locale defaultLocale)
Creates a new ResourceService with the given base URL and default locale.

Parameters:
baseURL - base URL
defaultLocale - default locale

ResourceService

public ResourceService(java.net.URL stringBaseURL,
                       java.net.URL baseURL,
                       java.util.Locale defaultLocale)
Method Detail

checkForService

public static ResourceService checkForService()
Returns a reference to the shared ResourceService. Does not create one if a service doesn't exist.

Returns:
reference to shared ResourceService; may be null;

getService

public static ResourceService getService()
Returns a reference to the shared ResourceService. Unlike other service objects (base, core, fields), getService() always returns a non-null reference to a ResourceService object.

Returns:
ResourceService an instance of the resource service which can be used to invoke non static methods. Do not save this pointer past the end of your method invocation as it may change depending on the application context at a later point.

serviceCouldBeNull

public static ResourceService serviceCouldBeNull()
Returns pointer to shared ResourceService. Does not create one if it does not exist.

Returns:
shared ResourceService; may be null

setService

public static void setService(ResourceService service)
Sets up the shared ResourceService. This should only be called once for a process/applet.

Parameters:
service - shared ResourceService

getString

public static java.lang.String getString(java.lang.String stringTable,
                                         java.lang.String key)
A convenience using the service() and the locale, which is obtained by calling getLocale().

Parameters:
stringTable - the name of the string table to retrieve the resource from.
key - they key to look up in that resource table.
Returns:
String the value mapped in that string table.
See Also:
getLocale()

string

public static java.lang.String string(java.lang.String stringTable,
                                      java.lang.String key)
Deprecated. Replaced by getString(String, String)

Looks up the string in the given table using the given key.

Parameters:
stringTable - table
key - key

getString

public static java.lang.String getString(java.lang.String stringTable,
                                         java.lang.String key,
                                         java.util.Locale locale)
A convenience using the service() and the specified locale.

Parameters:
stringTable - the name of the string table to retrieve the resource from.
key - they key to look up in that resource table.
locale - the locale to use for determining which translation of the string table to use.
Returns:
String the value mapped in that string table.

getString

public static java.lang.String getString(java.lang.String stringTable,
                                         java.lang.String key,
                                         java.lang.String optionalKeyPrefix,
                                         java.util.Locale locale)
A convenience using the service() and the specified locale. Looks up the value of the key or a combination of the key and the prefix. The priority is given to the value associated with the combination key and prefix. If the combination key, does not have an associated value, it defaults to the value associated with the key.

Parameters:
stringTable - the name of the string table to retrieve the resource from.
key - they key to look up in that resource table.
optionalKeyPrefix - key prefix if any.
locale - the locale to use for determining which translation of the string table to use.
Returns:
String the value mapped in that string table.

getString

public static java.lang.String getString(java.lang.String stringTable,
                                         java.lang.String key,
                                         java.util.Locale locale,
                                         boolean displayWarning)
A convenience using the service(), the specified locale, and whether to display a warning if not found.

Parameters:
stringTable - the name of the string table to retrieve the resource from.
key - they key to look up in that resource table.
locale - the locale to use for determining which translation of the string table to use.
displayWarning - if false and the key is not found in the specified table a warning will be suppressed rather than printed.
Returns:
String the value mapped in that string table.

string

public static java.lang.String string(java.lang.String stringTable,
                                      java.lang.String key,
                                      java.util.Locale locale)
Deprecated. Replaced by getString(String, String, Locale)

Looks up the string in the given table using the given key and locale.

Parameters:
stringTable - table
key - key
locale - locale

isNlsKey

public static boolean isNlsKey(java.lang.String str)
A convenience for checking if a given string is a resource key.

Parameters:
str - a string to check if it follows our convention for a resource key. A null will always return false.
Returns:
true if and only if it begins with an @.

setOverrideLocale

public void setOverrideLocale(java.util.Locale overrideLocale)
This is to add a backdoor to ResourceService to allow docs and QA folks to force the HTML UI to render in a certain locale.

Parameters:
overrideLocale - locale to use as an override

getOverrideLocale

public java.util.Locale getOverrideLocale()
This is to add a backdoor to ResourceService to allow docs and QA folks to force the HTML UI to render in a certain locale.

Returns:
override locale

setOverrideLocaleOn

public void setOverrideLocaleOn(boolean overrideLocaleOn)
This is to add a backdoor to ResourceService to allow docs and QA folks to force the HTML UI to render in a certain locale.

Parameters:
overrideLocaleOn - flag for override locale

getOverrideLocaleOn

public boolean getOverrideLocaleOn()
This is to add a backdoor to ResourceService to allow docs and QA folks to force the HTML UI to render in a certain locale.

Returns:
override locale flag

setLocales

public void setLocales(java.util.List locales)
This is to add a backdoor to ResourceService for LocaleID to set a list of Locale UniqueNames

Parameters:
locales - list of Locale UniqueName Strings

getLocales

public java.util.List getLocales()
This is to add a backdoor to ResourceService for Inspector to get a list of Locale UniqueName Strings

Returns:
the list of Locale UniqueName Strings

getLocale

public java.util.Locale getLocale()
Returns the "default" locale that clients should use. This locale is also used for the locale-less versions of the localized* methods. This is to be used over Locale.getDefault() because this method may be overridden by subclassers to return the appropriate locale.

Returns:
the current Locale for the application context at the time it is invoked.

getRestrictedLocale

public java.util.Locale getRestrictedLocale(java.util.Locale locale)
Get a locale that is guaranteed to be available to the realm. A realm may not have all locales available to it, for ui display. This method will check the locale, make sure it is one of the ones available to the realm, or swizzle to an available locale.

Parameters:
locale - - the prospective locale
Returns:
the locale that the realm can use

getDefaultLocale

public java.util.Locale getDefaultLocale()
Returns the default locale. See definition of default locale, above. Note that the locale() method by contrast returns the locale of last resort, at least in this implementation (subclasses presumably might return something different).

Returns:
the Locale that this application has associated with the given context when the code is run. It may be specific to the user who triggered the action.

setDefaultLocale

public void setDefaultLocale(java.util.Locale locale)
Sets the default locale. See definition of default locale, above. Note that the locale() method by contrast returns the locale of last resort, at least in this implementation (subclasses presumably might return something different).

Parameters:
locale - locale to set as the default

getDefaultImagesRoot

public java.lang.String getDefaultImagesRoot()
Returns the defaultImagesRoot.

Returns:
a string as a file path for root directory for images.

registerStringProcessor

public void registerStringProcessor(StringTableProcessor processor)
register string processor. we need to know this so that when clearCache is called, we can also callback to those string processor and clean all string caches out.

Parameters:
processor - the StringTableProcessor to register, must not be null.

clearCache

public void clearCache()
Allows you to "reboot" the Resource Manager, so you don't have to shut down everything just to reload a string resource that's changed on disk.


getLocalizedHelpPath

public java.lang.String getLocalizedHelpPath(java.lang.String helpPath)
Returns the path of the root of the help system for this service's locale.

Parameters:
helpPath - helpPath to localize
Returns:
localized help path

getLocalizedHelpPath

public java.lang.String getLocalizedHelpPath(java.lang.String helpPath,
                                             java.util.Locale locale)
Returns the path of the root of the help system for the specified locale.

Parameters:
helpPath -
locale -

helpDirectoryForLocale

public java.lang.String helpDirectoryForLocale(java.util.Locale locale)
Returns the locale directory that contains help for the specified locale.

Parameters:
locale - locale
Returns:
help directory for locale

reportTemplateDirectoryForLocale

public java.lang.String reportTemplateDirectoryForLocale(java.util.Locale locale)
Returns the locale directory that contains reports template for the specified locale.

Parameters:
locale - locale
Returns:
reports template directory for locale

getLocalizedString

public java.lang.String getLocalizedString(java.lang.String stringTable,
                                           java.lang.String key)
Lookup a localized string for this service's locale, which is obtained by calling getLocale().

Parameters:
stringTable - the name of the stringTable to use
key - the key to lookup in the string table for the locale
Returns:
a localized string for this service's locale.
See Also:
getLocale()

getLocalizedString

public java.lang.String getLocalizedString(java.lang.String stringTable,
                                           java.lang.String key,
                                           java.util.Locale locale)
Lookup a localized string for the specified locale. Will display an error message if the key cannot be resolved.

Parameters:
stringTable - the name of the stringTable to use
key - the key to lookup in the string table for the locale
locale - the locale to format the string in
Returns:
a localized string in the specified locale.

getLocalizedString

public java.lang.String getLocalizedString(java.lang.String stringTable,
                                           java.lang.String key,
                                           java.util.Locale locale,
                                           boolean displayWarning)
Lookup a localized string for the specified locale.

Parameters:
stringTable - the name of the stringTable to use
key - the key to lookup in the string table for the locale
locale - the locale to format the string in
displayWarning - toggles the display of missing-key warning
Returns:
a localized string in the specified locale.

getLocalizedString

public java.lang.String getLocalizedString(java.lang.String stringTable,
                                           java.lang.String key,
                                           java.util.Locale locale,
                                           boolean displayWarning,
                                           boolean defaultingLocale,
                                           boolean defaultingSystem)
Lookup a localized string for the specified locale.

Parameters:
stringTable - the name of the stringTable to use
key - the key to lookup in the string table for the locale
locale - the locale to format the string in
displayWarning - toggles the display of missing-key warning
defaultingLocale - toggles defaulting to canonical/lastresort locale
defaultingSystem - toggles defaulting to system resource This is being overwritten by BaseResourceService.java, only meaningful for realm resources.

getLocalizedString

public java.lang.String getLocalizedString(java.lang.String stringTable,
                                           java.lang.String key,
                                           java.util.Locale locale,
                                           boolean displayWarning,
                                           boolean defaultingLocale)
Lookup a localized string for the specified locale.

Parameters:
stringTable - the name of the stringTable to use
key - the key to lookup in the string table for the locale
locale - the locale to format the string in
displayWarning - toggles the display of missing-key warning
defaultingLocale - toggles defaulting to canonical/lastresort locale
Returns:
a localized string in the specified locale. If defaulting is set to false and no string was found, it will return null. If defaulting is true and no string is found, the *key* is returned. Logging *relies* on this behavior.

getLocalizedFormat

public java.lang.String getLocalizedFormat(java.lang.String stringTable,
                                           java.lang.String key,
                                           java.util.Locale locale)
Lookup a localized string for the specified locale. It is the same as getLocalizedString in Util

Parameters:
stringTable - the name of the stringTable to use
key - the key to lookup in the string table for the locale
locale - the locale to format the string in This is being overwritten by BaseResourceService.java, only meaningful for realm resources.

getLocalizedFormat

public java.lang.String getLocalizedFormat(java.lang.String stringTable,
                                           java.lang.String key,
                                           java.util.Locale locale,
                                           boolean displayWarning,
                                           boolean defaultingLocale,
                                           boolean defaultingSystem)
Lookup a localized string for the specified locale. It is the same as getLocalizedString in Util

Parameters:
stringTable - the name of the stringTable to use
key - the key to lookup in the string table for the locale
locale - the locale to format the string in
displayWarning - toggles the display of missing-key warning
defaultingLocale - toggles defaulting to canonical/lastresort locale
defaultingSystem - toggles defaulting to system resource This is being overwritten by BaseResourceService.java, only meaningful for realm resources.

getLocalizedCompositeKey

public java.lang.String getLocalizedCompositeKey(java.lang.String string,
                                                 java.util.Locale locale)
If the specified string starts with an '@', it is assummed to be a composed localized string key (the string table and key are concatenated, separated by a slash (e.g. "@AStringTable/MyString"), and it will be localized in the specified locale. If the string does not start with an '@', the string itself is returned.

Parameters:
string - string to localize
locale - locale
Returns:
localized composite key

getLocalizedCompositeKey

public java.lang.String getLocalizedCompositeKey(java.lang.String string,
                                                 java.util.Locale locale,
                                                 boolean displayWarning)
If the specified string starts with an '@', it is assummed to be a composed localized string key (the string table and key are concatenated, separated by a slash (e.g. "@AStringTable/MyString"), and it will be localized in the specified locale. If the string does not start with an '@', the string itself is returned.

Parameters:
string - string to localize
locale - locale
displayWarning - toggles the display of missing-key warning
Returns:
localized composite key

registerDynamicTableName

public static void registerDynamicTableName(java.lang.String tableName)
Called by app code at initialization to register resource files ("tables") that may later be overlaid via pushOverlayForTable()

Parameters:
tableName - Name of resource file that will be overlaid (e.g. "sourcing.core.Content")

pushOverlayForTable

public static java.lang.String pushOverlayForTable(java.lang.String tableName,
                                                   java.lang.String overlayTableName)
Called by app code to push an "overlay" resource file for a particular file onto the current thread state. Calling code should stash the returned (original) string, and pass it back in a bracketed call to popOverlayForTable() (App code should be run in a try {} finally block, with pop called in finally

Parameters:
tableName - file to be overlaid (e.g. "sourcing.core.Content")
overlayTableName - the overlay file (e.g. "sourcing.core.Content.Survey")
Returns:
previous value for this key -- should be passed back to pop call

popOverlayForTable

public static void popOverlayForTable(java.lang.String tableName,
                                      java.lang.String prev)
Pop a previously pushed overlay from the thread state

Parameters:
tableName - file that had been overlaid (e.g. "sourcing.core.Content")
prev - the value returned from the corresponding call to push...()

getLocalizedCompositeKey

public java.lang.String getLocalizedCompositeKey(java.lang.String string,
                                                 java.util.Locale locale,
                                                 boolean displayWarning,
                                                 boolean defaulting)
If the specified string starts with an '@', it is assummed to be a composed localized string key (the string table and key are concatenated, separated by a slash (e.g. "@AStringTable/MyString"), and it will be localized in the specified locale. If the string does not start with an '@', the string itself is returned.

Parameters:
string - string to localize
locale - locale
displayWarning - toggles the display of missing-key warning
defaulting - toggles defaulting to rooted/last resort locale
Returns:
localized composite key

getLocalizedCompositeKey

public java.lang.String getLocalizedCompositeKey(java.lang.String string,
                                                 java.util.Locale locale,
                                                 boolean displayWarning,
                                                 boolean defaulting,
                                                 boolean resolveDynamicKeys)
If the specified string starts with an '@', it is assummed to be a composed localized string key (the string table and key are concatenated, separated by a slash (e.g. "@AStringTable/MyString"), and it will be localized in the specified locale. If the string does not start with an '@', the string itself is returned.

Parameters:
string - string to localize
locale - locale
displayWarning - toggles the display of missing-key warning
defaulting - toggles defaulting to rooted/last resort locale
resolveDynamicKeys - whether keys that support dynamic substitution should be resolved. If false, caller should later call getLocalizedStringWithDynamicResolution() at display time to get the final version
Returns:
localized composite key

translateDynamicString

public static java.lang.String translateDynamicString(java.lang.String string,
                                                      java.util.Locale locale)
Called on strings that may need further (contextual / dynamic) evaluation. E.g if a resource string was not fully resolved at the time of field properties initialization (because it referenced a resource file that was registered as Dynamic (see ResourceService.registerDynamicTableName())) then this will perform that file resolution.


parseCompositeKey

public java.lang.String[] parseCompositeKey(java.lang.String compositeKey)
Break a composite key into its parts. For the resource service, a "composite key" is a key of the form: "@stringtable/key" where stringtable is the name of some resource string table and the key is a key within that file. This method will break up such a key into its parts. The 0th element of the return value is the string table and the 1th element is the key. If the compositeKey is not of the composite key form then the the 0th element will be null and the string will just be the composite key

Parameters:
compositeKey - The composite key to be parsed
Returns:
the parsed composite key

getLocalizedCompositeFormat

public java.lang.String getLocalizedCompositeFormat(java.lang.String string,
                                                    java.util.Locale locale,
                                                    boolean displayWarning,
                                                    boolean defaulting)

createLocalizedMap

public static void createLocalizedMap(java.util.Map table,
                                      java.util.Locale locale)
If a Map contains a string starting with an '@', it is assumed to be a localized string key which is localized using the localizedCompositeKey(). This is a recursive method.

Parameters:
table - data for creating map
locale - locale for creating map

stringTable

public java.util.Map stringTable(java.lang.String path,
                                 java.util.Locale locale)
Returns a string table with the specified path in the specified locale.

Parameters:
path - path
locale - locale
Returns:
string table with the specified path in the specified locale

stringTable

public java.util.Map stringTable(java.lang.String path,
                                 java.util.Locale locale,
                                 boolean defaultingSystem)
Returns a string table with the specified path in the specified locale.

Parameters:
path - path
locale - locale
defaultingSystem - defaulting to system
Returns:
string table with the specified path in the specified locale

stringTable

public java.util.Map stringTable(java.lang.String path,
                                 java.util.Locale locale,
                                 StringTableProcessor processor)
Returns a string table with the specified path in the specified locale.

Parameters:
path - path
locale - locale
processor - customer string csv processor
Returns:
string table with the specified path in the specified locale

stringTable

public java.util.Map stringTable(java.lang.String path,
                                 java.util.Locale locale,
                                 StringTableProcessor processor,
                                 boolean defaultingLocale)
Returns a string table with the specified path in the specified locale.

Parameters:
path - path
locale - locale
processor - customer string csv processor
defaultingLocale - toggle defaulting to relaxed locale
Returns:
string table with the specified path in the specified locale

stringTable

public java.util.Map stringTable(java.lang.String path,
                                 java.util.Locale locale,
                                 StringTableProcessor processor,
                                 boolean defaultingLocale,
                                 boolean defaultingSystem)
Returns a string table with the specified path in the specified locale.

Parameters:
path - path
locale - locale
processor - customer string csv processor
defaultingLocale - toggle defaulting to relaxed locale
defaultingSystem - toggles defaulting to system resource
Returns:
string table with the specified path in the specified locale

stringTableContent

public java.util.Map stringTableContent(java.lang.String path,
                                        java.util.Locale locale,
                                        boolean defaultingLocale,
                                        boolean defaultingSystem)
Returns a flat string table with the specified path in the specified locale.

Parameters:
path - path
locale - locale
defaultingLocale - toggle defaulting to relaxed locale
defaultingSystem - toggles defaulting to system resource
Returns:
string table with the specified path in the specified locale

stringTableContent

public java.util.Map stringTableContent(java.lang.String path,
                                        java.util.Locale locale,
                                        StringTableProcessor processor,
                                        boolean defaultingLocale,
                                        boolean defaultingSystem)
Returns a string table with the specified path in the specified locale.

Parameters:
path - path
locale - locale
processor - customer string csv processor
defaultingLocale - toggle defaulting to relaxed locale
defaultingSystem - toggles defaulting to system resource
Returns:
string table with the specified path in the specified locale

cacheStringTable

public void cacheStringTable(java.lang.String path,
                             java.util.Map stringTable)
Allows you to prepopulate the string table cache. Used for optimizing RPC. Not for general use.

Parameters:
path - path
stringTable - string table to populate
See Also:
ariba.base.client.BaseClient#getStartupInfo

cacheStringTable

public void cacheStringTable(java.lang.String path,
                             java.util.Locale locale,
                             java.util.Map stringTable,
                             StringTableProcessor processor)
Allows you to prepopulate the string table cache. This should be used for optimization of RPC or for by StringTableProcessor only.

Parameters:
path - path
locale - locale for the resource table
stringTable - string table to populate
processor - the processor who processed the table

_setPseudoLocalizer

public static void _setPseudoLocalizer(ResourceService.PseudoLocalizer pl)

_getPseudoLocalizer

public static ResourceService.PseudoLocalizer _getPseudoLocalizer()

getAllStringTableNames

public java.util.Set<java.lang.String> getAllStringTableNames(java.util.Locale locale)
Returns the set of all string table names that exist and may contain resources for the specified locale.


verifyCSV

public void verifyCSV(java.io.InputStream resourceStream,
                      java.lang.String filePath)
               throws java.io.IOException
Verifies that the supplied resourceStream is a stream on a file that may legitimately be considered a CSV resource file.

By this we mean that the CSVReader can parse the file with a CSVStringTableConsumer consuming the tokens.

No exception is thrown if the stream is good. NOTE:

Parameters:
resourceStream - the stream to check
filePath - the logical name of the resource (for debugging and error messages)
Throws:
java.io.IOException - if resourceStream can not be considered a CSV resource file

writeStringTable

public void writeStringTable(java.lang.String stringTableName,
                             java.util.Locale locale,
                             java.util.Map updates)
                      throws java.io.IOException,
                             FileReplacer.BadStateException
Updates the designated resource file with the objects stored in the given Map Important: The caller is responsible for the synchronization on the file (using GlobalLocking for instance)

Parameters:
stringTableName - the name of the resource table to update
locale - the locale of the resources
updates - the map with only the key/value to update or add. For deletion see unsetLocalizedString(List, String, Locale)
Throws:
FileReplacer.BadStateException - when the system is in an unstable state
java.io.IOException - when the operation didn't succeed

writeStringTable

public void writeStringTable(java.lang.String stringTableName,
                             java.util.Locale locale,
                             java.io.InputStream inputStream)
                      throws java.io.IOException,
                             FileReplacer.BadStateException
Updates the designated resource file with contents of inputStream

Important notes:

Parameters:
stringTableName - the name of the resource table to update
locale - the locale of the resources
inputStream - the new file that will replace the stringTable identified by stringTableName
Throws:
FileReplacer.BadStateException - when the system is in an unstable state
java.io.IOException - when the operation didn't succeed

unsetLocalizedString

public void unsetLocalizedString(java.util.List listKeysToUnset,
                                 java.lang.String stringTableName,
                                 java.util.Locale locale)
                          throws java.io.IOException,
                                 FileReplacer.BadStateException
Updates the designated resource file's by deleting the resources pointed by the keys stored in listOfKeysToUnset.

Parameters:
listKeysToUnset - the list of keys to delete from the resource file
stringTableName - the name of the resource file
locale - the locale of the resource to delete
Throws:
FileReplacer.BadStateException - when the system reached an unrecoverable state
java.io.IOException - when the operation didn't succeed

getLocalizedImagePath

public java.lang.String getLocalizedImagePath(java.lang.String path)
Returns a localized image path in the service's locale.

Parameters:
path - path
Returns:
localized image path for service's locale

getLocalizedImagePath

public java.lang.String getLocalizedImagePath(java.lang.String path,
                                              java.util.Locale locale)
Returns a localized image path in the specified locale. The path is relative to the resource URL - meaning there is no leading slash in the return value.

Parameters:
path - path
locale -
Returns:
localized image path

imageMap

public java.util.Map imageMap(java.util.Locale locale)
Returns an image map localized in the specified locale. Provides caching on top of getImageMap.

Parameters:
locale - locale
Returns:
localized image map

cacheImageMap

public void cacheImageMap(java.util.Map imageMap,
                          java.util.Locale locale)
Puts the imageMap in the cache under the given locale.

Parameters:
imageMap - image map
locale - locale with which the image map will be associated

getSearchDirs

public java.util.List<java.util.Locale> getSearchDirs(java.util.Locale givenLocale,
                                                      boolean defaulting)
Returns list of directories to search for the given locale.

Parameters:
givenLocale -
defaulting - toggles between defaulting to relaxed locale or not
Returns:
list of directories to search for locale

descendAndLocalizeObject

public java.lang.Object descendAndLocalizeObject(java.lang.Object object,
                                                 java.util.Locale locale,
                                                 ResourceService.Localizer localizer)
Traverses an object (if it is an Map, List, or String), and for all strings that start with '@', replaces it with a localized string for the specified locale, using the method getLocalizedCompositeKey(java.lang.String, java.util.Locale). Will return a copy of the appropriate sub-structure if any localization is done--this can be understood as the fact that object is not modified.

If the object is not a Map, List or a String, it is not altered and simply returned.

Parameters:
object - the object to traverse and localize
locale - the Locale for which the localization should be done
Returns:
the localized version of object

descendAndLocalizeObject

public java.lang.Object descendAndLocalizeObject(java.lang.Object object,
                                                 java.util.Locale locale)
Traverses an object (if it is an Map, List, or String), and for all strings that start with '@', replaces it with a localized string for the specified locale, using the method getLocalizedCompositeKey(java.lang.String, java.util.Locale). Will return a copy of the appropriate sub-structure if any localization is done--this can be understood as the fact that object is not modified.

If the object is not a Map, List or a String, it is not altered and simply returned.

Parameters:
object - the object to traverse and localize
locale - the Locale for which the localization should be done
Returns:
the localized version of object

findResourceURL

public java.lang.String findResourceURL(java.lang.String filename,
                                        java.util.Locale locale)
Returns the url string of file for the given locale

Parameters:
filename - name of the file
locale - locale for the file path
Returns:
url string of the file for the given locale

getDefaultStringTableProcessor

public StringTableProcessor getDefaultStringTableProcessor()


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.