📄 screenflowxmldao.java
字号:
/*
* $Id: ScreenFlowXmlDAO.java,v 1.1.1.1 2002/02/02 05:20:25 Administrator Exp $
* Copyright 2001 Sun Microsystems, Inc. All rights reserved.
* Copyright 2001 Sun Microsystems, Inc. Tous droits r閟erv閟.
*/
package com.huiton.mainframe.control.web;
import org.xml.sax.InputSource;
import org.w3c.dom.Element;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.SAXException;
// jaxp 1.0.1 imports
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import com.huiton.mainframe.util.tracer.Debug;
/**
* This class provides the data bindings for the screendefinitions.xml
* and the requestmappings.xml file.
* The data obtained is maintained by the ScreenFlowManager
*/
public class ScreenFlowXmlDAO {
// constants
public static final String URL_MAPPING = "url-mapping";
public static final String EXCEPTION_MAPPING = "exception-mapping";
public static final String SCREEN_DEFINITION = "screen-definition";
public static final String URL = "url";
public static final String LANGUAGE = "language";
public static final String TEMPLATE = "template";
public static final String TEMPLATE_NAME = "name";
public static final String RESULT = "result";
public static final String NEXT_SCREEN = "screen";
public static final String USE_REQUEST_HANDLER = "useRequestHandler";
public static final String REQUIRES_SIGNIN = "requiresSignin";
public static final String USE_FLOW_HANDLER = "useFlowHandler";
public static final String FLOW_HANDLER_CLASS = "class";
public static final String REQUEST_HANDLER_CLASS = "request-handler-class";
public static final String HANDLER_RESULT = "handler-result";
public static final String FLOW_HANDLER = "flow-handler";
public static final String EXCEPTION_CLASS = "exception-class";
public static final String DEFAULT_SCREEN = "default-screen";
public static final String SIGNIN_SCREEN = "signin-screen";
public static final String SIGNIN_ERROR_SCREEN = "signin-error-screen";
//张爱军增加的用以处理会话超时和无权限访问
public static final String SESSION_TIMEOUT_SCREEN = "session-timeout-screen";
public static final String NO_RIGHT_SCREEN = "no-right-screen";
//增加完毕
public static final String KEY = "key";
public static final String VALUE= "value";
public static final String DIRECT="direct";
public static final String SCREEN= "screen";
public static final String SCREEN_NAME = "screen-name";
public static final String PARAMETER = "parameter";
public static Element loadDocument(String location) {
Document doc = null;
try {
URL url = new URL(location);
InputSource xmlInp = new InputSource(url.openStream());
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = docBuilderFactory.newDocumentBuilder();
doc = parser.parse(xmlInp);
Element root = doc.getDocumentElement();
//root.normalize();
return root;
} catch (SAXParseException err) {
Debug.println ("ScreenFlowXmlDAO ** Parsing error" + ", line " +
err.getLineNumber () + ", uri " + err.getSystemId ());
Debug.println("ScreenFlowXmlDAO error: " + err.getMessage ());
} catch (SAXException e) {
Debug.println("ScreenFlowXmlDAO error: " + e);
} catch (java.net.MalformedURLException mfx) {
Debug.println("ScreenFlowXmlDAO error: " + mfx);
} catch (java.io.IOException e) {
Debug.println("ScreenFlowXmlDAO error: " + e);
} catch (Exception pce) {
Debug.println("ScreenFlowXmlDAO error: " + pce);
}
return null;
}
public static ScreenFlowData loadScreenFlowData(String location) {
Element root = loadDocument(location);
HashMap screenDefinitionMappings = getScreenDefinitions(root);
HashMap exceptionMappings = getExceptionMappings(root);
String defaultScreen = getTagValue(root, DEFAULT_SCREEN);
String signinScreen = getTagValue(root, SIGNIN_SCREEN);
String signinErrorScreen = getTagValue(root, SIGNIN_ERROR_SCREEN);
return new ScreenFlowData(exceptionMappings,
screenDefinitionMappings,
defaultScreen,
signinScreen,
signinErrorScreen);
}
public static HashMap loadScreenDefinitions(String location) {
Element root = loadDocument(location);
return getScreens(root);
}
public static HashMap loadRequestMappings(String location) {
Element root = loadDocument(location);
return getRequestMappings(root);
}
public static HashMap loadScreenDefinitionMappings(String location) {
Element root = loadDocument(location);
return getScreenDefinitions(root);
}
public static HashMap loadExceptionMappings(String location) {
Element root = loadDocument(location);
return getExceptionMappings(root);
}
private static String getSubTagAttribute(Element root, String tagName, String subTagName, String attribute) {
String returnString = "";
NodeList list = root.getElementsByTagName(tagName);
for (int loop = 0; loop < list.getLength(); loop++) {
Node node = list.item(loop);
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) ) {
if (child instanceof Element) {
return ((Element)child).getAttribute(attribute);
}
}
} // end inner loop
}
}
return returnString;
}
public static HashMap getScreenDefinitions(Element root) {
HashMap screensDefs = new HashMap();
NodeList list = root.getElementsByTagName(SCREEN_DEFINITION);
for (int loop = 0; loop < list.getLength(); loop++) {
Node node = list.item(loop);
if (node != null) {
String language = null;
String url = null;
if (node instanceof Element) {
language = ((Element)node).getAttribute(LANGUAGE);
url = ((Element)node).getAttribute(URL);
}
if ((language != null) && (url != null) && !screensDefs.containsKey(language)) {
screensDefs.put(language, url);
} else {
Debug.println("*** Non Fatal errror: ScreenDefinitions for language " + language +
" defined more than once in screen definitions file");
}
}
}
return screensDefs;
}
public static HashMap getScreens(Element root) {
HashMap screens = new HashMap();
// get the template
// 此处改成获取多模板
HashMap templates = new HashMap();
NodeList list = root.getElementsByTagName(TEMPLATE);
String templateName = "", templateValue = "";
for (int loop = 0; loop < list.getLength(); loop++) {
Node node = list.item(loop);
templateName = ((Element)node).getAttribute(TEMPLATE_NAME);
if (node != null) {
Node child = node.getFirstChild();
if ((child != null) && child.getNodeValue() != null)
templateValue = child.getNodeValue();
}
Debug.println("ScreenFlowXmlDAO.getScreen(): templateName = " + templateName);
Debug.println("ScreenFlowXmlDAO.getScreen(): templateValue = " + templateValue);
templates.put(templateName, templateValue);
}
screens.put(TEMPLATE, templates);
// 此处改成获取多模板
// get screens
list = root.getElementsByTagName(SCREEN);
for (int loop = 0; loop < list.getLength(); loop++) {
Node node = list.item(loop);
if (node != null) {
String screenName = getSubTagValue(node, SCREEN_NAME);
HashMap parameters = getParameters(node);
Screen screen = new Screen(screenName, parameters);
if (!screens.containsKey(screenName)) {
screens.put(screenName, screen);
} else {
Debug.println("*** Non Fatal errror: Screen " + screenName +
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -