1 15 package org.apache.tapestry.util.text; 16 17 import java.io.IOException ; 18 import java.io.InputStream ; 19 import java.io.Reader ; 20 import java.io.UnsupportedEncodingException ; 21 import java.util.HashMap ; 22 import java.util.Map ; 23 24 36 public class LocalizedProperties 37 { 38 private Map _propertyMap; 39 40 43 public LocalizedProperties() 44 { 45 this(new HashMap ()); 46 } 47 48 56 public LocalizedProperties(Map propertyMap) 57 { 58 _propertyMap = propertyMap; 59 } 60 61 68 public String getProperty(String key) 69 { 70 Object value = _propertyMap.get(key); 71 if (value instanceof String ) 72 return (String ) value; 73 return null; 74 } 75 76 84 public String getProperty(String key, String defaultValue) 85 { 86 String value = getProperty(key); 87 if (value != null) 88 return value; 89 return defaultValue; 90 } 91 92 98 public void setProperty(String key, String value) 99 { 100 _propertyMap.put(key, value); 101 } 102 103 109 public Map getPropertyMap() 110 { 111 return _propertyMap; 112 } 113 114 122 public void load(InputStream ins) throws IOException 123 { 124 LocalizedPropertiesLoader loader = new LocalizedPropertiesLoader(ins); 125 loader.load(_propertyMap); 126 } 127 128 137 public void load(InputStream ins, String encoding) throws UnsupportedEncodingException , IOException 138 { 139 LocalizedPropertiesLoader loader = new LocalizedPropertiesLoader(ins, encoding); 140 loader.load(_propertyMap); 141 } 142 143 151 public void load(Reader reader) throws IOException 152 { 153 LocalizedPropertiesLoader loader = new LocalizedPropertiesLoader(reader); 154 loader.load(_propertyMap); 155 } 156 } 157 | Popular Tags |