1 16 package cintoo.messages.format; 17 18 import java.text.MessageFormat ; 19 import java.util.MissingResourceException ; 20 import java.util.ResourceBundle ; 21 22 29 public class Formatter { 30 33 public Formatter() { 34 } 35 36 43 public String format(ResourceBundle bundle, String key) { 44 return formatArgs(bundle, key); 45 } 46 47 55 public String format(ResourceBundle bundle, String key, Object ... args) { 56 return formatArgs(bundle, key, args); 57 } 58 59 private String formatArgs(ResourceBundle bundle, String key, Object ... args) { 60 if (null != bundle) { 61 try { 62 return formatArgs(bundle.getString(key), args); 63 } catch (MissingResourceException e) { 64 65 } 66 } 67 return "!" + key + "!"; 68 } 69 70 private String formatArgs(String text, Object ... args) { 71 return MessageFormat.format(text, args); 72 } 73 74 } 75 | Popular Tags |