org.zkoss.util.resource
Class Locators

java.lang.Object
  extended by org.zkoss.util.resource.Locators

public class Locators
extends java.lang.Object

Utilities to load and locate resources.

Author:
tomyeh
See Also:
Locator

Nested Class Summary
static class Locators.StreamLocation
          the location information.
static class Locators.URLLocation
          the location information.
 
Constructor Summary
Locators()
           
 
Method Summary
static Locator getDefault()
          Returns the default resource locator which is an instance of ClassLocator.
static Locators.URLLocation locate(java.lang.String file, java.util.Locale locale, Locator locator)
          Locates the filename based on the locale.
static Locators.StreamLocation locateAsStream(java.lang.String file, java.util.Locale locale, Locator locator)
          Locates the input stream based on the locale, and returns the info of StreamLocation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Locators

public Locators()
Method Detail

getDefault

public static final Locator getDefault()
Returns the default resource locator which is an instance of ClassLocator.


locate

public static final Locators.URLLocation locate(java.lang.String file,
                                                java.util.Locale locale,
                                                Locator locator)
Locates the filename based on the locale.

Example, assume file="/a/b.ext" and locale="zh_TW", then the following files are tried in sequence:
/a/b_zh_TW.ext
/a/b_zh.ext
/a/b.ext

Unlike ClassLoader.getResource, it returns the found file, not the URL. In the previous example, one of /a/b_zh_TW.ext, /a/b_zh.ext and /a/b.ext will be returned.

To get the real URL, you still require locator.getResource:
locator.getResource(Locators.locate(locator, "/a/b.ext", locale));

Note: '_' is considered as a special character in the parsing, so there might be problem if a filename contains '_' used other than locale.

Unlike Files.locate(java.lang.String), where the filename must contain '*', this method always tries to locate the file by inserting the locale before '.'. In other words, Files.locate("/a/b*.c") is similar to Locators.locate(("/a/b.c", null, a_file_locator);

Parameters:
locale - the locale; null means the current locale
Returns:
the URL containing proper locale characters; null if not found. Note: it could compare it with the file argument with ==, because this method will return the same string if it is the result.

locateAsStream

public static final Locators.StreamLocation locateAsStream(java.lang.String file,
                                                           java.util.Locale locale,
                                                           Locator locator)
Locates the input stream based on the locale, and returns the info of StreamLocation.

See Also:
locate(java.lang.String, java.util.Locale, org.zkoss.util.resource.Locator)


Copyright © 2005-2011 Potix Corporation. All Rights Reserved. SourceForge.net Logo