1 22 23 package org.cofax; 24 25 import java.util.*; 26 27 35 public class Glossary { 36 37 private HashMap keyValues = new HashMap(); 38 39 42 public Glossary() { 43 return; 44 } 45 46 52 public void setKeyValues(HashMap inHashMap) { 53 keyValues = inHashMap; 54 } 55 56 61 public HashMap getKeyValues() { 62 return keyValues; 63 } 64 65 72 public String getString(String fieldName) { 73 74 Object value = keyValues.get(fieldName); 75 return (value != null) ? value.toString() : ""; 76 } 77 78 86 public void putString(String fieldName, String value) { 87 88 keyValues.put(fieldName, value); 89 90 } 91 92 99 public void addToGlossary(HashMap newKeyValues) { 100 101 for (Iterator i = newKeyValues.keySet().iterator(); i.hasNext();) { 102 String tag = (String ) i.next(); 103 String value = newKeyValues.get(tag).toString(); 104 keyValues.put(tag, value); 105 } 106 107 return; 108 } 109 110 115 public String printGlossary() { 116 117 String printme = ""; 118 119 for (Iterator i = keyValues.keySet().iterator(); i.hasNext();) { 120 String key = i.next().toString(); 121 String value = getString(key); 122 printme = printme + key + " = " + value + "<br>\n"; 123 124 } 125 126 return printme; 127 } 128 129 136 public String printGlossary(String startWithName) { 137 String printme = new String (); 138 139 for (Iterator i = keyValues.keySet().iterator(); i.hasNext();) { 140 String key = i.next().toString(); 141 String value = getString(key); 142 143 if (key.startsWith(startWithName)) { 144 printme = printme + key + " = " + value + "<br>\n"; 145 } 146 } 147 148 return printme; 149 } 150 151 156 public int size() { 157 return keyValues.size(); 158 } 159 160 167 public String applyGlossary(String inString) { 168 if (inString == null) { 169 return ""; 170 } 171 HashMap params = getKeyValues(); 172 if (params == null) { 173 return inString; 174 } 175 176 int firstOc = inString.indexOf("`"); 177 String first; 178 String last; 179 String param; 180 int nextOc = 0; 181 182 while (firstOc > -1) { 183 nextOc = inString.indexOf("`", firstOc + 1); 184 if (nextOc > -1) { 185 first = inString.substring(0, firstOc); 186 last = inString.substring(nextOc + 1, inString.length()); 187 188 param = inString.substring(firstOc + 1, nextOc); 189 190 String myValue = ""; 191 if (params.containsKey(param)) { 192 myValue = params.get(param).toString(); 193 } 194 if (myValue == null) { 195 myValue = ""; 196 } 197 inString = first + myValue + last; 198 199 firstOc = inString.indexOf("`"); 200 } else { 201 firstOc = -1; 202 } 203 } 204 205 return inString; 206 } 207 208 } 209 | Popular Tags |