1 17 package org.apache.geronimo.common.propertyeditor; 18 19 import java.io.ByteArrayInputStream ; 20 import java.io.ByteArrayOutputStream ; 21 import java.io.IOException ; 22 import java.util.Properties ; 23 24 30 public class PropertiesEditor extends TextPropertyEditorSupport { 31 38 public Object getValue() { 39 Object currentValue = super.getValue(); 40 if (currentValue instanceof Properties ) { 41 return (Properties ) currentValue; 42 } else { 43 ByteArrayInputStream stream = new ByteArrayInputStream (currentValue.toString().getBytes()); 46 Properties bundle = new Properties (); 48 try { 49 bundle.load(stream); 50 } catch (IOException e) { 51 throw new PropertyEditorException(e); 53 } 54 return bundle; 55 } 56 } 57 58 67 public String getAsText() { 68 Object value = getValue(); 69 if (value instanceof Properties ) { 70 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 71 try { 72 ((Properties ) value).store(baos, null); 73 } catch (IOException e) { 74 throw new PropertyEditorException(e); 76 } 77 return baos.toString(); 78 } 79 return ("" + value); 80 } 81 82 } 83 | Popular Tags |