1 package webman.stager; 2 3 import java.util.*; 4 5 11 public class PropertySet 12 { 13 private Hashtable hashtable; 14 15 18 public PropertySet() 19 { 20 hashtable = new Hashtable(); 21 } 22 23 27 public PropertySet(Hashtable h) 28 { 29 this(); 30 Enumeration keys = h.keys(); 31 String key; 32 while ( keys.hasMoreElements() ) 33 { 34 key = (String )(keys.nextElement()); 35 set(key.toLowerCase(), h.get(key)); 36 } 37 } 38 39 43 public PropertySet(com.teamkonzept.lib.PropertyManager p) 44 { 45 this(); 46 Enumeration keys = p.getKeys(); 47 String key; 48 while ( keys.hasMoreElements() ) 49 { 50 key = (String )(keys.nextElement()); 51 set(key.toLowerCase(), p.getValue(key)); 52 } 53 } 54 55 56 63 public void set(String key, Object value) 64 { 65 if ( value != null ) { 67 hashtable.put(key.toLowerCase().trim(),value); 68 } 69 } 70 71 75 public String get(String key) 76 { 77 String result = (String )(hashtable.get(key.toLowerCase().trim())); 78 if (result != null) 79 { 80 return result.trim(); 81 } 82 else 83 { 84 return null; 85 } 86 } 87 88 95 public Vector getPropertyGroup(String keyStub) 96 { 97 Vector selectedKeys = new Vector(); 99 Enumeration allKeys = hashtable.keys(); 100 String key; 101 keyStub = keyStub.toLowerCase(); 102 while ( allKeys.hasMoreElements() ) 103 { 104 key = (String )(allKeys.nextElement()); 105 if ( key.startsWith(keyStub) ) 106 { 107 selectedKeys.add(key); 108 } 109 } 110 Object [] array = selectedKeys.toArray(); 112 Arrays.sort(array); 113 Vector result = new Vector(); 115 for ( int i=0; i<array.length; i++ ) 116 { 117 result.add(get((String )array[i])); 118 } 119 return result; 120 } 121 122 127 public Hashtable getReceiverProperties() 128 { 129 Hashtable result = new Hashtable(); 130 Enumeration keys = hashtable.keys(); 131 String key; 132 while ( keys.hasMoreElements() ) 133 { 134 key = (String )(keys.nextElement()); 135 if (key.toLowerCase().startsWith("receiver")) 136 { 137 result.put(key,hashtable.get(key)); 138 } 139 } 140 return result; 141 } 142 143 String debugDump() 145 { 146 final String NEW_LINE = System.getProperty("line.separator"); 147 Enumeration keys = hashtable.keys(); 148 String key, result=""; 149 while ( keys.hasMoreElements() ) 150 { 151 key = (String )keys.nextElement(); 152 result += "DEBUG: key=" + key + " value=" + get(key) + NEW_LINE; 153 } 154 return result; 155 } 156 } 157 | Popular Tags |