View Javadoc
1 /*** 2 * $Revision: 1.2 $ 3 */ 4 package com.sun.xml.registry.ebxml.util; 5 6 import java.text.*; 7 import java.util.*; 8 import javax.xml.registry.*; 9 10 /*** 11 * Internationalization utilities 12 * 13 * This class expects to obtain messages from a ResourceBundle in a 14 * subpackage of this package called "resources" with a baseName of 15 * "Messages". Typically, this is done using Java property files loaded 16 * via PropertyResourceBundle. 17 * 18 * @author Edwin Goei 19 */ 20 public class I18nUtil 21 { 22 private static final I18nUtil INSTANCE = new I18nUtil(); 23 24 private ResourceBundle bundle; 25 26 private I18nUtil() { 27 // May want to add a setLocale() method in the future?? 28 Locale locale = Locale.getDefault(); 29 30 String baseName = getClass().getPackage().getName() 31 + ".resources.Messages"; 32 bundle = ResourceBundle.getBundle(baseName, locale); 33 } 34 35 public static I18nUtil getInstance() { 36 return INSTANCE; 37 } 38 39 public String getMessage(String key) { 40 String message = null; 41 try { 42 message = bundle.getString(key); 43 } catch (MissingResourceException x) { 44 x.printStackTrace(); 45 message = "[MissingResourceException] key=" + key; 46 } 47 return message; 48 } 49 50 public String getMessage(String key, Object[] params) { 51 if (params == null) { 52 return getMessage(key); 53 } 54 return MessageFormat.format(getMessage(key), params); 55 } 56 57 public JAXRException newJAXRException(String key) { 58 return new JAXRException(getMessage(key)); 59 } 60 61 public JAXRException newJAXRException(String key, Object[] params) { 62 return new JAXRException(getMessage(key, params)); 63 } 64 }

This page was automatically generated by Maven