📄 configxmlreader.java
字号:
ArrayList eventList = new ArrayList();
Node node = list.item(0);
if (node instanceof Element) {
Element nodeElement = (Element) node;
NodeList procEvents = nodeElement.getElementsByTagName(EVENT);
for (int procCount = 0; procCount < procEvents.getLength(); procCount++) {
Node eventNode = procEvents.item(procCount);
if (eventNode instanceof Element) {
Element event = (Element) eventNode;
String type = event.getAttribute(EVENT_TYPE);
String path = event.getAttribute(EVENT_PATH);
String invoke = event.getAttribute(EVENT_METHOD);
HashMap eventMap = new HashMap();
eventMap.put(EVENT_TYPE, type);
eventMap.put(EVENT_PATH, path);
eventMap.put(EVENT_METHOD, invoke);
eventList.add(eventMap);
}
}
}
map.put(FIRSTVISIT, eventList);
}
list = null;
// preprocessor events
list = root.getElementsByTagName(PREPROCESSOR);
if (list.getLength() > 0) {
ArrayList eventList = new ArrayList();
Node node = list.item(0);
if (node instanceof Element) {
Element nodeElement = (Element) node;
NodeList procEvents = nodeElement.getElementsByTagName(EVENT);
for (int procCount = 0; procCount < procEvents.getLength(); procCount++) {
Node eventNode = procEvents.item(procCount);
if (eventNode instanceof Element) {
Element event = (Element) eventNode;
String type = event.getAttribute(EVENT_TYPE);
String path = event.getAttribute(EVENT_PATH);
String invoke = event.getAttribute(EVENT_METHOD);
HashMap eventMap = new HashMap();
eventMap.put(EVENT_TYPE, type);
eventMap.put(EVENT_PATH, path);
eventMap.put(EVENT_METHOD, invoke);
eventList.add(eventMap);
}
}
}
map.put(PREPROCESSOR, eventList);
}
list = null;
// postprocessor events
list = root.getElementsByTagName(POSTPROCESSOR);
if (list.getLength() > 0) {
ArrayList eventList = new ArrayList();
Node node = list.item(0);
if (node instanceof Element) {
Element nodeElement = (Element) node;
NodeList procEvents = nodeElement.getElementsByTagName(EVENT);
for (int procCount = 0; procCount < procEvents.getLength(); procCount++) {
Node eventNode = procEvents.item(procCount);
if (eventNode instanceof Element) {
Element event = (Element) eventNode;
String type = event.getAttribute(EVENT_TYPE);
String path = event.getAttribute(EVENT_PATH);
String invoke = event.getAttribute(EVENT_METHOD);
HashMap eventMap = new HashMap();
eventMap.put(EVENT_TYPE, type);
eventMap.put(EVENT_PATH, path);
eventMap.put(EVENT_METHOD, invoke);
eventList.add(eventMap);
}
}
}
map.put(POSTPROCESSOR, eventList);
}
list = null;
}
/* Debugging */
/*
Debug.logVerbose("-------- Config Mappings --------", module);
HashMap debugMap = map;
Set debugSet = debugMap.keySet();
Iterator i = debugSet.iterator();
while (i.hasNext()) {
Object o = i.next();
String request = (String) o;
HashMap thisURI = (HashMap) debugMap.get(o);
Debug.logVerbose(request, module);
Iterator debugIter = ((Set) thisURI.keySet()).iterator();
while (debugIter.hasNext()) {
Object lo = debugIter.next();
String name = (String) lo;
String value = (String) thisURI.get(lo);
if (Debug.verboseOn()) Debug.logVerbose("\t" + name + " -> " + value, module);
}
}
Debug.logVerbose("------ End Config Mappings ------", module);
*/
/* End Debugging */
if (Debug.infoOn()) Debug.logInfo("ConfigMap Created: (" + map.size() + ") records.", module);
return map;
}
/** Gets a HashMap of handler mappings. */
public static Map getHandlerMap(URL xml) {
Map handlerMap = (Map) handlerCache.get(xml);
if (handlerMap == null) // don't want to block here
{
synchronized (ConfigXMLReader.class) {
// must check if null again as one of the blocked threads can still enter
handlerMap = (HashMap) handlerCache.get(xml);
if (handlerMap == null) {
handlerMap = loadHandlerMap(xml);
handlerCache.put(xml, handlerMap);
}
}
}
// never return null, just an empty map...
if (handlerMap == null) handlerMap = new HashMap();
return handlerMap;
}
public static Map loadHandlerMap(URL xml) {
HashMap map = new HashMap();
Element root = loadDocument(xml);
NodeList list = null;
if (root != null) {
Map rMap = new HashMap();
Map vMap = new HashMap();
list = root.getElementsByTagName(HANDLER);
for (int i = 0; i < list.getLength(); i++) {
Element handler = (Element) list.item(i);
String hName = checkEmpty(handler.getAttribute(HANDLER_NAME));
String hClass = checkEmpty(handler.getAttribute(HANDLER_CLASS));
String hType = checkEmpty(handler.getAttribute(HANDLER_TYPE));
if (hType.equals("view"))
vMap.put(hName, hClass);
else
rMap.put(hName, hClass);
}
map.put("view", vMap);
map.put("event", rMap);
}
/* Debugging */
Debug.logVerbose("-------- Handler Mappings --------", module);
Map debugMap = (Map) map.get("event");
if (debugMap != null && debugMap.size() > 0) {
Debug.logVerbose("-------------- EVENT -------------", module);
Set debugSet = debugMap.keySet();
Iterator i = debugSet.iterator();
while (i.hasNext()) {
Object o = i.next();
String handlerName = (String) o;
String className = (String) debugMap.get(o);
if (Debug.verboseOn()) Debug.logVerbose("[EH] : " + handlerName + " => " + className, module);
}
}
debugMap = (Map) map.get("view");
if (debugMap != null && debugMap.size() > 0) {
Debug.logVerbose("-------------- VIEW --------------", module);
Set debugSet = debugMap.keySet();
Iterator i = debugSet.iterator();
while (i.hasNext()) {
Object o = i.next();
String handlerName = (String) o;
String className = (String) debugMap.get(o);
if (Debug.verboseOn()) Debug.logVerbose("[VH] : " + handlerName + " => " + className, module);
}
}
Debug.logVerbose("------ End Handler Mappings ------", module);
/* End Debugging */
if (Debug.infoOn()) Debug.logInfo("HandlerMap Created: (" + map.size() + ") records.", module);
return map;
}
private static String checkEmpty(String string) {
if (string != null && string.length() > 0)
return string;
else
return "";
}
/** Not used right now */
public static String getSubTagValue(Node node, String subTagName) {
String returnString = "";
if (node != null) {
NodeList children = node.getChildNodes();
for (int innerLoop = 0; innerLoop < children.getLength(); innerLoop++) {
Node child = children.item(innerLoop);
if ((child != null) && (child.getNodeName() != null) && child.getNodeName().equals(subTagName)) {
Node grandChild = child.getFirstChild();
if (grandChild.getNodeValue() != null)
return grandChild.getNodeValue();
}
}
}
return returnString;
}
public static void main(String args[]) throws Exception {
/** Debugging */
if (args[0] == null) {
System.out.println("Please give a path to the config file you wish to test.");
return;
}
System.out.println("----------------------------------");
System.out.println("Request Mappings:");
System.out.println("----------------------------------");
java.util.HashMap debugMap = getRequestMap(new URL(args[0]));
java.util.Set debugSet = debugMap.keySet();
java.util.Iterator i = debugSet.iterator();
while (i.hasNext()) {
Object o = i.next();
String request = (String) o;
HashMap thisURI = (java.util.HashMap) debugMap.get(o);
System.out.println(request);
java.util.Iterator list = ((java.util.Set) thisURI.keySet()).iterator();
while (list.hasNext()) {
Object lo = list.next();
String name = (String) lo;
String value = (String) thisURI.get(lo);
System.out.println("\t" + name + " -> " + value);
}
}
System.out.println("----------------------------------");
System.out.println("End Request Mappings.");
System.out.println("----------------------------------");
/** End Debugging */
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -