diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2013-09-26 15:48:43 +0200 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2013-09-26 15:48:43 +0200 |
commit | fc44d4bcad00192f0df8f6086737b9b126094dcd (patch) | |
tree | a03a3018b6faba73309bf381337ea359ada10d01 /pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages | |
parent | 1eb95549f597e6dcb0d028768bbdcfb94d0a91ef (diff) | |
download | pdf-as-4-fc44d4bcad00192f0df8f6086737b9b126094dcd.tar.gz pdf-as-4-fc44d4bcad00192f0df8f6086737b9b126094dcd.tar.bz2 pdf-as-4-fc44d4bcad00192f0df8f6086737b9b126094dcd.zip |
initial code commit
Diffstat (limited to 'pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages')
-rw-r--r-- | pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/MessageResolver.java | 42 | ||||
-rw-r--r-- | pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/package-info.java | 8 |
2 files changed, 50 insertions, 0 deletions
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/MessageResolver.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/MessageResolver.java new file mode 100644 index 00000000..0bc1bab7 --- /dev/null +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/MessageResolver.java @@ -0,0 +1,42 @@ +package at.gv.egiz.pdfas.common.messages; + +import java.util.Locale; +import java.util.ResourceBundle; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MessageResolver { + private static final String messageResource = "resources.messages.common"; + private static final String missingMsg = "Please add message "; + + private static final Logger logger = LoggerFactory.getLogger(MessageResolver.class); + + private static ResourceBundle bundle; + + static { + ResourceBundle bundle = ResourceBundle.getBundle(messageResource); + if(bundle == null) { + logger.error("Failed to load resource bundle!!"); + Runtime.getRuntime().exit(-1); + } + } + + public static void forceLocale(Locale locale) { + bundle = ResourceBundle.getBundle(messageResource, locale); + } + + public static String resolveMessage(String msgId) { + if(bundle == null) { + return missingMsg + msgId; + } + if(bundle.containsKey(msgId)) { + String value = bundle.getString(msgId); + if(value == null) { + return missingMsg + msgId; + } + return value; + } + return missingMsg + msgId; + } +} diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/package-info.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/package-info.java new file mode 100644 index 00000000..0ac78c22 --- /dev/null +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.common.messages;
\ No newline at end of file |