[Schmitzm-commits] r2212 - trunk/schmitzm-core/src/main/java/de/schmitzm/lang
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Thu Jan 31 18:12:04 CET 2013
Author: mojays
Date: 2013-01-31 18:12:03 +0100 (Thu, 31 Jan 2013)
New Revision: 2212
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
Log:
LangUtil: method to set default locale from command line parameters
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java 2013-01-31 14:21:30 UTC (rev 2211)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java 2013-01-31 17:12:03 UTC (rev 2212)
@@ -2741,4 +2741,47 @@
return sb.toString();
}
+
+
+ /**
+ * Checks the command line parameters for one of the following keys and
+ * sets the default {@link Locale}. Possible parameter keys: {@code -l},
+ * {@code -L}, {@code /l}, {@code /L}
+ * @param args command line arguments
+ * @return array index the language parameter was found in; -1 if none of the possible
+ * parameter keys was found
+ */
+ public static int setDefaultLocaleFromCommandLineArguments(String[] args) {
+ return setDefaultLocaleFromCommandLineArguments(args, false, "-l", "/l");
+ }
+
+ /**
+ * Checks the command line parameters for a language parameter and
+ * sets the default {@link Locale}.
+ * @param args command line arguments
+ * @param caseSensitive indicates whether the parameter must be specified exactly or
+ * case-insensitive
+ * @param paramKeys possible parameter keys for language code (e.g. "-l", "/l", "-language", ...)
+ * followed by a valid ISO-639 code
+ * @return array index the language parameter was found in; -1 if none of the possible
+ * parameter keys was found
+ */
+ public static int setDefaultLocaleFromCommandLineArguments(String[] args, boolean caseSensitive, String... paramKeys) {
+ for (int i=0; i<args.length; i++) {
+ // Angabe der Sprache
+ // -l <language>
+ for (String paramKey : paramKeys) {
+ if ( caseSensitive && args[i].equals(paramKey) ||
+ !caseSensitive && args[i].equalsIgnoreCase(paramKey) ) {
+ try {
+ Locale.setDefault( new Locale(args[i+1]) );
+ return i;
+ } catch (Exception err) {
+ System.err.println("Invalid Argument: After "+args[i]+" a valid ISO-639 code is expected");
+ }
+ }
+ }
+ }
+ return -1;
+ }
}
More information about the Schmitzm-commits
mailing list