1 64 65 package com.jcorporate.expresso.core.dbobj; 66 67 import com.jcorporate.expresso.core.i18n.Messages; 68 import com.jcorporate.expresso.core.misc.StringUtil; 69 import org.apache.log4j.Logger; 70 71 import java.util.Locale ; 72 73 88 public class ISOValidValue extends ValidValue { 89 private static Logger log = Logger.getLogger(ISOValidValue.class); 90 91 92 96 public ISOValidValue() { 97 super(); 98 } 99 100 107 public ISOValidValue(String newValue, String newDescrip) { 108 super(newValue, newDescrip); 109 } 110 111 123 public ISOValidValue(String schemaClass, String prefix, 124 String value, String description) { 125 this(schemaClass, Locale.getDefault(), prefix, value, description); 126 } 127 128 141 public ISOValidValue(String schemaClass, Locale locale, String prefix, 142 String value, String description) { 143 setValue(value); 144 setDescription(description); 145 canonize(schemaClass, locale, prefix); 146 } 147 148 161 public ISOValidValue(RequestContext request, String schemaClass, String prefix, 162 String value, String description) { 163 setValue(value); 164 setDescription(description); 165 canonize(request, schemaClass, prefix); 166 } 167 168 174 public String getValue() { 175 return value; 176 } 177 178 184 public void setValue(String value) { 185 this.value = StringUtil.notNull(value); 186 } 187 188 194 public String getKey() { 195 return getValue(); 196 } 197 198 203 public String getDescription() { 204 return description; 205 } 206 207 213 public void setDescription(String description) { 214 this.description = StringUtil.notNull(description); 215 } 216 217 233 public String canonize(String schemaClass, String prefix) { 234 return canonize(schemaClass, Locale.getDefault(), prefix); 235 } 236 237 254 public String canonize(String schemaClass, Locale locale, String prefix) { 255 257 String key = (prefix != null ? prefix + "." + description : description); 258 String result = null; 259 try { 260 result = Messages.getString(schemaClass, locale, key, new Object [0]); 261 if (result != null) { 263 description = result; 264 } 265 } catch (IllegalArgumentException iae) { 266 log.warn("No such key:`" + key + "' found in schema bundle at `" + schemaClass + "'"); 270 result = null; 271 } 272 273 return result; 274 } 275 276 295 public String canonize(RequestContext request, String schemaClass, String prefix) { 296 298 String key = (prefix != null ? prefix + "." + description : description); 299 String result = null; 300 try { 301 result = Messages.getString(schemaClass, request.getLocale(), key, new Object [0]); 302 if (result != null) { 304 description = result; 305 } 306 } catch (IllegalArgumentException iae) { 307 log.warn("No such key:`" + key + "' found in schema bundle at `" + schemaClass + "'"); 311 result = null; 312 } 313 return result; 314 } 315 316 321 public String toString() { 322 StringBuffer buf = new StringBuffer (); 323 buf.append("ISOValidValue@" + Integer.toHexString(this.hashCode()) + "{"); 324 buf.append("value:`" + value + "' (`" + description + "')"); 325 buf.append("}"); 326 return buf.toString(); 327 } 328 329 } 330 331 332 | Popular Tags |