⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 urlmappingsxmldao.java

📁 sun公司的petstore,一个J2ee的示例应用程序.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            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);                    exceptionClassName = element.getAttribute(EXCEPTION_CLASS);                    screen = element.getAttribute(SCREEN);                    exceptionMappings.put(exceptionClassName, screen);                }            }        }        return exceptionMappings;    }    public static HashMap getEventMappings(Element root) {        HashMap eventMappings = new HashMap();        NodeList list = root.getElementsByTagName(EVENT_MAPPING);        for (int loop = 0; loop < list.getLength(); loop++) {            Node node = list.item(loop);            if (node != null) {                String eventClassName = getSubTagValue(node,EVENT_CLASS);                String ejbActionClass = getSubTagValue(node, EJB_ACTION_CLASS);                if ((eventClassName != null) && !eventClassName.equals("")) {                    eventMappings.put(eventClassName, new EventMapping(eventClassName, ejbActionClass));                }            }        }        return eventMappings;    }    public static HashMap getRequestMappings(Element root) {        HashMap urlMappings = new HashMap();        NodeList list = root.getElementsByTagName(URL_MAPPING);        for (int loop = 0; loop < list.getLength(); loop++) {            Node node = list.item(loop);            if (node != null) {                String url = "";                String screen = null;                String useActionString = null;                String useFlowHandlerString = null;                String requiresSigninString = null;                String flowHandler = null;                String webActionClass =null;                String ejbActionClass = null;                HashMap resultMappings = null;                boolean useFlowHandler = false;                boolean isAction = false;                boolean requiresSignin = false;                // get url mapping attributes                // need to be a element to get attributes                if (node instanceof Element) {                    Element element = ((Element)node);                    url = element.getAttribute(URL);                    screen = element.getAttribute(NEXT_SCREEN);                    useActionString = element.getAttribute(PROCESSS_ACTION);                    useFlowHandlerString = element.getAttribute(USE_FLOW_HANDLER);                }                webActionClass = getSubTagValue(node, WEB_ACTION_CLASS);                if (webActionClass != null) isAction= true;                // get request handler                if ((useFlowHandlerString != null) && useFlowHandlerString.equals("true")) useFlowHandler = true;                // get flow handler                if ((useFlowHandlerString != null) && useFlowHandlerString.equals("true")) useFlowHandler = true;                if (useFlowHandler) {                    // need to be a element to find sub nodes by name                    if (node instanceof Element) {                        Element element = (Element)node;                        NodeList children = element.getElementsByTagName(FLOW_HANDLER);                        Node flowHandlerNode = null;                        if (children.getLength() >= 1) {                            flowHandlerNode = children.item(0);                        }                        if (children.getLength() > 1) {                                 System.err.println("Non fatal error: There can be only one <" + FLOW_HANDLER +                                               "> definition in a <" + URL_MAPPING + ">");                        }                        // get the flow handler details                        if (flowHandlerNode != null) {                            if (flowHandlerNode instanceof Element) {                                Element flowElement = (Element)flowHandlerNode;                                flowHandler = flowElement.getAttribute(FLOW_HANDLER_CLASS);                                NodeList results = flowElement.getElementsByTagName(HANDLER_RESULT);                                if (results.getLength() > 0){                                    resultMappings = new HashMap();                                }                                for (int resultLoop=0; resultLoop < results.getLength(); resultLoop++) {                                    Node resultNode = results.item(resultLoop);                                    if (resultNode instanceof Element) {                                        Element resultElement = (Element)resultNode;                                        String key = resultElement.getAttribute(RESULT);                                        String value = resultElement.getAttribute(NEXT_SCREEN);                                        if (!resultMappings.containsKey(key)) {                                            resultMappings.put(key,value);                                        } else {                                            System.err.println("*** Non Fatal errror: Screen " + url + " <" + FLOW_HANDLER +                                                           "> key " + "\"" + key + "\" defined more than one time");                                        }                                    }                                } // end for                            }                        } // end if (flowHandler != null)                    }                } // end if (useFlowHandler)                URLMapping mapping = new URLMapping(url, screen,                                             isAction,                                             useFlowHandler,                                             webActionClass,                                             flowHandler,                                             resultMappings);                if (!urlMappings.containsKey(url)) {                    urlMappings.put(url, mapping);                } else {                    System.err.println("*** Non Fatal errror: Screen " + url +                                       " defined more than once in screen definitions file");                }            }        }        return urlMappings;    }    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();                }            } // end inner loop        }        return returnString;    }    public static String getSubTagValue(Element root, String tagName, String subTagName) {        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) ) {                        Node grandChild = child.getFirstChild();                        if (grandChild.getNodeValue() != null) return grandChild.getNodeValue();                    }                } // end inner loop            }        }        return returnString;    }    public static String getTagValue(Element root, String tagName) {        String returnString = "";        NodeList list = root.getElementsByTagName(tagName);        for (int loop = 0; loop < list.getLength(); loop++) {            Node node = list.item(loop);            if (node != null) {                Node child = node.getFirstChild();                if ((child != null) && child.getNodeValue() != null) return child.getNodeValue();            }        }        return returnString;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -