net.sf.mmm.util.nls.base
Class ResourceBundleSynchronizer

java.lang.Object
  extended by net.sf.mmm.util.component.base.AbstractLoggableObject
      extended by net.sf.mmm.util.cli.api.AbstractMain
          extended by net.sf.mmm.util.cli.api.AbstractVersionedMain
              extended by net.sf.mmm.util.nls.base.ResourceBundleSynchronizer

@CliClass(usage="Create and/or update resource-bundle property-files.")
@CliMode(id="default",
         title="default",
         usage="Create and/or update resource-bundle property-files from  for the given locales (including the root locale). Example:\n\n{mainClass} --bundle-class foo.bar.NlsBundleMyExample de de_DE en en_US en_GB fr zh ja_JP zh_TW\n\nFor each locale a property-file foo/bar/NlsBundleMyExample_.properties will be created or updated in the base-path. In each property-file all properties defined in  will be added with a TODO-marker and the original text as value. If the property-file already exists, all existing properties will remain unchanged and comments will be kept.")
public class ResourceBundleSynchronizer
extends AbstractVersionedMain

This class can be used to create and update the localized bundles (properties) from an AbstractResourceBundle.
It is a main-program. Simply call it with the parameter "--help" to get help. ATTENTION:
This class only works with java 6 or above.

Since:
1.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Field Summary
private  Class<? extends ResourceBundle> bundleClass
           
private  String datePattern
           
private static String DEFAULT_BASE_PATH
           
private static String DEFAULT_DATE_PATTERN
           
private static String DEFAULT_ENCODING
           
private  String encoding
           
private  String[] locales
           
private  String newline
           
static String OPTION_BUNDLE_CLASS
          The command-line option to set the bundle-class.
static String OPTION_DATE_PATTERN
          The command-line option to set the date-pattern.
static String OPTION_ENCODING
          The command-line option to set the encoding.
static String OPTION_LOCALE
          The command-line option to set the locales.
static String OPTION_PATH
          The command-line option to set the path.
private  String path
           
private  StreamUtil streamUtil
           
 
Fields inherited from class net.sf.mmm.util.cli.api.AbstractMain
EXIT_CODE_CONSTRAINT_VIOLATION, EXIT_CODE_ILLEGAL_SYNTAX, EXIT_CODE_OK, EXIT_CODE_UNEXPECTED
 
Constructor Summary
ResourceBundleSynchronizer()
          The constructor.
 
Method Summary
 Class<? extends ResourceBundle> getBundleClass()
          This method gets the Class reflecting the ResourceBundle to synchronize.
 String getDatePattern()
          This method gets the pattern used to format the date comment.
 String getEncoding()
          This method gets the encoding used to read and write the bundles.
 String[] getLocales()
          This method gets the locales of the bundles that should be synchronized.
 String getNewline()
          This method sets the newline string used to terminate a line in the resource bundle.
 String getPath()
          This method gets the base-path where the bundles are written to.
 StreamUtil getStreamUtil()
          This method gets the StreamUtilImpl instance to use.
static void main(String[] arguments)
          This is the main method used to run this class as application.
protected  int run(CliModeObject mode)
          This method is called after the options are parsed and injected.
 void setBundleClass(Class<? extends ResourceBundle> bundleClass)
          This method sets the bundle-class.
 void setDatePattern(String datePattern)
           
 void setEncoding(String encoding)
          This method sets the encoding.
 void setLocales(Locale... locales)
          This method sets the locales.
 void setLocales(String[] locales)
          This method sets the locales.
 void setNewline(String newline)
           
 void setPath(String basePath)
          This method sets the base-path.
 void setStreamUtil(StreamUtil streamUtil)
          This method sets the StreamUtil.
 void synchronize(ResourceBundle bundle)
          This method synchronizes (creates or updates) the localized bundles (properties).
protected  void synchronize(ResourceBundle bundle, String locale, String propertyPath, String date)
          Like synchronize(ResourceBundle) but for a single Locale.
 
Methods inherited from class net.sf.mmm.util.cli.api.AbstractVersionedMain
getVersion
 
Methods inherited from class net.sf.mmm.util.cli.api.AbstractMain
getIocContainer, getOutputSettings, getParserBuilder, getStandardError, getStandardOutput, handleError, printHelp, run, setStandardError, setStandardOutput, validate
 
Methods inherited from class net.sf.mmm.util.component.base.AbstractLoggableObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPTION_DATE_PATTERN

public static final String OPTION_DATE_PATTERN
The command-line option to set the date-pattern.

See Also:
Constant Field Values

OPTION_ENCODING

public static final String OPTION_ENCODING
The command-line option to set the encoding.

See Also:
Constant Field Values

OPTION_PATH

public static final String OPTION_PATH
The command-line option to set the path.

See Also:
Constant Field Values

OPTION_BUNDLE_CLASS

public static final String OPTION_BUNDLE_CLASS
The command-line option to set the bundle-class.

See Also:
Constant Field Values

OPTION_LOCALE

public static final String OPTION_LOCALE
The command-line option to set the locales.

See Also:
Constant Field Values

DEFAULT_BASE_PATH

private static final String DEFAULT_BASE_PATH
See Also:
getPath(), Constant Field Values

DEFAULT_ENCODING

private static final String DEFAULT_ENCODING
See Also:
getEncoding(), Constant Field Values

DEFAULT_DATE_PATTERN

