1 29 package com.genimen.djeneric.language; 30 31 import java.util.Locale ; 32 import java.util.MissingResourceException ; 33 import java.util.ResourceBundle ; 34 35 import com.genimen.djeneric.util.DjStringReplacer; 36 37 public class Messages 38 { 39 40 public static final String DJENERIC_LANGUAGE = "djeneric.language"; 41 private static final String BUNDLE_NAME = "com.genimen.djeneric.language.messages"; 42 43 private static ResourceBundle RESOURCE_BUNDLE; 44 45 static 46 { 47 reloadResources(); 48 } 49 50 public static void reloadResources() 51 { 52 String language = System.getProperty(DJENERIC_LANGUAGE); 53 54 if (language == null) language = "en"; 58 RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, new Locale (language, "", "")); 59 } 60 61 private Messages() 62 { 63 } 65 66 public static String getString(String key, Object p1, Object p2, Object p3, Object p4) 67 { 68 if (p1 == null) p1 = "null"; 69 if (p2 == null) p2 = "null"; 70 if (p3 == null) p3 = "null"; 71 if (p4 == null) p4 = "null"; 72 73 return getString(key, p1, p2, p3, p4, null); 74 } 75 76 public static String getString(String key, Object p1, Object p2, Object p3) 77 { 78 if (p1 == null) p1 = "null"; 79 if (p2 == null) p2 = "null"; 80 if (p3 == null) p3 = "null"; 81 82 return getString(key, p1, p2, p3, null, null); 83 } 84 85 public static String getString(String key, Object p1, Object p2) 86 { 87 if (p1 == null) p1 = "null"; 88 if (p2 == null) p2 = "null"; 89 90 return getString(key, p1, p2, null, null, null); 91 } 92 93 public static String getString(String key, Object p1) 94 { 95 if (p1 == null) p1 = "null"; 96 97 return getString(key, p1, null, null, null, null); 98 } 99 100 public static String getString(String key, Object p1, Object p2, Object p3, Object p4, Object p5) 101 { 102 DjStringReplacer sr = new DjStringReplacer(getString(key)); 103 104 if (p1 != null) 105 { 106 sr.replace("{1}", p1.toString()); 107 } 108 109 if (p2 != null) 110 { 111 sr.replace("{2}", p2.toString()); 112 } 113 114 if (p3 != null) 115 { 116 sr.replace("{3}", p3.toString()); 117 } 118 119 if (p4 != null) 120 { 121 sr.replace("{4}", p4.toString()); 122 } 123 124 if (p5 != null) 125 { 126 sr.replace("{5}", p5.toString()); 127 } 128 129 return sr.toString(); 130 } 131 132 public static String getString(String key) 133 { 134 try 135 { 136 return RESOURCE_BUNDLE.getString(key); 137 } 138 catch (MissingResourceException e) 139 { 140 return '!' + key + '!'; 141 } 142 } 143 } | Popular Tags |