You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2017/12/03 17:15:23 UTC
[2/2] juneau git commit: Minor API changes.
Minor API changes.
Project: http://git-wip-us.apache.org/repos/asf/juneau/repo
Commit: http://git-wip-us.apache.org/repos/asf/juneau/commit/9b8b457f
Tree: http://git-wip-us.apache.org/repos/asf/juneau/tree/9b8b457f
Diff: http://git-wip-us.apache.org/repos/asf/juneau/diff/9b8b457f
Branch: refs/heads/master
Commit: 9b8b457fd1e504330836a56043670b5f90e48e40
Parents: 9c7f3a4
Author: JamesBognar <ja...@apache.org>
Authored: Sun Dec 3 12:15:18 2017 -0500
Committer: JamesBognar <ja...@apache.org>
Committed: Sun Dec 3 12:15:18 2017 -0500
----------------------------------------------------------------------
.../org/apache/juneau/utils/MessageBundle.java | 57 ++++++++++++++++++++
1 file changed, 57 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/juneau/blob/9b8b457f/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/MessageBundle.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/MessageBundle.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/MessageBundle.java
index 84bb9cb..304f8a8 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/MessageBundle.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/MessageBundle.java
@@ -84,6 +84,63 @@ public class MessageBundle extends ResourceBundle {
/**
* Constructor.
+ *
+ * <p>
+ * When this method is used, the bundle path is determined by searching for the resource bundle
+ * in the following locations:
+ * <ul>
+ * <li><code>[package].ForClass.properties</code>
+ * <li><code>[package].nls.ForClass.properties</code>
+ * <li><code>[package].i18n.ForClass.properties</code>
+ * </ul>
+ *
+ * @param forClass The class
+ * @return A new message bundle belonging to the class.
+ */
+ public static final MessageBundle create(Class<?> forClass) {
+ return create(forClass, findBundlePath(forClass));
+ }
+
+ /**
+ * Constructor.
+ *
+ * <p>
+ * A shortcut for calling <code>new MessageBundle(forClass, bundlePath)</code>.
+ *
+ *
+ * @param forClass The class
+ * @param bundlePath The location of the resource bundle.
+ * @return A new message bundle belonging to the class.
+ */
+ public static final MessageBundle create(Class<?> forClass, String bundlePath) {
+ return new MessageBundle(forClass, bundlePath);
+ }
+
+ private static final String findBundlePath(Class<?> forClass) {
+ String path = forClass.getName();
+ if (tryBundlePath(forClass, path))
+ return path;
+ path = forClass.getPackage().getName() + ".nls." + forClass.getSimpleName();
+ if (tryBundlePath(forClass, path))
+ return path;
+ path = forClass.getPackage().getName() + ".i18n." + forClass.getSimpleName();
+ if (tryBundlePath(forClass, path))
+ return path;
+ return null;
+ }
+
+ private static final boolean tryBundlePath(Class<?> c, String path) {
+ try {
+ path = c.getName();
+ ResourceBundle.getBundle(path, Locale.getDefault(), c.getClassLoader());
+ return true;
+ } catch (MissingResourceException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Constructor.
*
* @param forClass The class using this resource bundle.
* @param bundlePath