From 87cd5e8be869b19e6b37dbb13056882efff976a0 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Wed, 14 May 2014 11:35:43 +0200 Subject: Added Verification Messages --- .../egiz/pdfas/common/messages/CodesResolver.java | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/CodesResolver.java (limited to 'pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages') diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/CodesResolver.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/CodesResolver.java new file mode 100644 index 00000000..f98e8d07 --- /dev/null +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/CodesResolver.java @@ -0,0 +1,44 @@ +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 CodesResolver { + private static final String messageResource = "resources.messages.verify"; + private static final String missingMsg = "Unknown "; + + private static final Logger logger = LoggerFactory.getLogger(MessageResolver.class); + + private static ResourceBundle bundle; + + static { + bundle = ResourceBundle.getBundle(messageResource); + if(bundle == null) { + logger.error("Failed to load resource bundle!!"); + System.err.println("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; + } + +} -- cgit v1.2.3