org.pfsw.nls
Class NLSIniFileDetector

java.lang.Object
  extended by org.pfsw.nls.NLSIniFileDetector

public class NLSIniFileDetector
extends java.lang.Object

This class is responsible to lookup the classpath for a specified base name to which it depends the file extension ".ini". All found files are read to retrieve the included metadata which defines which texts for which locale can be found in which file. Eventually it provides a FileLocator per locale which allows to load the associated texts with a NLSIniFileLoader.


Field Summary
static boolean DEBUG
           
static java.lang.String DEFAULT_FILE_EXTENSTION
           
protected static java.lang.String FILE_MAPPING_SECTION
           
 
Constructor Summary
NLSIniFileDetector()
          Initialize the new instance with default values.
 
Method Summary
protected  void addFileMappings(org.pfsw.settings.Settings settings)
           
protected  org.pfsw.util.CollectionUtil coll()
           
 boolean detect(java.lang.String baseName)
          Detects all meta information files for the given base name on the current NLS lookup path.
 org.pfsw.file.FileLocator getFileForLocales(java.util.Locale locale)
          Returns the file locator for the given locale or null if not found.
protected  java.util.Map getFileMappings()
           
 org.pfsw.file.FileLocator[] getFilesForLocales(java.util.Locale[] locales)
          Returns a file locators for wich a mapping to the given locales have been found.
protected  org.pfsw.file.Classpath getLookupPath()
           
protected  NLSUtil nls()
           
protected  void readFileMapping(org.pfsw.file.ClasspathElement element, java.lang.String filename)
           
protected  void readFileMappingsFor(java.lang.String filename, org.pfsw.file.Classpath classpath)
          Read all classes specified in the given file, if it exists in the specified classpath element.
protected  void reset()
           
protected  void setFileMappings(java.util.Map newValue)
           
protected  void setLookupPath(org.pfsw.file.Classpath newValue)
           
protected  org.pfsw.text.StringUtil str()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static final boolean DEBUG

DEFAULT_FILE_EXTENSTION

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

FILE_MAPPING_SECTION

protected static final java.lang.String FILE_MAPPING_SECTION
See Also:
Constant Field Values
Constructor Detail

NLSIniFileDetector

public NLSIniFileDetector()
Initialize the new instance with default values.

Method Detail

getFileMappings

protected java.util.Map getFileMappings()

setFileMappings

protected void setFileMappings(java.util.Map newValue)

getLookupPath

protected org.pfsw.file.Classpath getLookupPath()

setLookupPath

protected void setLookupPath(org.pfsw.file.Classpath newValue)

detect

public boolean detect(java.lang.String baseName)
Detects all meta information files for the given base name on the current NLS lookup path.

This path usually is the classpath. However, it can explicitly set with -Dorg.pf.nls.path=any classpath.

After calling this method the getFilesForLocales() can be used to get the names of the file that contain the NLS text data.

Parameters:
baseName - The filename without file extension (".ini" will be appended)
Returns:
true if at least one language-to-file mapping was found.

getFilesForLocales

public org.pfsw.file.FileLocator[] getFilesForLocales(java.util.Locale[] locales)
Returns a file locators for wich a mapping to the given locales have been found.

This method should be called only after detect() has been called at least once before.

Parameters:
locales - The locales for which to return the corresponding file locators

getFileForLocales

public org.pfsw.file.FileLocator getFileForLocales(java.util.Locale locale)
Returns the file locator for the given locale or null if not found.


reset

protected void reset()

readFileMappingsFor

protected void readFileMappingsFor(java.lang.String filename,
                                   org.pfsw.file.Classpath classpath)
Read all classes specified in the given file, if it exists in the specified classpath element. Add those classes to the registry if they can be instantiated and are of the correct type.

Parameters:
filename - The name of the properties file that contains the class definitions
classpath - The classpath the specified filename to be looked up in

readFileMapping

protected void readFileMapping(org.pfsw.file.ClasspathElement element,
                               java.lang.String filename)

addFileMappings

protected void addFileMappings(org.pfsw.settings.Settings settings)

coll

protected org.pfsw.util.CollectionUtil coll()

nls

protected NLSUtil nls()

str

protected org.pfsw.text.StringUtil str()