1 16 17 package org.apache.jetspeed.util; 18 19 20 import java.util.Hashtable ; 21 import java.util.Locale ; 22 import java.util.Enumeration ; 23 import java.util.Map ; 24 import org.apache.jetspeed.services.resources.JetspeedResources; 25 import java.io.Serializable ; 26 27 33 public class MetaData implements Serializable 34 { 35 36 public static final String DEFAULT_TITLE = 37 JetspeedResources.getString(JetspeedResources.DEFAULT_TITLE_KEY); 38 39 public static final String DEFAULT_DESCRIPTION = 40 JetspeedResources.getString(JetspeedResources.DEFAULT_DESCRIPTION_KEY); 41 42 public static final String DEFAULT_IMAGE = 43 JetspeedResources.getString(JetspeedResources.DEFAULT_IMAGE_KEY); 44 45 48 private Hashtable data = new Hashtable (); 49 50 53 public void setTitle(String title) 54 { 55 setTitle(title, null); 56 } 57 58 61 public void setTitle(String title, Locale locale) 62 { 63 setProperty("title", locale, title); 64 } 65 66 69 public String getTitle() 70 { 71 return getTitle(null); 72 } 73 74 78 public String getTitle(Locale locale) 79 { 80 String title = (String ) getProperty("title", locale); 81 82 if ((title == null) && (locale != null)) 83 { 84 title = (String ) getProperty("title", null); 85 } 86 87 if (title == null) 88 { 89 title = DEFAULT_TITLE; 90 } 91 92 return title; 93 } 94 95 98 public void setImage(String image) 99 { 100 setImage(image, null); 101 } 102 103 106 public void setImage(String image, Locale locale) 107 { 108 setProperty("image", locale, image); 109 } 110 111 114 public String getImage() 115 { 116 return getImage(null); 117 } 118 119 123 public String getImage(Locale locale) 124 { 125 String image = (String ) getProperty("image", locale); 126 127 if ((image == null) && (locale != null)) 128 { 129 image = (String ) getProperty("image", null); 130 } 131 132 if (image == null) 133 { 134 image = DEFAULT_IMAGE; 135 } 136 137 return image; 138 } 139 140 143 public void setDescription(String description) 144 { 145 setDescription(description, null); 146 } 147 148 151 public void setDescription(String description, Locale locale) 152 { 153 setProperty("description", locale, description); 154 } 155 156 159 public String getDescription() 160 { 161 return getDescription(null); 162 } 163 164 168 public String getDescription(Locale locale) 169 { 170 String desc = (String ) getProperty("description", locale); 171 172 if ((desc == null) && (locale != null)) 173 { 174 desc = (String ) getProperty ("description", null); 175 } 176 177 if (desc == null) 178 { 179 desc = DEFAULT_DESCRIPTION; 180 } 181 182 return desc; 183 } 184 185 194 private void setProperty(String name, Locale locale, Object value) 195 { 196 if (name == null) 197 { 198 return; 199 } 200 201 if (locale != null) 202 { 203 name = name + "." + locale.toString(); 204 } 205 206 if (value == null) 207 { 208 data.remove(name); 209 } 210 else 211 { 212 data.put(name, value); 213 } 214 } 215 216 219 private Object getProperty(String name, Locale locale) 220 { 221 if (name == null) 222 { 223 return null; 224 } 225 226 String extname = null; 227 if (locale != null) 228 { 229 extname = name + "." + locale.toString(); 230 } 231 232 Object obj = null; 233 234 if (extname != null) 235 { 236 obj = data.get(extname); 237 } 238 if (obj == null) 239 { 240 obj = data.get(name); 241 } 242 243 return obj; 244 } 245 246 249 private Map getProperties() 250 { 251 return data; 252 } 253 254 259 public void merge(MetaData meta) 260 { 261 Map map = meta.getProperties(); 262 Hashtable params = (Hashtable ) map; 263 Enumeration en = params.keys(); 264 265 while (en.hasMoreElements()) 266 { 267 Object key = en.nextElement(); 268 String value = (String ) params.get(key); 269 270 if (value != null) 271 { 272 this.data.put(key, value); 273 } 274 } 275 } 276 } 277 | Popular Tags |