📄 configxmlreader.java
字号:
}
}
} else {
uriMap.put(REQUEST_DESCRIPTION, "");
}
// Get the response(s).
NodeList respList = mapping.getElementsByTagName(RESPONSE);
for (int respCount = 0; respCount < respList.getLength(); respCount++) {
Node responseNode = respList.item(respCount);
if (responseNode instanceof Element) {
Element response = (Element) responseNode;
String name = response.getAttribute(RESPONSE_NAME);
String type = response.getAttribute(RESPONSE_TYPE);
String value = response.getAttribute(RESPONSE_VALUE);
uriMap.put(name, type + ":" + value);
}
}
if (uri != null)
map.put(uri, uriMap);
}
}
/* Debugging */
if (Debug.verboseOn()) Debug.logVerbose("-------- Request 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);
if (Debug.verboseOn()) 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);
}
}
if (Debug.verboseOn()) Debug.logVerbose("------ End Request Mappings ------", module);
/* End Debugging */
if (Debug.infoOn()) Debug.logInfo("RequestMap Created: (" + map.size() + ") records.", module);
return map;
}
/** Gets a HashMap of view mappings. */
public static Map getViewMap(URL xml) {
Map viewMap = (Map) viewCache.get(xml);
if (viewMap == null) // don't want to block here
{
synchronized (ConfigXMLReader.class) {
// must check if null again as one of the blocked threads can still enter
viewMap = (HashMap) viewCache.get(xml);
if (viewMap == null) {
viewMap = loadViewMap(xml);
viewCache.put(xml, viewMap);
}
}
}
// never return null, just an empty map...
if (viewMap == null) viewMap = new HashMap();
return viewMap;
}
/** Gets a HashMap of view mappings. */
public static Map loadViewMap(URL xml) {
HashMap map = new HashMap();
Element root = loadDocument(xml);
if (root == null)
return map;
NodeList list = root.getElementsByTagName(INCLUDE);
for (int rootCount = 0; rootCount < list.getLength(); rootCount++) {
Node node = list.item(rootCount);
// Make sure we are an element.
if (node instanceof Element) {
// Get the file to include
Element mapping = (Element) node;
String includeFile = mapping.getAttribute(INCLUDE_FILE);
if ((includeFile != null) && (includeFile.length() > 0)) {
File oldFile = new File(xml.getFile());
File newFile = new java.io.File("" + oldFile.getParent() + java.io.File.separator + includeFile);
try {
Map subMap = loadViewMap(newFile.toURL());
map.putAll(subMap);
} catch (MalformedURLException mue) {
mue.printStackTrace();
}
}
String includeURL = mapping.getAttribute(INCLUDE_URL);
if ((includeURL != null) && (includeURL.length() > 0)) {
try {
Map subMap = loadViewMap(new URL(includeURL));
map.putAll(subMap);
} catch (MalformedURLException mue) {
mue.printStackTrace();
}
}
}
}
list = root.getElementsByTagName(VIEW_MAPPING);
for (int rootCount = 0; rootCount < list.getLength(); rootCount++) {
// Create a URI-MAP for each element found.
HashMap uriMap = new HashMap();
// Get the node.
Node node = list.item(rootCount);
// Make sure we are an element.
if (node instanceof Element) {
// Get the view info.
Element mapping = (Element) node;
String name = mapping.getAttribute(VIEW_NAME);
String page = mapping.getAttribute(VIEW_PAGE);
String type = mapping.getAttribute(VIEW_TYPE);
if (page == null || page.length() == 0) {
page = name;
}
uriMap.put(VIEW_NAME, name);
uriMap.put(VIEW_PAGE, page);
uriMap.put(VIEW_TYPE, type);
uriMap.put(VIEW_INFO, mapping.getAttribute(VIEW_INFO));
uriMap.put(VIEW_CONTENT_TYPE, mapping.getAttribute(VIEW_CONTENT_TYPE));
uriMap.put(VIEW_ENCODING, mapping.getAttribute(VIEW_ENCODING));
// Check for a description.
NodeList descList = mapping.getElementsByTagName(VIEW_DESCRIPTION);
if (descList.getLength() > 0) {
Node descNode = descList.item(0); // There should be only one.
if (descNode instanceof Element) { // We must be an element.
NodeList children = descNode.getChildNodes();
if (children.getLength() > 0) {
Node cdata = children.item(0); // Just get the first one.
String description = cdata.getNodeValue();
if (description != null)
description = description.trim();
else
description = "";
uriMap.put(VIEW_DESCRIPTION, description);
}
}
} else {
uriMap.put(VIEW_DESCRIPTION, "");
}
if (name != null)
map.put(name, uriMap);
}
}
/* Debugging */
Debug.logVerbose("-------- View 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 View Mappings ------", module);
/* End Debugging */
if (Debug.infoOn()) Debug.logInfo("ViewMap Created: (" + map.size() + ") records.", module);
return map;
}
/** Gets a HashMap of site configuration variables. */
public static Map getConfigMap(URL xml) {
Map configMap = (Map) headCache.get(xml);
if (configMap == null) // don't want to block here
{
synchronized (ConfigXMLReader.class) {
// must check if null again as one of the blocked threads can still enter
configMap = (HashMap) headCache.get(xml);
if (configMap == null) {
configMap = loadConfigMap(xml);
headCache.put(xml, configMap);
}
}
}
// never return null, just an empty map...
if (configMap == null) configMap = new HashMap();
return configMap;
}
/** Gets a HashMap of site configuration variables. */
public static Map loadConfigMap(URL xml) {
HashMap map = new HashMap();
Element root = loadDocument(xml);
NodeList list = null;
if (root != null) {
// default error page
list = root.getElementsByTagName(DEFAULT_ERROR_PAGE);
if (list.getLength() > 0) {
Node node = list.item(0);
NodeList children = node.getChildNodes();
Node child = children.item(0);
if (child.getNodeName() != null)
map.put(DEFAULT_ERROR_PAGE, child.getNodeValue());
}
list = null;
// site owner
list = root.getElementsByTagName(SITE_OWNER);
if (list.getLength() > 0) {
Node node = list.item(0);
NodeList children = node.getChildNodes();
Node child = children.item(0);
if (child.getNodeName() != null)
map.put(SITE_OWNER, child.getNodeValue());
}
list = null;
// security class
list = root.getElementsByTagName(SECURITY_CLASS);
if (list.getLength() > 0) {
Node node = list.item(0);
NodeList children = node.getChildNodes();
Node child = children.item(0);
if (child.getNodeName() != null)
map.put(SECURITY_CLASS, child.getNodeValue());
}
list = null;
// first visit events
list = root.getElementsByTagName(FIRSTVISIT);
if (list.getLength() > 0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -