1 17 package com.sun.org.apache.xml.internal.security.utils; 18 19 20 21 import java.text.MessageFormat ; 22 import java.util.Locale ; 23 import java.util.ResourceBundle ; 24 25 26 33 public class I18n { 34 35 36 public static final String NOT_INITIALIZED_MSG = 37 "You must initialize the xml-security library correctly before you use it. " 38 + "Call the static method \"com.sun.org.apache.xml.internal.security.Init.init();\" to do that " 39 + "before you use any functionality from that library."; 40 41 42 private static String defaultLanguageCode; 44 45 private static String defaultCountryCode; 47 48 private static ResourceBundle resourceBundle = 49 ResourceBundle.getBundle 50 (Constants.exceptionMessagesResourceBundleBase, Locale.US); 51 52 53 private static boolean alreadyInitialized = false; 54 55 56 private static String _languageCode = null; 57 58 59 private static String _countryCode = null; 60 61 65 private I18n() { 66 67 } 69 70 82 public static String translate(String message, Object [] args) { 83 return getExceptionMessage(message, args); 84 } 85 86 95 public static String translate(String message) { 96 return getExceptionMessage(message); 97 } 98 99 106 public static String getExceptionMessage(String msgID) { 107 108 try { 109 String s = resourceBundle.getString(msgID); 110 111 return s; 112 } catch (Throwable t) { 113 if (com.sun.org.apache.xml.internal.security.Init.isInitialized()) { 114 return "No message with ID \"" + msgID 115 + "\" found in resource bundle \"" 116 + Constants.exceptionMessagesResourceBundleBase + "\""; 117 } 118 return I18n.NOT_INITIALIZED_MSG; 119 } 120 } 121 122 129 public static String getExceptionMessage(String msgID, 130 Exception originalException) { 131 132 try { 133 Object exArgs[] = { originalException.getMessage() }; 134 String s = MessageFormat.format(resourceBundle.getString(msgID), 135 exArgs); 136 137 return s; 138 } catch (Throwable t) { 139 if (com.sun.org.apache.xml.internal.security.Init.isInitialized()) { 140 return "No message with ID \"" + msgID 141 + "\" found in resource bundle \"" 142 + Constants.exceptionMessagesResourceBundleBase 143 + "\". Original Exception was a " 144 + originalException.getClass().getName() + " and message " 145 + originalException.getMessage(); 146 } 147 return I18n.NOT_INITIALIZED_MSG; 148 } 149 } 150 151 158 public static String getExceptionMessage(String msgID, Object exArgs[]) { 159 160 try { 161 String s = MessageFormat.format(resourceBundle.getString(msgID), 162 exArgs); 163 164 return s; 165 } catch (Throwable t) { 166 if (com.sun.org.apache.xml.internal.security.Init.isInitialized()) { 167 return "No message with ID \"" + msgID 168 + "\" found in resource bundle \"" 169 + Constants.exceptionMessagesResourceBundleBase + "\""; 170 } 171 return I18n.NOT_INITIALIZED_MSG; 172 } 173 } 174 175 203 } 234 | Popular Tags |