?? screenflowxmldao.java
字號:
/* */package com.sun.j2ee.workflow.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 importsimport javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.DocumentBuilder;import java.net.URL;import java.util.ArrayList;import java.util.HashMap;import com.sun.j2ee.workflow.util.Debug;/** This class provides the data bindings for the screendefinitions.xml * and the requestmappings.xml file. * The data obtained is maintained by the ScreenFlowManager * @author Jian (James) Cai */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 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 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 String templateName = getTagValue(root, TEMPLATE); screens.put(TEMPLATE, templateName); // get screens NodeList 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 + " defined more than once in screen definitions file"); } } } return screens; } private static HashMap getParameters(Node node) { HashMap params = new HashMap(); if (node != null) { NodeList children = node.getChildNodes();
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -