wt.templateutil.processor
Class ContextBasedLocalizedResourceSrv

java.lang.Object
  extended bywt.templateutil.processor.ContextBasedLocalizedResourceSrv
All Implemented Interfaces:
ApplicationContextChild

public class ContextBasedLocalizedResourceSrv
extends Object
implements ApplicationContextChild

Presents a generalized service for locating localized resources via entries in *.property files. This is a merging of the ApplicationContextServices registry method for locating a resource and the LocalizedResource service method of finding a localized version of a given resource. A specific use of such a service would be generate the path to localized icons.

To use this class, you need to have an entry in service.properties of the following form : wt.services/rsc/default/LocalizedResourceService/<Context String>/<Context Class>/0=<Relative path from codebase>

an example of such an entry is : wt.services/rsc/default/LocalizedResourceService/HELP/java.lang.Object/0=wt.clients.images.helphtml.gif

The Context String and the Context Class will be passed in as arguments in the call to get the localized resource.

The Relative path from codebase will be the path to the file, where the filename is NOT localized.


Field Summary
private  String[] alternateExtensions
           
private  ApplicationContext applicationContext
           
private  boolean closeInputStream
           
private  Locale locale
           
private  LocalizedResource localizedResource
           
private  InputStream localizedResourceInputStream
           
protected  char newFileSeparator
           
protected  char oldFileSeparator
           
private  Vector preferences
           
private static String RESOURCE
           
private static boolean VERBOSE
           
private static String versionID
           
 
Fields inherited from interface wt.services.applicationcontext.ApplicationContextChild
APPLICATION_CONTEXT
 
Constructor Summary
ContextBasedLocalizedResourceSrv()
           
 
Method Summary
 String[] getAlternateExtensions()
          Returns the current set of alternate extensions to be used when searching for a localized resource.
 ApplicationContext getApplicationContext()
          Gets the object for the association that plays role: APPLICATION_CONTEXT.
 ApplicationContextServices getApplicationContextServices()
           
 Locale getLocale()
          Returns the current Locale.
 Vector getPreferences()
          Return the vector of preferences to be used to determine the Locale to use if the Locale has not been set directly with a call to the setLocale method.
 InputStream getResourceInputStream(String action, Object obj)
           
 String getResourcePath(String action, Object obj)
          Uses the ApplicationContextService with the String and Object as the Context to select a base path for a localized resource.
 String getResourceURL(String action, Object obj)
          Returns the full URL to a resource, assuming that the resource is somewhere under the codebase directory.
static void main(String[] args)
          Used to test if a certain localized resource is is being found by the service.
 String processResourceName(String resourceFileName)
          Replaces the "." in the String returned from a *.property file with the correct file separator.
 void setAlternateExtensions(String[] new_Extensions)
          Sets the allowed alternate extensions when searching for a localized resource.
 void setApplicationContext(ApplicationContext a_ApplicationContext)
          Sets the object for the association that plays role: APPLICATION_CONTEXT.
 void setLocale(Locale new_locale)
          Set the Locale to be used to select the localized resource.
 void setPreferences(Vector new_Preferences)
          Sets the vector of preferences to be used to determine the Locale to use if the Locale has not been set directly with a call to the setLocale method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

versionID

private static final String versionID
See Also:
Constant Field Values

applicationContext

private ApplicationContext applicationContext

VERBOSE

private static boolean VERBOSE

locale

private Locale locale

preferences

private Vector preferences

alternateExtensions

private String[] alternateExtensions

closeInputStream

private boolean closeInputStream

localizedResource

private LocalizedResource localizedResource

localizedResourceInputStream

private InputStream localizedResourceInputStream

oldFileSeparator

protected char oldFileSeparator

newFileSeparator

protected char newFileSeparator
Constructor Detail

ContextBasedLocalizedResourceSrv

public ContextBasedLocalizedResourceSrv()
                                 throws UnableToLoadServiceProperties
Method Detail

setLocale

public void setLocale(Locale new_locale)
Set the Locale to be used to select the localized resource.

Parameters:
new_locale -

getLocale

public Locale getLocale()
Returns the current Locale. This Locale will be used to define the Locale of the localized resource.

Returns:
Locale

setPreferences

public void setPreferences(Vector new_Preferences)
Sets the vector of preferences to be used to determine the Locale to use if the Locale has not been set directly with a call to the setLocale method.

Parameters:
new_Preferences -

getPreferences

public Vector getPreferences()
Return the vector of preferences to be used to determine the Locale to use if the Locale has not been set directly with a call to the setLocale method.

Returns:
Vector

setAlternateExtensions

public void setAlternateExtensions(String[] new_Extensions)
Sets the allowed alternate extensions when searching for a localized resource.

For example, when searching for an HTML page, you would like to be able to search for a file name with either the *.html or the *.htm extension. Setting this String array is how you specify these options

Parameters:
new_Extensions -

getAlternateExtensions

public String[] getAlternateExtensions()
Returns the current set of alternate extensions to be used when searching for a localized resource.

For example, when searching for an HTML page, you would like to be able to search for a file name with either the *.html or the *.htm extension. Setting this String array is how you specify these options

Returns:
String[]

getResourcePath

public String getResourcePath(String action,
                              Object obj)
                       throws WTException
Uses the ApplicationContextService with the String and Object as the Context to select a base path for a localized resource. Then, using a localized resource is selected.

Parameters:
action - The context String used in the ApplicationContextServices lookup
obj - The class of this Object is used to define the Context Class used in the ApplicationContextServices lookup
Returns:
String The path, relative to codebase, to the the localized resource
Throws:
WTException

processResourceName

public String processResourceName(String resourceFileName)
Replaces the "." in the String returned from a *.property file with the correct file separator.

Parameters:
resourceFileName - Entry from the a *.property file
Returns:
String Processed String with "." replaced by File.separator

getResourceURL

public String getResourceURL(String action,
                             Object obj)
                      throws WTException
Returns the full URL to a resource, assuming that the resource is somewhere under the codebase directory.

Parameters:
action - The context String used in the ApplicationContextServices service
obj - The class of this Object is used to define the class to be used in the ApplicationContextServices service
Returns:
String URL to a localized resource
Throws:
WTException

getResourceInputStream

public InputStream getResourceInputStream(String action,
                                          Object obj)
                                   throws WTException
Throws:
WTException

getApplicationContextServices

public ApplicationContextServices getApplicationContextServices()

getApplicationContext

public ApplicationContext getApplicationContext()
Description copied from interface: ApplicationContextChild
Gets the object for the association that plays role: APPLICATION_CONTEXT.

Supported API: false

Specified by:
getApplicationContext in interface ApplicationContextChild
Returns:
ApplicationContext

setApplicationContext

public void setApplicationContext(ApplicationContext a_ApplicationContext)
                           throws WTPropertyVetoException
Description copied from interface: ApplicationContextChild
Sets the object for the association that plays role: APPLICATION_CONTEXT.

Supported API: false

Specified by:
setApplicationContext in interface ApplicationContextChild
Parameters:
a_ApplicationContext -
Throws:
WTPropertyVetoException

main

public static void main(String[] args)
Used to test if a certain localized resource is is being found by the service.

To run this test, enter the following command line call

java wt.templateutil.processor.ContextBasedLocalizedResourceSrv <Context String> <Locale>