1 package dinamica; 2 3 import electric.xml.*; 4 import java.sql.Types ; 5 6 16 public class Config 17 { 18 19 20 Document _doc = null; 21 Element _root = null; 22 Element _trans = null; 23 Element _output = null; 24 25 26 public String summary = null; 27 28 29 public String mvcLog = null; 30 public String jdbcLog = null; 31 32 33 public String transClassName = null; 34 35 36 public String transDataSource = null; 37 38 39 public String transValidator = null; 40 41 42 public String transTransactions = null; 43 44 45 Recordset _rs = new Recordset(); 46 47 48 public String outClassName = null; 49 50 51 public String outTemplate = null; 52 53 54 public String contentType = null; 55 56 57 public String expiration = null; 58 59 60 public String headers = null; 61 62 63 public String requestEncoding = null; 64 65 66 public String templateEncoding = null; 67 68 69 Recordset _print = new Recordset(); 70 71 72 public String path = null; 73 74 75 81 public Config(String xmlData, String path) throws Throwable 82 { 83 84 85 this.path = path; 86 87 88 _doc = new Document(xmlData); 89 _root = _doc.getRoot(); 90 _trans = _root.getElement("transaction"); 91 _output = _root.getElement("output"); 92 93 Element encoding = _root.getElement("request-encoding"); 94 if (encoding!=null) 95 requestEncoding = encoding.getTextString(); 96 97 98 summary = _root.getElement("summary").getString(); 99 100 101 mvcLog = _root.getElement("log").getString(); 102 103 104 _rs.append("id", Types.VARCHAR); 105 _rs.append("source", Types.VARCHAR); 106 _rs.append("scope", Types.VARCHAR); 107 _rs.append("onempty", Types.VARCHAR); 108 _rs.append("maxrows", Types.VARCHAR); 109 _rs.append("datasource", Types.VARCHAR); 110 _rs.append("params", Types.VARCHAR); 111 112 113 _print.append("mode", Types.VARCHAR); 114 _print.append("recordset", Types.VARCHAR); 115 _print.append("tag", Types.VARCHAR); 116 _print.append("control", Types.VARCHAR); 117 _print.append("pagesize", Types.VARCHAR); 118 _print.append("alternate-colors", Types.VARCHAR); 119 _print.append("null-value", Types.VARCHAR); 120 121 122 if (_trans!=null) 123 { 124 Element e = _trans.getElement("datasource"); 125 if (e!=null) 126 transDataSource = e.getString(); 127 128 transClassName = _trans.getElement("classname").getString(); 129 transValidator = _trans.getElement("validator").getString(); 130 transTransactions = _trans.getElement("transaction").getString(); 131 jdbcLog = _trans.getElement("jdbc-log").getString(); 132 133 134 Elements rsElems = _trans.getElements("recordset"); 135 while (rsElems.hasMoreElements()) 136 { 137 _rs.addNew(); 138 Element rs = rsElems.next(); 139 String id = rs.getAttribute("id"); 140 String mode = rs.getAttribute("source"); 141 String scope = rs.getAttribute("scope"); 142 String onempty = rs.getAttribute("on-empty-return"); 143 String maxrows = rs.getAttribute("max-rows"); 144 String rsDataSrc = rs.getAttribute("datasource"); 145 if (rsDataSrc!=null && rsDataSrc.trim().equals("")) 146 rsDataSrc = null; 147 String rsParams = rs.getAttribute("params"); 148 if (rsParams!=null && rsParams.trim().equals("")) 149 rsParams = null; 150 151 _rs.setValue("id", id); 152 _rs.setValue("source", mode); 153 _rs.setValue("scope", scope); 154 _rs.setValue("onempty", onempty); 155 _rs.setValue("maxrows", maxrows); 156 _rs.setValue("datasource", rsDataSrc); 157 _rs.setValue("params", rsParams); 158 } 159 if ( _rs.getRecordCount()>0) 160 _rs.top(); 161 } 162 163 164 if (_output!=null) 165 { 166 Element x = null; 167 outClassName = _output.getElement("classname").getString(); 168 169 x = _output.getElement("template"); 171 if (x!=null) { 172 templateEncoding = x.getAttribute("file-encoding"); 173 if (templateEncoding!=null && templateEncoding.trim().equals("")) 174 templateEncoding=null; 175 outTemplate = x.getString(); 176 } 177 178 x = _output.getElement("content-type"); 179 if (x!=null) { 180 contentType = x.getString(); 181 if (contentType.indexOf("charset")<0 && templateEncoding!=null) 183 contentType = contentType + "; charset=" + templateEncoding; 184 } 185 186 187 x = _output.getElement("expiration"); 188 if (x!=null) 189 expiration = x.getString(); 190 x = _output.getElement("set-http-headers"); 191 if (x!=null) 192 headers = x.getString(); 193 else 194 headers = "false"; 195 196 197 Elements rsElems = _output.getElements("print"); 198 while (rsElems.hasMoreElements()) 199 { 200 _print.addNew(); 201 Element rs = rsElems.next(); 202 String mode = rs.getAttribute("mode"); 203 String rset = rs.getAttribute("recordset"); 204 String tag = rs.getAttribute("tag"); 205 String control = rs.getAttribute("control"); 206 String pagesize = rs.getAttribute("pagesize"); 207 String altColors = rs.getAttribute("alternate-colors"); 208 String nullValue = rs.getAttribute("null-value"); 209 210 _print.setValue("mode", mode); 211 _print.setValue("recordset", rset); 212 _print.setValue("tag", tag); 213 _print.setValue("control", control); 214 _print.setValue("pagesize", pagesize); 215 _print.setValue("alternate-colors", altColors); 216 _print.setValue("null-value", nullValue); 217 } 218 if ( _print.getRecordCount()>0) 219 _print.top(); 220 221 } 222 223 } 224 225 229 public Recordset getRecordsets() 230 { 231 return _rs; 232 } 233 234 238 public Recordset getPrintCommands() 239 { 240 return _print; 241 } 242 243 247 public Document getDocument() 248 { 249 return _doc; 250 } 251 252 259 public String getConfigValue(String tagName) throws Throwable 260 { 261 Element e = _root.getElement(new XPath(tagName)); 262 if (e!=null) 263 return e.getString(); 264 else 265 throw new Throwable ("Configuration element not found: " + tagName); 266 267 } 268 269 277 public String getConfigValue(String tagName, String value) throws Throwable 278 { 279 Element e = _root.getElement(new XPath(tagName)); 280 if (e!=null) 281 return e.getString(); 282 else 283 return value; 284 285 } 286 287 293 public String getUriForExitCode(int exitCode) throws Throwable 294 { 295 String uri = null; 296 297 Element onexit = _root.getElement( new XPath("//on-exit[@return-code='" + exitCode + "']") ); 298 if (onexit!=null) 299 uri = onexit.getAttributeValue("forward-to"); 300 return uri; 301 } 302 303 } 304 | Popular Tags |