private static final String DEFAULT_DATE_PATTERN
See Also:
getEncoding(), Constant Field Values

path

@CliOption(name="--path",
           aliases="-p",
           operand="DIR",
           usage="Write property-files to the base-path {operand} (Default is \"{default}\").")
private String path
See Also:
getPath()

encoding

@CliOption(name="--encoding",
           aliases="-e",
           operand="ENC",
           usage="Read and write property-files using the specified encoding {operand} (Default is {default}).")
private String encoding
See Also:
getEncoding()

newline

private String newline
See Also:
getNewline()

datePattern

@CliOption(name="--date-pattern",
           aliases="-d",
           operand="PATTERN",
           usage="Use the specified date pattern for writing synchronization date to property-files (Default is \"{default}\").")
private String datePattern
See Also:
getDatePattern()

locales

@CliOption(name="--locale",
           aliases="-l",
           operand="LOCALE",
           required=true,
           usage="The list of locales to synchronize. Each locale has to be in the form \"ll[_CC[_vv]]\" where \"ll\" is the lowercase ISO 639 code, CC is the uppercase ISO 3166 2-letter code and vv is an arbitrary variant. Examples are \"de\", \"en_US\" or \"th_TH_TH\".")
private String[] locales
See Also:
getLocales()

bundleClass

@CliOption(name="--bundle",
           aliases="-b",
           operand="CLASS",
           required=true,
           usage="The bundle-class for which the property-files should be created or update. It has to be the fully qualified name of a subclass of AbstractResourceBundle. For all given locales the according property-file is created or updated.")
private Class<? extends ResourceBundle> bundleClass
See Also:
getBundleClass()

streamUtil

private StreamUtil streamUtil
See Also:
getStreamUtil()
Constructor Detail

ResourceBundleSynchronizer

public ResourceBundleSynchronizer()
The constructor.

Method Detail

getDatePattern

public String getDatePattern()
This method gets the pattern used to format the date comment.

Returns:
the date pattern.
See Also:
SimpleDateFormat

setDatePattern

public void setDatePattern(String datePattern)
Parameters:
datePattern - the datePattern to set

getLocales

public String[] getLocales()
This method gets the locales of the bundles that should be synchronized. Examples for locales (entries of the returned array) are "",

Returns:
the locales to create/update.

setLocales

public void setLocales(String[] locales)
This method sets the locales.

Parameters:
locales - are the locales to set

setLocales

public void setLocales(Locale... locales)
This method sets the locales.

Parameters:
locales - are the locales to set

getPath

public String getPath()
This method gets the base-path where the bundles are written to. They will appear there under their appropriate classpath. The default is DEFAULT_BASE_PATH.

Returns:
the basePath is the base path where the resource bundles are written to.

setPath

public void setPath(String basePath)
This method sets the base-path.

Parameters:
basePath - the basePath to set

getEncoding

public String getEncoding()
This method gets the encoding used to read and write the bundles. The default is UTF-8.

Returns:
the encoding.

setEncoding

public void setEncoding(String encoding)
This method sets the encoding.

Parameters:
encoding - the encoding to set

getNewline

public String getNewline()
This method sets the newline string used to terminate a line in the resource bundle. The default is LF (\n).

Returns:
the newline

setNewline

public void setNewline(String newline)
Parameters:
newline - the newline to set

getBundleClass

public Class<? extends ResourceBundle> getBundleClass()
This method gets the Class reflecting the ResourceBundle to synchronize.

Returns:
the bundle-class.

setBundleClass

public void setBundleClass(Class<? extends ResourceBundle> bundleClass)
This method sets the bundle-class.

Parameters:
bundleClass - is the bundle-class to set

getStreamUtil

public StreamUtil getStreamUtil()
This method gets the StreamUtilImpl instance to use.

Overrides:
getStreamUtil in class AbstractMain
Returns:
the StreamUtilImpl.

setStreamUtil

public void setStreamUtil(StreamUtil streamUtil)
This method sets the StreamUtil.

Parameters:
streamUtil - is the StreamUtilImpl instance to use.

synchronize

public void synchronize(ResourceBundle bundle)
                 throws IOException
This method synchronizes (creates or updates) the localized bundles (properties). If a bundle already exists, it will NOT just be overwritten but the missing keys are appended to the end of the file. If no keys are missing, the existing file remains untouched.

Parameters:
bundle - is the bundle instance as java object.
Throws:
IOException - if the operation failed with an input/output error.

synchronize

protected void synchronize(ResourceBundle bundle,
                           String locale,
                           String propertyPath,
                           String date)
                    throws IOException
Like synchronize(ResourceBundle) but for a single Locale.

Parameters:
bundle - is the bundle instance as java object.
locale - is the locale to synchronize as string.
propertyPath - is the path to the property-file excluding locale-suffix.
date - is the current date as string.
Throws:
IOException - if an I/O problem occurred.

run

protected int run(CliModeObject mode)
           throws Exception
This method is called after the options are parsed and injected. It has to be implemented and should do the actual job.

Overrides:
run in class AbstractVersionedMain
Parameters:
mode - is the mode of the invocation.
Returns:
the error-code or AbstractMain.EXIT_CODE_OK on success.
Throws:
Exception - in case of an unexpected error.

main

public static void main(String[] arguments)
This is the main method used to run this class as application.

Parameters:
arguments - are the command-line arguments.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.