1 23 package org.infoglue.cms.applications.workflowtool.util; 24 25 import java.io.UnsupportedEncodingException ; 26 import java.util.Collection ; 27 import java.util.Date ; 28 import java.util.Iterator ; 29 import java.util.Map ; 30 import java.util.Properties ; 31 32 import org.apache.log4j.Logger; 33 import org.w3c.dom.Document ; 34 35 import com.opensymphony.module.propertyset.PropertyException; 36 import com.opensymphony.module.propertyset.PropertySet; 37 import com.opensymphony.module.propertyset.PropertySetSchema; 38 39 42 public class InfogluePropertySet implements PropertySet { 43 46 private final static Logger logger = Logger.getLogger(InfogluePropertySet.class.getName()); 47 48 51 private static final String UTF8_ENCODING = "utf-8"; 52 53 56 private final PropertySet delegate; 57 58 59 60 63 public InfogluePropertySet(final PropertySet delegate) 64 { 65 this.delegate = delegate; 66 } 67 68 71 public void setDataString(final String key, final String value) throws PropertyException 72 { 73 if(value == null || value.length() == 0) 74 { 75 if(exists(key)) 76 { 77 remove(key); 78 } 79 } 80 else 81 { 82 try 83 { 84 logger.debug("PropertysetHelper.setData(\"" + key + "\",\"" + value + "\")"); 85 setData(key, value.getBytes(UTF8_ENCODING)); 86 } 87 catch(UnsupportedEncodingException e) 88 { 89 throw new PropertyException("Unable to set data for [" + key + "]."); 90 } 91 } 92 93 } 94 95 98 public String getDataString(final String key) throws PropertyException 99 { 100 try 101 { 102 final byte[] b = getData(key); 103 final String value = (b == null) ? null : new String (b, UTF8_ENCODING); 104 logger.debug("PropertysetHelper.getData(\"" + key + "\")=\"" + (value == null ? "NULL" : value) + "\""); 105 return value; 106 } 107 catch(UnsupportedEncodingException e) 108 { 109 throw new PropertyException("Unable to get data for [" + key + "]."); 110 } 111 } 112 113 114 117 public void removeKeys(final String key, final boolean isPrefix) throws PropertyException 118 { 119 if(key == null) 120 { 121 remove(); 122 } 123 else 124 { 125 if(isPrefix) 126 { 127 for(Iterator i = getKeys(key).iterator(); i.hasNext(); ) 128 { 129 remove(i.next().toString()); 130 } 131 } 132 else 133 { 134 if(exists(key)) 135 { 136 remove(key); 137 } 138 } 139 } 140 } 141 142 145 public String getAsString(final String key) 146 { 147 if(!exists(key) || getAsActualType(key) == null) 148 { 149 return null; 150 } 151 152 switch(getType(key)) 153 { 154 case PropertySet.BOOLEAN: 155 return new Boolean (getBoolean(key)).toString(); 156 case PropertySet.DATA: 157 return getDataString(key); 158 case PropertySet.DATE: 159 return getDate(key).toString(); 160 case PropertySet.DOUBLE: 161 return new Double (getDouble(key)).toString(); 162 case PropertySet.INT: 163 return new Integer (getInt(key)).toString(); 164 case PropertySet.LONG: 165 return new Long (getLong(key)).toString(); 166 case PropertySet.STRING: 167 return getString(key); 168 case PropertySet.TEXT: 169 return getText(key); 170 default: 171 logger.warn("Unsupported type [" + getType(key) + "]."); 172 } 173 return null; 174 } 175 176 177 181 184 public boolean exists(String key) throws PropertyException 185 { 186 return delegate.exists(key); 187 } 188 189 192 public Object getAsActualType(String key) throws PropertyException 193 { 194 return delegate.exists(key) ? delegate.getAsActualType(key) : null; 195 } 196 197 200 public boolean getBoolean(String key) throws PropertyException 201 { 202 return delegate.getBoolean(key); 203 } 204 205 208 public byte[] getData(String key) throws PropertyException 209 { 210 return delegate.getData(key); 211 } 212 213 216 public Date getDate(String key) throws PropertyException 217 { 218 return delegate.getDate(key); 219 } 220 221 224 public double getDouble(String key) throws PropertyException 225 { 226 return delegate.getDouble(key); 227 } 228 229 232 public int getInt(String key) throws PropertyException 233 { 234 return delegate.getInt(key); 235 } 236 237 240 public Collection getKeys() throws PropertyException 241 { 242 return delegate.getKeys(); 243 } 244 245 248 public Collection getKeys(int type) throws PropertyException 249 { 250 return delegate.getKeys(type); 251 } 252 253 256 public Collection getKeys(String prefix, int type) throws PropertyException 257 { 258 return delegate.getKeys(prefix, type); 259 } 260 261 264 public Collection getKeys(String prefix) throws PropertyException 265 { 266 return delegate.getKeys(prefix); 267 } 268 269 272 public long getLong(String key) throws PropertyException 273 { 274 return delegate.getLong(key); 275 } 276 277 280 public Object getObject(String key) throws PropertyException 281 { 282 return delegate.getObject(key); 283 } 284 285 288 public Properties getProperties(String key) throws PropertyException 289 { 290 return delegate.getProperties(key); 291 } 292 293 296 public PropertySetSchema getSchema() throws PropertyException 297 { 298 return delegate.getSchema(); 299 } 300 301 304 public String getString(String key) throws PropertyException 305 { 306 return delegate.getString(key); 307 } 308 309 312 public String getText(String key) throws PropertyException 313 { 314 return delegate.getText(key); 315 } 316 317 320 public int getType(String key) throws PropertyException 321 { 322 return delegate.getType(key); 323 } 324 325 328 public Document getXML(String key) throws PropertyException 329 { 330 return delegate.getXML(key); 331 } 332 333 336 public void init(Map config, Map args) 337 { 338 delegate.init(config, args); 339 } 340 341 344 public boolean isSettable(String property) 345 { 346 return delegate.isSettable(property); 347 } 348 349 352 public void remove() throws PropertyException 353 { 354 delegate.remove(); 355 } 356 357 360 public void remove(String key) throws PropertyException 361 { 362 delegate.remove(key); 363 } 364 365 368 public void setAsActualType(String key, Object value) throws PropertyException 369 { 370 delegate.setAsActualType(key, value); 371 } 372 373 376 public void setBoolean(String key, boolean value) throws PropertyException 377 { 378 delegate.setBoolean(key, value); 379 } 380 381 384 public void setData(String key, byte[] value) throws PropertyException 385 { 386 delegate.setData(key, value); 387 } 388 389 392 public void setDate(String key, Date value) throws PropertyException 393 { 394 delegate.setDate(key, value); 395 } 396 397 400 public void setDouble(String key, double value) throws PropertyException 401 { 402 delegate.setDouble(key, value); 403 } 404 405 408 public void setInt(String key, int value) throws PropertyException 409 { 410 delegate.setInt(key, value); 411 } 412 413 416 public void setLong(String key, long value) throws PropertyException 417 { 418 delegate.setLong(key, value); 419 } 420 421 424 public void setObject(String key, Object value) throws PropertyException 425 { 426 delegate.setObject(key, value); 427 } 428 429 432 public void setProperties(String key, Properties value) throws PropertyException 433 { 434 delegate.setProperties(key, value); 435 } 436 437 440 public void setSchema(PropertySetSchema schema) throws PropertyException 441 { 442 delegate.setSchema(schema); 443 } 444 445 448 public void setString(String key, String value) throws PropertyException 449 { 450 delegate.setString(key, value); 451 } 452 453 456 public void setText(String key, String value) throws PropertyException 457 { 458 delegate.setText(key, value); 459 } 460 461 464 public void setXML(String key, Document value) throws PropertyException 465 { 466 delegate.setXML(key, value); 467 } 468 469 472 public boolean supportsType(int type) 473 { 474 return delegate.supportsType(type); 475 } 476 477 480 public boolean supportsTypes() 481 { 482 return delegate.supportsTypes(); 483 } 484 } | Popular Tags |