📄 urlmappingsxmldao.java
字号:
/* Copyright 2004 Sun Microsystems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistribution in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of Sun Microsystems, Inc. or the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. This software is provided "AS IS," without a warranty of any kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. You acknowledge that Software is not designed, licensed or intended for use in the design, construction, operation or maintenance of any nuclear facility. $Id: URLMappingsXmlDAO.java,v 1.1 2004/04/15 03:44:08 yutayoshida Exp $ */package com.sun.j2ee.blueprints.waf.controller.web;import org.xml.sax.InputSource;import org.w3c.dom.*;import org.xml.sax.*;// jaxp 1.0.1 importsimport javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.DocumentBuilder;import java.net.URL;import java.util.*;import com.sun.j2ee.blueprints.util.tracer.Debug;import com.sun.j2ee.blueprints.waf.controller.web.URLMapping;import com.sun.j2ee.blueprints.waf.controller.web.ScreenFlowData;/** * 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 URLMappingsXmlDAO { // constants public static final String URL_MAPPING = "url-mapping"; public static final String EVENT_MAPPING = "event-mapping"; public static final String EXCEPTION_MAPPING = "exception-mapping"; 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 PROCESSS_ACTION = "isAction"; public static final String REQUIRES_SIGNIN = "requiresSignin"; public static final String USE_FLOW_HANDLER = "useFlowHandler"; public static final String IS_TRANSACTIONAL = "isTransactional"; public static final String FLOW_HANDLER_CLASS = "class"; public static final String WEB_ACTION_CLASS = "web-action-class"; public static final String EJB_ACTION_CLASS = "ejb-action-class"; public static final String COMMAND_CLASS = "command-class"; public static final String EVENT_CLASS = "event-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 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) { System.err.println ("URLMappingsXmlDAO ** Parsing error" + ", line " + err.getLineNumber () + ", uri " + err.getSystemId ()); System.err.println("URLMappingsXmlDAO error: " + err.getMessage ()); } catch (SAXException e) { System.err.println("URLMappingsXmlDAO error: " + e); } catch (java.net.MalformedURLException mfx) { System.err.println("URLMappingsXmlDAO error: " + mfx); } catch (java.io.IOException e) { System.err.println("URLMappingsXmlDAO error: " + e); } catch (Exception pce) { System.err.println("URLMappingsXmlDAO error: " + pce); } return null; } public static ScreenFlowData loadScreenFlowData(String location) { Element root = loadDocument(location); ArrayList exceptionMappings = getExceptionMappings(root); String defaultScreen = getTagValue(root, DEFAULT_SCREEN); return new ScreenFlowData(exceptionMappings, defaultScreen); } public static HashMap loadRequestMappings(String location) { Element root = loadDocument(location); return getRequestMappings(root); } public static ArrayList loadExceptionMappings(String location) { Element root = loadDocument(location); return getExceptionMappings(root); } public static HashMap loadEventMappings(String location) { Element root = loadDocument(location); return getEventMappings(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 ArrayList getExceptionMappings(Element root) { ArrayList exceptionMappings = new ArrayList(); NodeList list = root.getElementsByTagName(EXCEPTION_MAPPING); for (int loop = 0; loop < list.getLength(); loop++) { Node node = list.item(loop); if (node != null) { String exceptionClassName = ""; String screen = null; // get exception nodes // need to be a element to get attributes if (node instanceof Element) { Element element = ((Element)node);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -