|
|||||||||||||||||||
| This license of Clover is provided to support the development of JBind only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover. | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| MessageFormats.java | 70% | 95,2% | 100% | 88,2% |
|
||||||||||||||
| 1 |
/* |
|
| 2 |
* JBind |
|
| 3 |
* |
|
| 4 |
* Copyright (c) by Stefan Wachter. All rights reserved. |
|
| 5 |
* |
|
| 6 |
* Usage, modification, and redistribution is subject to license terms that are |
|
| 7 |
* available at 'http://www.jbind.org'. The JBind license is like the |
|
| 8 |
* 'Apache Software License V 1.1'. |
|
| 9 |
*/ |
|
| 10 |
package org.jbind.message; |
|
| 11 |
|
|
| 12 |
import java.text.MessageFormat; |
|
| 13 |
import java.util.Collections; |
|
| 14 |
import java.util.Enumeration; |
|
| 15 |
import java.util.HashMap; |
|
| 16 |
import java.util.Locale; |
|
| 17 |
import java.util.Map; |
|
| 18 |
import java.util.ResourceBundle; |
|
| 19 |
|
|
| 20 |
public class MessageFormats implements IMessageFormats {
|
|
| 21 |
|
|
| 22 |
private String myBaseName = null; |
|
| 23 |
private Map myFormatMaps = Collections.synchronizedMap(new HashMap()); |
|
| 24 |
|
|
| 25 | 3 |
public MessageFormats(String aBaseName) {
|
| 26 | 3 |
myBaseName = aBaseName; |
| 27 |
} |
|
| 28 |
|
|
| 29 | 3 |
private Map getFormatMap(Locale aLocale) {
|
| 30 | 3 |
ResourceBundle b = null; |
| 31 | 3 |
if (null != aLocale) {
|
| 32 | 0 |
b = ResourceBundle.getBundle(myBaseName, aLocale); |
| 33 |
} |
|
| 34 | 3 |
if (null == b) {
|
| 35 | 3 |
b = ResourceBundle.getBundle(myBaseName); |
| 36 |
} |
|
| 37 | 3 |
Map m = new HashMap(); |
| 38 | 3 |
for (Enumeration e = b.getKeys(); e.hasMoreElements(); ) {
|
| 39 | 813 |
String k = (String)e.nextElement(); |
| 40 | 813 |
String s = b.getString(k); |
| 41 | 813 |
MessageFormat f = new MessageFormat(s); |
| 42 | 813 |
m.put(k, f); |
| 43 |
} |
|
| 44 | 3 |
return m; |
| 45 |
} |
|
| 46 |
|
|
| 47 | 948 |
public MessageFormat getMessageFormat(Locale aLocale, String aKey) {
|
| 48 | 948 |
Object localeKey = aLocale; |
| 49 | 948 |
if (null == localeKey) {
|
| 50 | 948 |
localeKey = ""; |
| 51 |
} |
|
| 52 | 948 |
Map m = (Map)myFormatMaps.get(localeKey); |
| 53 | 948 |
if (null == m) {
|
| 54 | 3 |
m = getFormatMap(aLocale); |
| 55 | 3 |
myFormatMaps.put(localeKey, m); |
| 56 |
} |
|
| 57 | 948 |
return (MessageFormat)m.get(aKey); |
| 58 |
} |
|
| 59 |
|
|
| 60 |
} |
|
| 61 |
|
|
||||||||||