|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.mmm.util.component.base.AbstractLoggableObject
net.sf.mmm.util.cli.api.AbstractMain
net.sf.mmm.util.cli.api.AbstractVersionedMain
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 fromfor 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_ public class ResourceBundleSynchronizer.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.")
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.
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 |
---|
public static final String OPTION_DATE_PATTERN
set the
date-pattern
.
public static final String OPTION_ENCODING
set the encoding
.
public static final String OPTION_PATH
set the path
.
public static final String OPTION_BUNDLE_CLASS
public static final String OPTION_LOCALE
private static final String DEFAULT_BASE_PATH
getPath()
,
Constant Field Valuesprivate static final String DEFAULT_ENCODING
getEncoding()
,
Constant Field Valuesprivate static final String DEFAULT_DATE_PATTERN
getEncoding()
,
Constant Field Values@CliOption(name="--path", aliases="-p", operand="DIR", usage="Write property-files to the base-path {operand} (Default is \"{default}\").") private String path
getPath()
@CliOption(name="--encoding", aliases="-e", operand="ENC", usage="Read and write property-files using the specified encoding {operand} (Default is {default}).") private String encoding
getEncoding()
private String newline
getNewline()
@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
getDatePattern()
@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
getLocales()
@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
getBundleClass()
private StreamUtil streamUtil
getStreamUtil()
Constructor Detail |
---|
public ResourceBundleSynchronizer()
Method Detail |
---|
public String getDatePattern()
SimpleDateFormat
public void setDatePattern(String datePattern)
datePattern
- the datePattern to setpublic String[] getLocales()
synchronized
. Examples for locales
(entries of the returned array) are ""
,
public void setLocales(String[] locales)
locales
.
locales
- are the locales to setpublic void setLocales(Locale... locales)
locales
.
locales
- are the locales to setpublic String getPath()
DEFAULT_BASE_PATH
.
public void setPath(String basePath)
base-path
.
basePath
- the basePath to setpublic String getEncoding()
UTF-8
.
public void setEncoding(String encoding)
encoding
.
encoding
- the encoding to setpublic String getNewline()
\n
).
public void setNewline(String newline)
newline
- the newline to setpublic Class<? extends ResourceBundle> getBundleClass()
Class
reflecting the ResourceBundle
to
synchronize.
public void setBundleClass(Class<? extends ResourceBundle> bundleClass)
bundle-class
.
bundleClass
- is the bundle-class to setpublic StreamUtil getStreamUtil()
StreamUtilImpl
instance to use.
getStreamUtil
in class AbstractMain
StreamUtilImpl
.public void setStreamUtil(StreamUtil streamUtil)
StreamUtil
.
streamUtil
- is the StreamUtilImpl
instance to use.public void synchronize(ResourceBundle bundle) throws IOException
bundle
- is the bundle instance as java object.
IOException
- if the operation failed with an input/output error.protected void synchronize(ResourceBundle bundle, String locale, String propertyPath, String date) throws IOException
synchronize(ResourceBundle)
but for a single Locale
.
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.
IOException
- if an I/O problem occurred.protected int run(CliModeObject mode) throws Exception
run
in class AbstractVersionedMain
mode
- is the mode
of the invocation.
AbstractMain.EXIT_CODE_OK
on success.
Exception
- in case of an unexpected error.public static void main(String[] arguments)
arguments
- are the command-line arguments.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |