1 24 package org.ofbiz.webapp.control; 25 26 import java.io.File ; 27 import java.net.MalformedURLException ; 28 import java.net.URL ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 import java.util.Map ; 32 import java.util.Set ; 33 34 import javolution.util.FastList; 35 import javolution.util.FastMap; 36 37 import org.ofbiz.base.util.Debug; 38 import org.ofbiz.base.util.UtilValidate; 39 import org.ofbiz.base.util.UtilXml; 40 import org.ofbiz.base.util.cache.UtilCache; 41 import org.w3c.dom.Document ; 42 import org.w3c.dom.Element ; 43 44 52 public class ConfigXMLReader { 53 54 public static final String module = ConfigXMLReader.class.getName(); 55 56 public static ControllerConfig getControllerConfig(URL url) { 57 ControllerConfig controllerConfig = (ControllerConfig) controllerCache.get(url); 58 if (controllerConfig == null) { synchronized (ConfigXMLReader.class) { 60 controllerConfig = (ControllerConfig) controllerCache.get(url); 62 if (controllerConfig == null) { 63 controllerConfig = new ControllerConfig(url); 64 controllerCache.put(url, controllerConfig); 65 } 66 } 67 } 68 return controllerConfig; 69 } 70 71 public static UtilCache controllerCache = new UtilCache("webapp.ControllerConfig"); 72 73 public static class ControllerConfig { 74 public URL url; 75 76 public Map configMap = FastMap.newInstance(); 77 public Map handlerMap = FastMap.newInstance(); 78 public Map requestMap = FastMap.newInstance(); 79 public Map viewMap = FastMap.newInstance(); 80 81 public ControllerConfig(URL url) { 82 this.url = url; 83 84 Element rootElement = loadDocument(url); 85 if (rootElement != null) { 86 this.configMap = loadConfigMap(rootElement, url); 87 this.handlerMap = loadHandlerMap(rootElement, url); 88 this.requestMap = loadRequestMap(rootElement, url); 89 this.viewMap = loadViewMap(rootElement, url); 90 } 91 } 92 } 93 94 95 public static final String DEFAULT_ERROR_PAGE = "errorpage"; 96 public static final String SITE_OWNER = "owner"; 97 public static final String SECURITY_CLASS = "security-class"; 98 public static final String FIRSTVISIT = "firstvisit"; 99 public static final String PREPROCESSOR = "preprocessor"; 100 public static final String POSTPROCESSOR = "postprocessor"; 101 102 103 public static final String INCLUDE = "include"; 104 public static final String INCLUDE_FILE = "file"; 105 public static final String INCLUDE_URL = "url"; 106 107 public static final String REQUEST_MAPPING = "request-map"; 108 public static final String REQUEST_URI = "uri"; 109 public static final String REQUEST_EDIT = "edit"; 110 111 public static final String REQUEST_DESCRIPTION = "description"; 112 public static final String ERROR_PAGE = "error"; 113 public static final String NEXT_PAGE = "success"; 114 115 public static final String SECURITY = "security"; 116 public static final String SECURITY_HTTPS = "https"; 117 public static final String SECURITY_AUTH = "auth"; 118 public static final String SECURITY_EXTVIEW = "external-view"; 119 public static final String SECURITY_DIRECT = "direct-request"; 120 121 public static final String EVENT = "event"; 122 public static final String EVENT_PATH = "path"; 123 public static final String EVENT_TYPE = "type"; 124 public static final String EVENT_METHOD = "invoke"; 125 public static final String EVENT_GLOBAL_TRANSACTION = "global-transaction"; 126 127 public static final String RESPONSE = "response"; 128 public static final String RESPONSE_NAME = "name"; 129 public static final String RESPONSE_TYPE = "type"; 130 public static final String RESPONSE_VALUE = "value"; 131 132 133 public static final String VIEW_MAPPING = "view-map"; 134 public static final String VIEW_NAME = "name"; 135 public static final String VIEW_PAGE = "page"; 136 public static final String VIEW_TYPE = "type"; 137 public static final String VIEW_INFO = "info"; 138 public static final String VIEW_CONTENT_TYPE = "content-type"; 139 public static final String VIEW_ENCODING = "encoding"; 140 public static final String VIEW_DESCRIPTION = "description"; 141 142 143 public static final String HANDLER = "handler"; 144 public static final String HANDLER_NAME = "name"; 145 public static final String HANDLER_TYPE = "type"; 146 public static final String HANDLER_CLASS = "class"; 147 148 149 public static Element loadDocument(URL location) { 150 Document document = null; 151 try { 152 document = UtilXml.readXmlDocument(location, true); 153 Element rootElement = document.getDocumentElement(); 154 if (Debug.verboseOn()) Debug.logVerbose("Loaded XML Config - " + location, module); 156 return rootElement; 157 } catch (Exception e) { 158 Debug.logError(e, module); 159 } 160 return null; 161 } 162 163 164 public static Map getRequestMap(URL xml) { 165 ControllerConfig controllerConfig = getControllerConfig(xml); 166 return controllerConfig != null ? controllerConfig.requestMap : null; 167 } 168 169 170 public static Map loadRequestMap(Element root, URL xml) { 171 long startTime = System.currentTimeMillis(); 172 FastMap map = FastMap.newInstance(); 173 if (root == null) { 174 root = loadDocument(xml); 175 } 176 177 if (root == null) return map; 178 179 List includeElementList = UtilXml.childElementList(root, INCLUDE); 180 Iterator includeElementIter = includeElementList.iterator(); 181 while (includeElementIter.hasNext()) { 182 Element includeElement = (Element ) includeElementIter.next(); 183 String includeFile = includeElement.getAttribute(INCLUDE_FILE); 184 185 if ((includeFile != null) && (includeFile.length() > 0)) { 186 File oldFile = new File (xml.getFile()); 187 File newFile = new java.io.File ("" + oldFile.getParent() + java.io.File.separator + includeFile); 188 189 try { 190 Map subMap = loadRequestMap(null, newFile.toURL()); 191 192 map.putAll(subMap); 193 } catch (MalformedURLException mue) { 194 mue.printStackTrace(); 195 } 196 } 197 198 String includeURL = includeElement.getAttribute(INCLUDE_URL); 199 if ((includeURL != null) && (includeURL.length() > 0)) { 200 try { 201 Map subMap = loadRequestMap(null, new URL (includeURL)); 202 map.putAll(subMap); 203 } catch (MalformedURLException mue) { 204 mue.printStackTrace(); 205 } 206 } 207 } 208 209 List requestMapElementList = UtilXml.childElementList(root, REQUEST_MAPPING); 210 Iterator requestMapElementIter = requestMapElementList.iterator(); 211 while (requestMapElementIter.hasNext()) { 212 Element requestMapElement = (Element ) requestMapElementIter.next(); 213 214 FastMap uriMap = FastMap.newInstance(); 216 217 String uri = requestMapElement.getAttribute(REQUEST_URI); 219 String edit = requestMapElement.getAttribute(REQUEST_EDIT); 220 221 if (edit == null || edit.equals("")) 222 edit = "true"; 223 if (uri != null) { 224 uriMap.put(REQUEST_URI, uri); 225 uriMap.put(REQUEST_EDIT, edit); 226 } 227 228 Element securityElement = UtilXml.firstChildElement(requestMapElement, SECURITY); 230 if (securityElement != null) { 231 String securityHttps = securityElement.getAttribute(SECURITY_HTTPS); 232 String securityAuth = securityElement.getAttribute(SECURITY_AUTH); 233 String securityExtView = securityElement.getAttribute(SECURITY_EXTVIEW); 234 String securityDirectRequest = securityElement.getAttribute(SECURITY_DIRECT); 235 uriMap.put(SECURITY_HTTPS, securityHttps); 236 uriMap.put(SECURITY_AUTH, securityAuth); 237 uriMap.put(SECURITY_EXTVIEW, securityExtView); 238 uriMap.put(SECURITY_DIRECT, securityDirectRequest); 239 } 240 241 Element eventElement = UtilXml.firstChildElement(requestMapElement, EVENT); 243 if (eventElement != null) { 244 String type = eventElement.getAttribute(EVENT_TYPE); 245 String path = eventElement.getAttribute(EVENT_PATH); 246 String invoke = eventElement.getAttribute(EVENT_METHOD); 247 248 uriMap.put(EVENT_TYPE, type); 249 uriMap.put(EVENT_PATH, path); 250 uriMap.put(EVENT_METHOD, invoke); 251 252 uriMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); 254 } 255 256 String description = UtilXml.childElementValue(requestMapElement, REQUEST_DESCRIPTION); 258 uriMap.put(REQUEST_DESCRIPTION, UtilValidate.isNotEmpty(description) ? description : ""); 259 260 List responseElementList = UtilXml.childElementList(requestMapElement, RESPONSE); 262 Iterator responseElementIter = responseElementList.iterator(); 263 while (responseElementIter.hasNext()) { 264 Element responseElement = (Element ) responseElementIter.next(); 265 String name = responseElement.getAttribute(RESPONSE_NAME); 266 String type = responseElement.getAttribute(RESPONSE_TYPE); 267 String value = responseElement.getAttribute(RESPONSE_VALUE); 268 uriMap.put(name, type + ":" + value); 269 } 270 271 if (uri != null) { 272 map.put(uri, uriMap); 273 } 274 } 275 276 277 if (Debug.verboseOn()) { 278 Debug.logVerbose("-------- Request Mappings --------", module); 279 FastMap debugMap = map; 280 Set debugSet = debugMap.keySet(); 281 Iterator i = debugSet.iterator(); 282 283 while (i.hasNext()) { 284 Object o = i.next(); 285 String request = (String ) o; 286 FastMap thisURI = (FastMap) debugMap.get(o); 287 288 289 StringBuffer verboseMessageBuffer = verboseMessageBuffer = new StringBuffer (); 290 291 Iterator debugIter = ((Set ) thisURI.keySet()).iterator(); 292 while (debugIter.hasNext()) { 293 Object lo = debugIter.next(); 294 String name = (String ) lo; 295 String value = (String ) thisURI.get(lo); 296 297 verboseMessageBuffer.append("[" + name + "=>" + value + "]"); 298 } 299 Debug.logVerbose(request + " :: " + verboseMessageBuffer.toString(), module); 300 } 301 Debug.logVerbose("------ End Request Mappings ------", module); 302 } 303 304 305 double totalSeconds = (System.currentTimeMillis() - startTime)/1000.0; 306 if (Debug.infoOn()) Debug.logInfo("RequestMap Created: (" + map.size() + ") records in " + totalSeconds + "s", module); 307 return map; 308 } 309 310 311 public static Map getViewMap(URL xml) { 312 ControllerConfig controllerConfig = getControllerConfig(xml); 313 return controllerConfig != null ? controllerConfig.viewMap : null; 314 } 315 316 317 public static Map loadViewMap(Element root, URL xml) { 318 long startTime = System.currentTimeMillis(); 319 FastMap map = FastMap.newInstance(); 320 if (root == null) { 321 root = loadDocument(xml); 322 } 323 324 if (root == null) { 325 return map; 326 } 327 328 List includeElementList = UtilXml.childElementList(root, INCLUDE); 329 Iterator includeElementIter = includeElementList.iterator(); 330 while (includeElementIter.hasNext()) { 331 Element includeElement = (Element ) includeElementIter.next(); 332 String includeFile = includeElement.getAttribute(INCLUDE_FILE); 333 334 if ((includeFile != null) && (includeFile.length() > 0)) { 335 File oldFile = new File (xml.getFile()); 336 File newFile = new java.io.File ("" + oldFile.getParent() + java.io.File.separator + includeFile); 337 338 try { 339 Map subMap = loadRequestMap(null, newFile.toURL()); 340 341 map.putAll(subMap); 342 } catch (MalformedURLException mue) { 343 mue.printStackTrace(); 344 } 345 } 346 347 String includeURL = includeElement.getAttribute(INCLUDE_URL); 348 if ((includeURL != null) && (includeURL.length() > 0)) { 349 try { 350 Map subMap = loadRequestMap(null, new URL (includeURL)); 351 map.putAll(subMap); 352 } catch (MalformedURLException mue) { 353 mue.printStackTrace(); 354 } 355 } 356 } 357 358 List viewMapElementList = UtilXml.childElementList(root, VIEW_MAPPING); 359 Iterator viewMapElementIter = viewMapElementList.iterator(); 360 while (viewMapElementIter.hasNext()) { 361 Element viewMapElement = (Element ) viewMapElementIter.next(); 362 FastMap uriMap = FastMap.newInstance(); 364 365 String name = viewMapElement.getAttribute(VIEW_NAME); 367 String page = viewMapElement.getAttribute(VIEW_PAGE); 368 if (page == null || page.length() == 0) { 369 page = name; 370 } 371 372 uriMap.put(VIEW_NAME, name); 373 uriMap.put(VIEW_PAGE, page); 374 uriMap.put(VIEW_TYPE, viewMapElement.getAttribute(VIEW_TYPE)); 375 uriMap.put(VIEW_INFO, viewMapElement.getAttribute(VIEW_INFO)); 376 uriMap.put(VIEW_CONTENT_TYPE, viewMapElement.getAttribute(VIEW_CONTENT_TYPE)); 377 uriMap.put(VIEW_ENCODING, viewMapElement.getAttribute(VIEW_ENCODING)); 378 379 String description = UtilXml.childElementValue(viewMapElement, VIEW_DESCRIPTION); 381 uriMap.put(VIEW_DESCRIPTION, UtilValidate.isNotEmpty(description) ? description : ""); 382 383 if (name != null) map.put(name, uriMap); 384 } 385 386 387 if (Debug.verboseOn()) { 388 Debug.logVerbose("-------- View Mappings --------", module); 389 FastMap debugMap = map; 390 Set debugSet = debugMap.keySet(); 391 Iterator i = debugSet.iterator(); 392 393 while (i.hasNext()) { 394 Object o = i.next(); 395 String request = (String ) o; 396 FastMap thisURI = (FastMap) debugMap.get(o); 397 398 StringBuffer verboseMessageBuffer = verboseMessageBuffer = new StringBuffer (); 399 400 Iterator debugIter = ((Set ) thisURI.keySet()).iterator(); 401 while (debugIter.hasNext()) { 402 Object lo = debugIter.next(); 403 String name = (String ) lo; 404 String value = (String ) thisURI.get(lo); 405 406 verboseMessageBuffer.append("[" + name + "=>" + value + "]"); 407 } 408 Debug.logVerbose(request + " :: " + verboseMessageBuffer.toString(), module); 409 } 410 Debug.logVerbose("------ End View Mappings ------", module); 411 } 412 413 414 double totalSeconds = (System.currentTimeMillis() - startTime)/1000.0; 415 if (Debug.infoOn()) Debug.logInfo("ViewMap Created: (" + map.size() + ") records in " + totalSeconds + "s", module); 416 return map; 417 } 418 419 420 public static Map getConfigMap(URL xml) { 421 ControllerConfig controllerConfig = getControllerConfig(xml); 422 return controllerConfig != null ? controllerConfig.configMap : null; 423 } 424 425 426 public static Map loadConfigMap(Element root, URL xml) { 427 long startTime = System.currentTimeMillis(); 428 FastMap map = FastMap.newInstance(); 429 if (root == null) { 430 root = loadDocument(xml); 431 } 432 433 if (root != null) { 434 String errorpage = UtilXml.childElementValue(root, DEFAULT_ERROR_PAGE); 436 if (UtilValidate.isNotEmpty(errorpage)) map.put(DEFAULT_ERROR_PAGE, errorpage); 437 438 String owner = UtilXml.childElementValue(root, SITE_OWNER); 440 if (UtilValidate.isNotEmpty(owner)) map.put(SITE_OWNER, owner); 441 442 String securityClass = UtilXml.childElementValue(root, SECURITY_CLASS); 444 if (UtilValidate.isNotEmpty(securityClass)) map.put(SECURITY_CLASS, securityClass); 445 446 Element firstvisitElement = UtilXml.firstChildElement(root, FIRSTVISIT); 448 if (firstvisitElement != null) { 449 List eventList = FastList.newInstance(); 450 List eventElementList = UtilXml.childElementList(firstvisitElement, EVENT); 451 Iterator eventElementIter = eventElementList.iterator(); 452 while (eventElementIter.hasNext()) { 453 Element eventElement = (Element ) eventElementIter.next(); 454 FastMap eventMap = FastMap.newInstance(); 455 eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); 456 eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); 457 eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); 458 459 eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); 461 eventList.add(eventMap); 462 } 463 map.put(FIRSTVISIT, eventList); 464 } 465 466 Element preprocessorElement = UtilXml.firstChildElement(root, PREPROCESSOR); 468 if (preprocessorElement != null) { 469 List eventList = FastList.newInstance(); 470 List eventElementList = UtilXml.childElementList(preprocessorElement, EVENT); 471 Iterator eventElementIter = eventElementList.iterator(); 472 while (eventElementIter.hasNext()) { 473 Element eventElement = (Element ) eventElementIter.next(); 474 FastMap eventMap = FastMap.newInstance(); 475 eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); 476 eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); 477 eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); 478 479 eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); 481 eventList.add(eventMap); 482 } 483 map.put(PREPROCESSOR, eventList); 484 } 485 486 Element postprocessorElement = UtilXml.firstChildElement(root, POSTPROCESSOR); 488 if (postprocessorElement != null) { 489 List eventList = FastList.newInstance(); 490 List eventElementList = UtilXml.childElementList(postprocessorElement, EVENT); 491 Iterator eventElementIter = eventElementList.iterator(); 492 while (eventElementIter.hasNext()) { 493 Element eventElement = (Element ) eventElementIter.next(); 494 FastMap eventMap = FastMap.newInstance(); 495 eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); 496 eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); 497 eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); 498 499 eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); 501 eventList.add(eventMap); 502 } 503 map.put(POSTPROCESSOR, eventList); 504 } 505 506 Element afterLoginElement = UtilXml.firstChildElement(root, "after-login"); 508 if (afterLoginElement != null) { 509 List eventList = FastList.newInstance(); 510 List eventElementList = UtilXml.childElementList(afterLoginElement, EVENT); 511 Iterator eventElementIter = eventElementList.iterator(); 512 while (eventElementIter.hasNext()) { 513 Element eventElement = (Element ) eventElementIter.next(); 514 FastMap eventMap = FastMap.newInstance(); 515 eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); 516 eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); 517 eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); 518 519 eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); 521 eventList.add(eventMap); 522 } 523 map.put("after-login", eventList); 524 } 525 526 Element beforeLogoutElement = UtilXml.firstChildElement(root, "before-logout"); 528 if (beforeLogoutElement != null) { 529 List eventList = FastList.newInstance(); 530 List eventElementList = UtilXml.childElementList(beforeLogoutElement, EVENT); 531 Iterator eventElementIter = eventElementList.iterator(); 532 while (eventElementIter.hasNext()) { 533 Element eventElement = (Element ) eventElementIter.next(); 534 FastMap eventMap = FastMap.newInstance(); 535 eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); 536 eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); 537 eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); 538 539 eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); 541 eventList.add(eventMap); 542 } 543 map.put("before-logout", eventList); 544 } 545 } 546 547 548 568 569 570 double totalSeconds = (System.currentTimeMillis() - startTime)/1000.0; 571 if (Debug.infoOn()) Debug.logInfo("ConfigMap Created: (" + map.size() + ") records in " + totalSeconds + "s", module); 572 return map; 573 } 574 575 576 public static Map getHandlerMap(URL xml) { 577 ControllerConfig controllerConfig = getControllerConfig(xml); 578 return controllerConfig != null ? controllerConfig.handlerMap : null; 579 } 580 581 public static Map loadHandlerMap(Element root, URL xml) { 582 long startTime = System.currentTimeMillis(); 583 FastMap map = FastMap.newInstance(); 584 if (root == null) { 585 root = loadDocument(xml); 586 } 587 588 if (root != null) { 589 Map rMap = FastMap.newInstance(); 590 Map vMap = FastMap.newInstance(); 591 592 List handlerElementList = UtilXml.childElementList(root, HANDLER); 593 Iterator handlerElementIter = handlerElementList.iterator(); 594 while (handlerElementIter.hasNext()) { 595 Element handlerElement = (Element ) handlerElementIter.next(); 596 String hName = checkEmpty(handlerElement.getAttribute(HANDLER_NAME)); 597 String hClass = checkEmpty(handlerElement.getAttribute(HANDLER_CLASS)); 598 String hType = checkEmpty(handlerElement.getAttribute(HANDLER_TYPE)); 599 if (hType.equals("view")) { 600 vMap.put(hName, hClass); 601 } else { 602 rMap.put(hName, hClass); 603 } 604 } 605 map.put("view", vMap); 606 map.put("event", rMap); 607 } 608 609 610 if (Debug.verboseOn()) { 611 Debug.logVerbose("-------- Handler Mappings --------", module); 612 Map debugMap = (Map ) map.get("event"); 613 614 if (debugMap != null && debugMap.size() > 0) { 615 Debug.logVerbose("-------------- EVENT -------------", module); 616 Set debugSet = debugMap.keySet(); 617 Iterator i = debugSet.iterator(); 618 while (i.hasNext()) { 619 Object o = i.next(); 620 String handlerName = (String ) o; 621 String className = (String ) debugMap.get(o); 622 Debug.logVerbose("[EH] : " + handlerName + " => " + className, module); 623 } 624 } 625 debugMap = (Map ) map.get("view"); 626 if (debugMap != null && debugMap.size() > 0) { 627 Debug.logVerbose("-------------- VIEW --------------", module); 628 Set debugSet = debugMap.keySet(); 629 Iterator i = debugSet.iterator(); 630 while (i.hasNext()) { 631 Object o = i.next(); 632 String handlerName = (String ) o; 633 String className = (String ) debugMap.get(o); 634 Debug.logVerbose("[VH] : " + handlerName + " => " + className, module); 635 } 636 } 637 Debug.logVerbose("------ End Handler Mappings ------", module); 638 } 639 640 double totalSeconds = (System.currentTimeMillis() - startTime)/1000.0; 641 if (Debug.infoOn()) Debug.logInfo("HandlerMap Created: (" + map.size() + ") records in " + totalSeconds + "s", module); 642 return map; 643 } 644 645 private static String checkEmpty(String string) { 646 if (string != null && string.length() > 0) 647 return string; 648 else 649 return ""; 650 } 651 652 public static void main(String args[]) throws Exception { 653 654 if (args[0] == null) { 655 System.out.println("Please give a path to the config file you wish to test."); 656 return; 657 } 658 System.out.println("----------------------------------"); 659 System.out.println("Request Mappings:"); 660 System.out.println("----------------------------------"); 661 Map debugMap = getRequestMap(new URL (args[0])); 662 Set debugSet = debugMap.keySet(); 663 Iterator i = debugSet.iterator(); 664 while (i.hasNext()) { 665 Object o = i.next(); 666 String request = (String ) o; 667 FastMap thisURI = (FastMap) debugMap.get(o); 668 669 System.out.println(request); 670 Iterator list = ((java.util.Set ) thisURI.keySet()).iterator(); 671 while (list.hasNext()) { 672 Object lo = list.next(); 673 String name = (String ) lo; 674 String value = (String ) thisURI.get(lo); 675 System.out.println("\t" + name + " -> " + value); 676 } 677 } 678 System.out.println("----------------------------------"); 679 System.out.println("End Request Mappings."); 680 System.out.println("----------------------------------"); 681 682 } 683 } 684 | Popular Tags |