1 12 13 59 package com.openedit.page; 60 61 import java.util.HashMap ; 62 import java.util.Locale ; 63 import java.util.Map ; 64 65 66 71 public class PageProperty 72 { 73 private Map values; 74 private String name; 75 protected String fieldPath; 76 77 84 public PageProperty(String name) 85 { 86 if (name == null) 87 { 88 throw new IllegalArgumentException ("Property name cannot be null"); 89 } 90 91 this.name = name; 92 values = new HashMap (); 93 } 94 95 100 public String getName() 101 { 102 return name; 103 } 104 105 111 public void setValue(String value, Locale locale) 112 { 113 StringBuffer localeString = new StringBuffer (); 114 if (locale != null) 115 { 116 String language = locale.getLanguage(); 117 String country = locale.getCountry(); 118 String variant = locale.getVariant(); 119 120 localeString.append(language ); 121 if ( country != null) 122 { 123 localeString.append("_"); 124 localeString.append(country); 125 } 126 if ( variant != null) 127 { 128 localeString.append("_"); 129 localeString.append(variant); 130 } 131 } 132 setValue(value, localeString.toString() ); 133 } 134 135 142 public void setValue(String value, String locale) 143 { 144 if (locale == null) 145 { 146 locale = ""; 147 } 148 149 values.put(locale, value); 150 } 151 152 157 public String getValue() 158 { 159 return getValue(Locale.getDefault()); 160 } 161 162 178 public String getValue(Locale locale) 179 { 180 if( locale == null) 181 { 182 locale = Locale.getDefault(); 183 } 184 String language = locale.getLanguage(); 185 String country = locale.getCountry(); 186 String variant = locale.getVariant(); 187 return getValue( language, country, variant); 188 } 189 public String getValue(String inLocale) 190 { 191 String lang = ""; 192 String country = ""; 193 String variant = ""; 194 195 int first = inLocale.indexOf('_'); 196 if( first == -1) 197 { 198 lang = inLocale; 199 } 200 else 201 { 202 lang = inLocale.substring(0,first); 203 int second = inLocale.indexOf(first, '_'); 204 if( second == -1 ) 205 { 206 country = inLocale.substring(first + 1); 207 } 208 else 209 { 210 country = inLocale.substring(first, second); 211 variant = inLocale.substring(second + 1); 212 } 213 } 214 return getValue(lang,country, variant); 215 } 216 217 public String getValue(String language, String country, String variant) 218 { 219 if( "default".equals(language) ) 220 { 221 language = ""; 222 } 223 String value = null; 224 225 233 if (variant != null) 235 { 236 value = (String ) values.get(language + "_" + country + "_" + variant); 237 238 if (value != null) 239 { 240 return value; 241 } 242 } 243 244 if (country != null) 245 { 246 value = (String ) values.get(language + "_" + country); 247 248 if (value != null) 249 { 250 return value; 251 } 252 } 253 254 if (language != null) 255 { 256 value = (String ) values.get(language); 257 258 if (value != null) 259 { 260 return value; 261 } 262 } 263 264 return (String ) values.get(""); 265 } 266 267 272 public Map getValues() 273 { 274 return values; 275 } 276 public String toString() 277 { 278 return getValue(); 279 } 280 283 public String getPath() { 284 return fieldPath; 285 } 286 289 public void setPath(String inPath) { 290 fieldPath = inPath; 291 } 292 293 public void setValue(String inString) 294 { 295 setValue(inString,(String )null); 296 297 } 298 } 299 | Popular Tags |