1 23 24 29 30 package com.sun.enterprise.cli.framework; 31 32 import java.util.ResourceBundle ; 34 import java.util.Locale ; 35 import java.util.Vector ; 36 import java.util.Properties ; 37 import java.util.Iterator ; 38 import java.util.MissingResourceException ; 39 import java.text.MessageFormat ; 40 41 45 public class LocalStringsManager { 46 47 private String packageName; 48 private String propertyFile; 49 private Vector resourceBundles = new Vector (); 50 public static String DEFAULT_STRING_VALUE = "Key not found"; 51 52 53 public LocalStringsManager(String packageName, String propertyFile) 54 { 55 this.packageName = packageName; 56 this.propertyFile = propertyFile; 57 ResourceBundle resourceBundle = 58 ResourceBundle.getBundle(packageName + "." + propertyFile); 59 resourceBundles.add(resourceBundle); 60 } 61 62 65 public LocalStringsManager(Vector localizePropertiesList) 66 { 67 for (int i = 0; i < localizePropertiesList.size(); i++) 68 { 69 Properties properties = (Properties ) localizePropertiesList.get(i); 70 String packageNameStr = (String ) properties.get("base-package"); 71 String propertyFileStr = (String ) properties.get("property-file-name"); 72 ResourceBundle resourceBundle = 73 ResourceBundle.getBundle(packageNameStr + "." + propertyFileStr); 74 resourceBundles.add(resourceBundle); 75 } 76 } 77 78 79 82 public LocalStringsManager(Vector localizeStringList, Locale locale) 83 { 84 for (int i = 0; i < localizeStringList.size(); i++) 85 { 86 ResourceBundle resourceBundle = 87 ResourceBundle.getBundle((String )localizeStringList.get(i), 88 locale); 89 resourceBundles.add(resourceBundle); 90 } 91 } 92 93 94 97 public String getPropertiesFile() 98 { 99 return propertyFile; 100 } 101 102 105 public String getPackageName() 106 { 107 return packageName; 108 } 109 110 111 114 public Vector getResourceBundles() 115 { 116 return resourceBundles; 117 } 118 119 120 123 public String getString(String key) 124 { 125 Iterator resourcesIter = resourceBundles.iterator(); 126 String value = DEFAULT_STRING_VALUE + " (" + key + ")"; 127 while (resourcesIter.hasNext()) 128 { 129 ResourceBundle resourceBundle = (ResourceBundle )resourcesIter.next(); 130 try 131 { 132 value = resourceBundle.getString(key); 133 break; 134 } 135 catch (MissingResourceException mre) 136 { 137 } 139 } 140 return value; 141 } 142 143 146 public String getString(String key, Object [] toInsert) 147 throws CommandValidationException 148 { 149 String fmtStr = null; 150 try 151 { 152 MessageFormat msgFormat = 153 new MessageFormat (getString(key)); 154 fmtStr = msgFormat.format(toInsert); 155 } 156 catch(Exception e) 157 { 158 throw new CommandValidationException(e); 159 } 160 return fmtStr; 161 } 162 } 163 | Popular Tags |