1 48 49 package org.jpublish.util; 50 51 import java.util.HashMap ; 52 import java.util.Locale ; 53 import java.util.Map ; 54 55 60 61 public class Property { 62 63 private String name = null; 64 private Map values = new HashMap (); 65 66 71 72 public Property(String name) { 73 if (name == null) { 74 throw new IllegalArgumentException ("Property name cannot be null"); 75 } 76 this.name = name; 77 } 78 79 84 85 public String getName() { 86 return name; 87 } 88 89 94 95 public String getValue() { 96 return getValue(Locale.getDefault()); 97 } 98 99 111 112 public String getValue(Locale locale) { 113 String language = locale.getLanguage(); 114 String country = locale.getCountry(); 115 String variant = locale.getVariant(); 116 117 String value = null; 118 119 value = (String ) values.get(locale.toString()); 120 if (value != null) { 121 return value; 122 } 123 124 if (variant != null) { 125 value = (String ) values.get(language + "_" + country + "_" + variant); 126 if (value != null) { 127 return value; 128 } 129 } 130 131 if (country != null) { 132 value = (String ) values.get(language + "_" + country); 133 if (value != null) { 134 return value; 135 } 136 } 137 138 if (language != null) { 139 value = (String ) values.get(language); 140 if (value != null) { 141 return value; 142 } 143 } 144 145 return (String ) values.get(""); 146 } 147 148 154 155 public void setValue(String value, Locale locale) { 156 String localeString = null; 157 if (locale != null) { 158 localeString = locale.toString(); 159 } 160 setValue(value, localeString); 161 } 162 163 170 171 public void setValue(String value, String locale) { 172 if (locale == null) { 173 locale = ""; 174 } 175 values.put(locale, value); 176 } 177 178 183 184 public Map getValues() { 185 return values; 186 } 187 188 } 189 | Popular Tags |