Package wt.util

Class LocalizedResource

java.lang.Object
wt.util.LocalizedResource

public class LocalizedResource extends Object
LocalizedResource contains the utility methods for finding and opening the resource that best matches the given Locale.

Supported API: true
Extendable: false
  • Constructor Details

    • LocalizedResource

      public LocalizedResource(String resourceName)

      Supported API: true
    • LocalizedResource

      public LocalizedResource(String resourceName, String alternateExtension)

      Supported API: true
  • Method Details

    • getLocale

      public Locale getLocale()
      Get the Locale object for this instance. Instance must be initialized or opened prior to call.

      Supported API: true
    • getResourceName

      public String getResourceName()
      Get the resource name that best matched. Instance must be initialized or opened prior to call.

      Supported API: true
    • setLocale

      public void setLocale(Locale locale)
      Set the Locale object for this instance. Used to override locale set when instance was initialized or opened.

      Supported API: true
    • getLocalizedResourceName

      public static String getLocalizedResourceName(WTContext aContext, String aFilename)
      Returns the Localized name of a Resource, with a specified Locale and a filename. This method supports localized backoff. The locale is 'backed off' to attempt a best guess. For example, given the locale of "en_US" and the resourceName of "resource.xxx", if resource_en_US.xxx is not found, it will attempt to find resource_en.xxx. If that in turn is not found, resource.xxx is looked for. If no best match is found, an attempt to find a best match on the server's locale is attempted. The locale will be determined from WTContext, which is set in an HTML file using the property "wt.context.locale".

      Replaces LocaleHelper.translateURLString( )

      Parameters:
      aLocale - The locale to generate the file with.
      aFilename - The filename to generate the file around.
      Returns:
      String The localized version of the String.

      Supported API: true
    • getLocalizedResourceName

      public static String getLocalizedResourceName(Locale aLocale, String aFilename)
      Returns the Localized name of a Resource, with a specified Locale and a filename. This method supports localized backoff. The locale is 'backed off' to attempt a best guess. For example, given the locale of "en_US" and the resourceName of "resource.xxx", if resource_en_US.xxx is not found, it will attempt to find resource_en.xxx. If that in turn is not found, resource.xxx is looked for. If no best match is found, an attempt to find a best match on the server's locale is attempted.

      Replaces LocaleHelper.translateURLString( )

      Parameters:
      aLocale - The locale to generate the file with.
      aFilename - The filename to generate the file around.
      Returns:
      String The localized version of the String.

      Supported API: true
    • setDebug

      public static void setDebug(boolean value)
      Sets the debug value which controls logging from this class.

      Supported API: true
    • init

      protected void init(Locale locale) throws WTException
      Look for the given resource for the given locale. If the resource is not found, the locale is 'backed off' to attempt a best guess. For example, given the locale of "en_US" and the resourceName of "resource.xxx", if resource_en_US.xxx is not found, it will attempt to find resource_en.xxx. If that in turn is not found, resource.xxx is looked for. If no best match is found, an attempt to find a best match on the server's locale is attempted.

      Supported API: true
      Parameters:
      locale - The locale to search on.
      Throws:
      WTException - Thrown if an IO exception occurs.
    • init

      protected void init() throws WTException
      Look for the given resource for the server's locale. If the resource is not found, the locale is 'backed off' to attempt a best guess. For example, given the locale of "en_US" and the resourceName of "resource.xxx", if resource_en_US.xxx is not found, it will attempt to find resource_en.xxx. If that in turn is not found, resource.xxx is looked for.

      Supported API: true
      Throws:
      WTException - Thrown if an IO exception occurs.
    • init

      public void init(Vector preferences) throws WTException
      Look for the given resource for the given locales. If the resource is not found, the locale is 'backed off' to attempt a best guess. For example, given the locale of "en_US" and the resourceName of "resource.xxx", if resource_en_US.xxx is not found, it will attempt to find resource_en.xxx. If that in turn is not found, resource.xxx is looked for. If no best match is found, an attempt to find a best match on the server's locale is attempted.

      Supported API: true
      Parameters:
      preferences - Vector containing the locales to search on.
      Throws:
      WTException - Thrown if an IO exception occurs.
    • getInputStream

      protected InputStream getInputStream() throws WTException
      Return input stream of best matching resource. Instance must be initialized or opened prior to call.

      Supported API: true
      Returns:
      BufferedInputStream.
      Throws:
      WTException - Thrown if an IO exception occurs.
    • closeInputStream

      protected void closeInputStream()
      Close input stream of this instance. Supported API: true
    • openResource

      public InputStream openResource(Locale locale) throws WTException
      Look for the given resource for the given locale. If the resource is not found, the locale is 'backed off' to attempt a best guess. For example, given the locale of "en_US" and the resourceName of "resource.xxx", if resource_en_US.xxx is not found, it will attempt to find resource_en.xxx. If that in turn is not found, resource.xxx is looked for. If no best match is found, an attempt to find a best match on the server's locale is attempted. If a best match is found, the returned input stream is already buffered for efficient reading.

      Supported API: true
      Parameters:
      locale - The locale to search on.
      Returns:
      InputStream.
      Throws:
      WTException - Thrown if an IO exception occurs.
    • openResource

      public InputStream openResource() throws WTException
      Look for the given resource for the server's locale. If the resource is not found, the locale is 'backed off' to attempt a best guess. For example, given the locale of "en_US" and the resourceName of "resource.xxx", if resource_en_US.xxx is not found, it will attempt to find resource_en.xxx. If that in turn is not found, resource.xxx is looked for. If a best match is found, load the resource into a BufferedInputStream.

      Supported API: true
      Returns:
      BufferedInputStream.
      Throws:
      WTException - Thrown if an IO exception occurs.
    • openResource

      public InputStream openResource(Vector preferences) throws WTException
      Look for the given resource for the given locales. If the resource is not found, the locale is 'backed off' to attempt a best guess. For example, given the locale of "en_US" and the resourceName of "resource.xxx", if resource_en_US.xxx is not found, it will attempt to find resource_en.xxx. If that in turn is not found, resource.xxx is looked for. If no best match is found, an attempt to find a best match on the server's locale is attempted. If a best match is found, load the resource into a BufferedInputStream.

      Supported API: true
      Parameters:
      preferences - Vector containing the locales to search on.
      Returns:
      BufferedInputStream.
      Throws:
      WTException - Thrown if an IO exception occurs.