1 18 package org.apache.batik.util.gui.resource; 19 20 import java.util.ArrayList ; 21 import java.util.List ; 22 import java.util.MissingResourceException ; 23 import java.util.ResourceBundle ; 24 import java.util.StringTokenizer ; 25 26 33 public class ResourceManager { 34 37 protected ResourceBundle bundle; 38 39 43 public ResourceManager(ResourceBundle rb) { 44 bundle = rb; 45 } 46 47 52 public String getString(String key) 53 throws MissingResourceException { 54 return bundle.getString(key); 55 } 56 57 63 public List getStringList(String key) 64 throws MissingResourceException { 65 return getStringList(key, " \t\n\r\f", false); 66 } 67 74 public List getStringList(String key, String delim) 75 throws MissingResourceException { 76 return getStringList(key, delim, false); 77 } 78 79 87 public List getStringList(String key, String delim, boolean returnDelims) 88 throws MissingResourceException { 89 List result = new ArrayList (); 90 StringTokenizer st = new StringTokenizer (getString(key), 91 delim, 92 returnDelims); 93 while (st.hasMoreTokens()) { 94 result.add(st.nextToken()); 95 } 96 return result; 97 } 98 99 105 public boolean getBoolean(String key) 106 throws MissingResourceException , ResourceFormatException { 107 String b = getString(key); 108 109 if (b.equals("true")) { 110 return true; 111 } else if (b.equals("false")) { 112 return false; 113 } else { 114 throw new ResourceFormatException("Malformed boolean", 115 bundle.getClass().getName(), 116 key); 117 } 118 } 119 120 126 public int getInteger(String key) 127 throws MissingResourceException , ResourceFormatException { 128 String i = getString(key); 129 130 try { 131 return Integer.parseInt(i); 132 } catch (NumberFormatException e) { 133 throw new ResourceFormatException("Malformed integer", 134 bundle.getClass().getName(), 135 key); 136 } 137 } 138 139 public int getCharacter(String key) 140 throws MissingResourceException , ResourceFormatException { 141 String s = getString(key); 142 143 if(s == null || s.length() == 0){ 144 throw new ResourceFormatException("Malformed character", 145 bundle.getClass().getName(), 146 key); 147 } 148 149 return s.charAt(0); 150 } 151 152 } 153 | Popular Tags |