[cal10n-dev] branch, master, updated. v0.7-7-gff91eb1
added by portage for gitosis-gentoo
git-noreply at pixie.qos.ch
Wed Oct 28 18:26:49 CET 2009
The branch, master has been updated
via ff91eb1c05510d41e19243a039a85f4864af0648 (commit)
from c835e6c2babc39cd5c935b00a84d7d4bc796cce0 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=cal10n.git;a=commit;h=ff91eb1c05510d41e19243a039a85f4864af0648
http://github.com/ceki/cal10n/commit/ff91eb1c05510d41e19243a039a85f4864af0648
commit ff91eb1c05510d41e19243a039a85f4864af0648
Author: Ceki Gulcu <ceki at qos.ch>
Date: Wed Oct 28 18:25:09 2009 +0100
- The bundle <code>lookup</code>() method in MessageConveyor now uses
the class loader of the enum tpye instead of the class loader which
loaded the MessageConveyor class. The fixes CAL-8.
diff --git a/cal10n-api/src/main/java/ch/qos/cal10n/MessageConveyor.java b/cal10n-api/src/main/java/ch/qos/cal10n/MessageConveyor.java
index 11395c9..ff9033e 100644
--- a/cal10n-api/src/main/java/ch/qos/cal10n/MessageConveyor.java
+++ b/cal10n-api/src/main/java/ch/qos/cal10n/MessageConveyor.java
@@ -42,86 +42,90 @@ import ch.qos.cal10n.util.CAL10NResourceBundleFinder;
*/
public class MessageConveyor implements IMessageConveyor {
- final Locale locale;
-
- final Map<String, CAL10NResourceBundle> cache = new ConcurrentHashMap<String, CAL10NResourceBundle>();
-
- /**
- * The {@link Locale} associated with this instance.
- *
- * @param locale
- */
- public MessageConveyor(Locale locale) {
- this.locale = locale;
- }
-
- /**
- * Given an enum as key, find the corresponding resource bundle and return the
- * corresponding internationalized.
- *
- * <p>
- * The name of the resource bundle is defined via the {@link BaseName}
- * annotation whereas the locale is specified in this MessageConveyor
- * instance's constructor.
- *
- * @param key
- * an enum instance used as message key
- *
- */
- public <E extends Enum<?>> String getMessage(E key, Object... args)
- throws MessageConveyorException {
-
- String declararingClassName = key.getDeclaringClass().getName();
- CAL10NResourceBundle rb = cache.get(declararingClassName);
- if (rb == null || rb.hasChanged()) {
- rb = lookup(key);
- cache.put(declararingClassName, rb);
- }
-
- String keyAsStr = key.toString();
- String value = rb.getString(keyAsStr);
- if (value == null) {
- return "No key found for " + keyAsStr;
- } else {
- if (args == null || args.length == 0) {
- return value;
- } else {
- return MessageFormat.format(value, args);
- }
- }
- }
-
- private <E extends Enum<?>> CAL10NResourceBundle lookup(E key)
- throws MessageConveyorException {
- Class<?> declaringClass = key.getDeclaringClass();
-
- String baseName = AnnotationExtractor.getBaseName(key.getDeclaringClass());
- if (baseName == null) {
- throw new MessageConveyorException(
- "Missing @BaseName annotation in enum type ["
- + key.getClass().getName() + "]. See also "
- + Cal10nConstants.MISSING_BN_ANNOTATION_URL);
- }
-
- String charset = AnnotationExtractor.getCharset(declaringClass, locale);
- CAL10NResourceBundle rb = CAL10NResourceBundleFinder.getBundle(this
- .getClass().getClassLoader(), baseName, locale, charset);
-
- if (rb == null) {
- throw new MessageConveyorException("Failed to locate resource bundle ["
- + baseName + "] for locale [" + locale + "] for enum type ["
- + key.getDeclaringClass().getName() + "]");
- }
- return rb;
- }
-
- public String getMessage(MessageParameterObj mpo)
- throws MessageConveyorException {
- if (mpo == null) {
- throw new IllegalArgumentException(
- "MessageParameterObj argumument cannot be null");
- }
- return getMessage(mpo.getKey(), mpo.getArgs());
- }
-
+ final Locale locale;
+
+ final Map<String, CAL10NResourceBundle> cache = new ConcurrentHashMap<String, CAL10NResourceBundle>();
+
+ /**
+ * The {@link Locale} associated with this instance.
+ *
+ * @param locale
+ */
+ public MessageConveyor(Locale locale) {
+ this.locale = locale;
+ }
+
+ /**
+ * Given an enum as key, find the corresponding resource bundle and return
+ * the corresponding internationalized.
+ *
+ * <p>
+ * The name of the resource bundle is defined via the {@link BaseName}
+ * annotation whereas the locale is specified in this MessageConveyor
+ * instance's constructor.
+ *
+ * @param key
+ * an enum instance used as message key
+ *
+ */
+ public <E extends Enum<?>> String getMessage(E key, Object... args)
+ throws MessageConveyorException {
+
+ String declararingClassName = key.getDeclaringClass().getName();
+ CAL10NResourceBundle rb = cache.get(declararingClassName);
+ if (rb == null || rb.hasChanged()) {
+ rb = lookup(key);
+ cache.put(declararingClassName, rb);
+ }
+
+ String keyAsStr = key.toString();
+ String value = rb.getString(keyAsStr);
+ if (value == null) {
+ return "No key found for " + keyAsStr;
+ } else {
+ if (args == null || args.length == 0) {
+ return value;
+ } else {
+ return MessageFormat.format(value, args);
+ }
+ }
+ }
+
+ private <E extends Enum<?>> CAL10NResourceBundle lookup(E key)
+ throws MessageConveyorException {
+ Class<?> declaringClass = key.getDeclaringClass();
+
+ String baseName = AnnotationExtractor.getBaseName(key
+ .getDeclaringClass());
+ if (baseName == null) {
+ throw new MessageConveyorException(
+ "Missing @BaseName annotation in enum type ["
+ + key.getClass().getName() + "]. See also "
+ + Cal10nConstants.MISSING_BN_ANNOTATION_URL);
+ }
+
+ String charset = AnnotationExtractor.getCharset(declaringClass, locale);
+ // use the declaring class' loader instead of
+ // this.getClass().getClassLoader()
+ // see also http://jira.qos.ch/browse/CAL-8
+ CAL10NResourceBundle rb = CAL10NResourceBundleFinder.getBundle(
+ declaringClass.getClassLoader(), baseName, locale, charset);
+
+ if (rb == null) {
+ throw new MessageConveyorException(
+ "Failed to locate resource bundle [" + baseName
+ + "] for locale [" + locale + "] for enum type ["
+ + key.getDeclaringClass().getName() + "]");
+ }
+ return rb;
+ }
+
+ public String getMessage(MessageParameterObj mpo)
+ throws MessageConveyorException {
+ if (mpo == null) {
+ throw new IllegalArgumentException(
+ "MessageParameterObj argumument cannot be null");
+ }
+ return getMessage(mpo.getKey(), mpo.getArgs());
+ }
}
diff --git a/cal10n-site/src/site/pages/news.html b/cal10n-site/src/site/pages/news.html
index 4dbfedb..53397c1 100644
--- a/cal10n-site/src/site/pages/news.html
+++ b/cal10n-site/src/site/pages/news.html
@@ -34,6 +34,14 @@
Muir in <a href="http://jira.qos.ch/browse/CAL-9">CAL-9</a>.
</p>
+ <p>The bundle <code>lookup</code>() method in
+ <code>MessageConveyor</code> now uses the class loader of the enum
+ tpye instead of the class loader which loaded the
+ <code>MessageConveyor</code> class. The fixes <a
+ href="http://jira.qos.ch/browse/CAL-8">CAL-8</a> as reported by
+ Pete Muir.
+ </p>
+
<hr width="80%" align="center" />
<h3>4th of September 2009 - Release of CAL10N version 0.7</h3>
-----------------------------------------------------------------------
Summary of changes:
.../main/java/ch/qos/cal10n/MessageConveyor.java | 168 ++++++++++----------
cal10n-site/src/site/pages/news.html | 8 +
2 files changed, 94 insertions(+), 82 deletions(-)
hooks/post-receive
--
Compiler assisted localization library
More information about the cal10n-dev
mailing list