X-Git-Url: http://git.nikiroo.be/?p=jvcard.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Fresources%2FBundles.java;h=945e7f13fec0a73eea71d5080a6f7929bfa5b9c9;hp=76c471f6efddda0ed97a6dddae6e99363a646ca0;hb=7f82bf682ab5747b2d4ccdccae9ea3fcdb013cee;hpb=b9f192ed5290f3263f60dc5a2dc9fd754eead958 diff --git a/src/be/nikiroo/jvcard/resources/Bundles.java b/src/be/nikiroo/jvcard/resources/Bundles.java index 76c471f..945e7f1 100644 --- a/src/be/nikiroo/jvcard/resources/Bundles.java +++ b/src/be/nikiroo/jvcard/resources/Bundles.java @@ -10,6 +10,8 @@ import java.util.ResourceBundle; * */ public class Bundles { + static private String confDir = getConfDir(); + /** * Return the non-localised bundle of the given name. * @@ -20,7 +22,7 @@ public class Bundles { */ static public ResourceBundle getBundle(String name) { return ResourceBundle.getBundle(Bundles.class.getPackage().getName() - + "." + name, new FixedResourceBundleControl()); + + "." + name, new FixedResourceBundleControl(confDir)); } /** @@ -34,8 +36,47 @@ public class Bundles { * @return the localised bundle */ static public ResourceBundle getBundle(String name, Locale locale) { - return ResourceBundle.getBundle(Bundles.class.getPackage().getName() - + "." + name, locale, new FixedResourceBundleControl()); + + "." + name, locale, new FixedResourceBundleControl(confDir)); } + + /** + * Set the primary configuration directory to look for .properties + * files in. + * + * All {@link ResourceBundle}s returned by this class after that point will + * respect this new directory. + * + * @param confDir + * the new directory + */ + static public void setDirectory(String confDir) { + Bundles.confDir = confDir; + } + + /** + * Return the configuration directory where to try to find the + * .properties files in priority. + * + * @return the configuration directory + */ + static private String getConfDir() { + // Do not override user-supplied config directory (see --help) + if (Bundles.confDir != null) + return Bundles.confDir; + + try { + ResourceBundle bundle = ResourceBundle.getBundle(Bundles.class + .getPackage().getName() + "." + "jvcard", + Locale.getDefault(), new FixedResourceBundleControl(null)); + + String configDir = bundle.getString("CONFIG_DIR"); + if (configDir != null && configDir.trim().length() > 0) + return configDir; + } catch (Exception e) { + } + + return null; + } + }