@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 <bundle-class> 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_<locale>.properties will be created or updated in the base-path. In each property-file all properties defined in <bundle-class> 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
AbstractResourceBundle
. | Modifier and Type | Class and Description |
|---|---|
class |
ResourceBundleSynchronizer.NlsBundleContainer
This inner class is a container for
ResourceBundle or NlsBundle. |
| Modifier and Type | Field and Description |
|---|---|
private List<Class<?>> |
bundleClasses |
private NlsBundleHelper |
bundleHelper |
private String |
datePattern |
protected 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 ReflectionUtil |
reflectionUtil |
private NlsResourceBundleLocator |
resourceBundleLocator |
EXIT_CODE_CONSTRAINT_VIOLATION, EXIT_CODE_ILLEGAL_SYNTAX, EXIT_CODE_OK, EXIT_CODE_UNEXPECTED| Constructor and Description |
|---|
ResourceBundleSynchronizer()
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
List<Class<?>> |
getBundleClasses()
This method gets the
Class reflecting the ResourceBundle to synchronize. |
NlsBundleHelper |
getBundleHelper() |
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.
|
ReflectionUtil |
getReflectionUtil()
This method gets the
ReflectionUtil. |
NlsResourceBundleLocator |
getResourceBundleLocator()
This method gets the
NlsResourceBundleLocator. |
private boolean |
isProductive(Class<?> bundleClass)
Determines if the given
bundleClass is productive. |
static void |
main(String[] arguments)
This is the main method used to run this class as application.
|
protected int |
runDefaultMode()
This method is called from
AbstractVersionedMain.run(CliModeObject) if the program is executed in default mode. |
void |
setBundleClasses(List<Class<?>> bundleClasses)
This method sets the
bundle-classes. |
void |
setBundleHelper(NlsBundleHelper bundleHelper) |
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 |
setReflectionUtil(ReflectionUtil reflectionUtil) |
void |
setResourceBundleLocator(NlsResourceBundleLocator resourceBundleFinder) |
void |
synchronize(ResourceBundleSynchronizer.NlsBundleContainer bundle)
This method synchronizes (creates or updates) the localized bundles (properties).
|
protected void |
synchronize(ResourceBundleSynchronizer.NlsBundleContainer bundle,
String locale,
String propertyPath,
String date)
Like
synchronize(NlsBundleContainer) but for a single Locale. |
getVersion, rungetIocContainer, getOutputSettings, getParserBuilder, getStandardError, getStandardOutput, getStreamUtil, handleError, printHelp, run, runAndExit, setStandardError, setStandardOutput, validategetLoggerpublic 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
protected static final String DEFAULT_BASE_PATH
getPath(),
Constant Field Valuesprivate static final String DEFAULT_ENCODING
private static final String DEFAULT_DATE_PATTERN
@CliOption(name="--path", aliases="-p", operand="DIR", usage="Write property-files to the base-path {operand} (Default is \"{default}\").") private String path
@CliOption(name="--encoding", aliases="-e", operand="ENC", usage="Read and write property-files using the specified encoding {operand} (Default is {default}).") private String encoding
private String newline
@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
@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
@CliOption(name="--bundle", aliases="-b", operand="CLASS", usage="The explicit list of bundle-classes for which the property-files should be created or updated. 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. If this option is omitted the bundle-classes are resolved from all instances of META-INF/net.sf.mmm/nls-bundles on your classpath.") private List<Class<?>> bundleClasses
private NlsResourceBundleLocator resourceBundleLocator
private ReflectionUtil reflectionUtil
private NlsBundleHelper bundleHelper
public String getDatePattern()
SimpleDateFormatpublic void setDatePattern(String datePattern)
datePattern - the datePattern to setpublic String[] getLocales()
synchronized.
Examples for locales (entries of the returned array) are "", "en", or "en_GB".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 List<Class<?>> getBundleClasses()
Class reflecting the ResourceBundle to synchronize.public void setBundleClasses(List<Class<?>> bundleClasses)
bundle-classes.bundleClasses - is the List of bundle-classes to setpublic NlsResourceBundleLocator getResourceBundleLocator()
NlsResourceBundleLocator.NlsResourceBundleLocator.public void setResourceBundleLocator(NlsResourceBundleLocator resourceBundleFinder)
resourceBundleFinder - is the resourceBundleFinder to setpublic ReflectionUtil getReflectionUtil()
ReflectionUtil.ReflectionUtil.public void setReflectionUtil(ReflectionUtil reflectionUtil)
reflectionUtil - is the ReflectionUtil.public NlsBundleHelper getBundleHelper()
NlsBundleHelper.public void setBundleHelper(NlsBundleHelper bundleHelper)
bundleHelper - is the NlsBundleHelper.public void synchronize(ResourceBundleSynchronizer.NlsBundleContainer bundle) throws IOException
bundle - is the bundle instance as java object.IOException - if the operation failed with an input/output error.protected void synchronize(ResourceBundleSynchronizer.NlsBundleContainer bundle, String locale, String propertyPath, String date) throws IOException
synchronize(NlsBundleContainer) 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 runDefaultMode()
throws Exception
AbstractVersionedMainAbstractVersionedMain.run(CliModeObject) if the program is executed in default mode.runDefaultMode in class AbstractVersionedMainAbstractMain.EXIT_CODE_OK on success.Exception - in case of an unexpected error.private boolean isProductive(Class<?> bundleClass)
bundleClass is productive.bundleClass - is the Class to test.true if productive, false otherwise.public static void main(String[] arguments)
arguments - are the command-line arguments.Copyright © 2001–2016 mmm-Team. All rights reserved.