Source Code Cross Referenced for Dom.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » console » help » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ESB » cbesb 1.2 » com.bostechcorp.cbesb.console.help 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ChainBuilder ESB
003:         * 		Visual Enterprise Integration
004:         * 
005:         * Copyright (C) 2006 Bostech Corporation
006:         * 
007:         * This program is free software; you can redistribute it and/or modify it 
008:         * under the terms of the GNU General Public License as published by the 
009:         * Free Software Foundation; either version 2 of the License, or (at your option) 
010:         * any later version.
011:         *
012:         * This program is distributed in the hope that it will be useful, 
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
014:         * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
015:         * for more details.
016:         * 
017:         * You should have received a copy of the GNU General Public License along with 
018:         * this program; if not, write to the Free Software Foundation, Inc., 
019:         * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020:         *
021:         *
022:         * $Id: Dom.java 4950 2007-01-29 09:21:20Z lzheng $
023:         */
024:
025:        package com.bostechcorp.cbesb.console.help;
026:
027:        import org.w3c.dom.NamedNodeMap;
028:        import org.w3c.dom.Node;
029:        import org.w3c.dom.NodeList;
030:
031:        public class Dom {
032:
033:            /**
034:             * Search for a child with the given nodeName. If recursive, search in all
035:             * the child of firdt level, then if not found, search in the 2nd level of
036:             * the first child, ...
037:             * 
038:             * @param parent
039:             *            parent node
040:             * @param nodeName
041:             *            node name
042:             * @param recursive
043:             *            boolean to know if we got through the xml tree
044:             * @return a node
045:             */
046:            public static Node findChild(Node parent, String nodeName,
047:                    boolean recursive) {
048:                parent.normalize();
049:                Node result = null;
050:                if (parent != null && nodeName != null) {
051:                    NodeList nl = parent.getChildNodes();
052:                    for (int i = 0; i < nl.getLength() && result == null; i++) {
053:                        if (nodeName.equals(nl.item(i).getNodeName())) {
054:                            result = nl.item(i);
055:                        }
056:                    }
057:                    // now, search recursively if required
058:                    if (result == null && recursive) {
059:                        for (int i = 0; i < nl.getLength() && result == null; i++) {
060:                            result = findChild(nl.item(i), nodeName, true);
061:                        }
062:                    }
063:                }
064:                return result;
065:            }
066:
067:            /**
068:             * Search for a child with the given nodeName. If recursive, search in all
069:             * the child of firdt level, then if not found, search in the 2nd level of
070:             * the first child, ...
071:             * 
072:             * @param parent
073:             *            parent node
074:             * @param namespaceURI
075:             *            The namespaceURI of the node
076:             * @param nodeName
077:             *            node name
078:             * @param recursive
079:             *            boolean to know if we got through the xml tree
080:             * @return a node
081:             */
082:            public static Node findChild(Node parent, String namespaceURI,
083:                    String nodeName, boolean recursive) {
084:                parent.normalize();
085:                String prefix = getPrefixForNamespaceURIRecursive(parent,
086:                        namespaceURI);
087:                return (findChild(parent, prefix + nodeName, recursive));
088:            }
089:
090:            /**
091:             * Return the first child of a node, regardless <i>text</i> node
092:             * 
093:             * @param node
094:             * @return
095:             */
096:            public static Node getFirstChild(Node node) {
097:                node.normalize();
098:                Node result = node.getFirstChild();
099:                while (result.getNodeType() == Node.TEXT_NODE) {
100:                    result = result.getNextSibling();
101:                }
102:                return result;
103:            }
104:
105:            /**
106:             * Return the next sibling of a node, regardless <i>text</i> node
107:             * 
108:             * @param node
109:             * @return
110:             */
111:            public static Node getNextSibling(Node node) {
112:                node.normalize();
113:                Node result = node.getNextSibling();
114:                while (result.getNodeType() == Node.TEXT_NODE) {
115:                    result = result.getNextSibling();
116:                }
117:                return result;
118:            }
119:
120:            /**
121:             * Search a document to see if a namespace is declared in it and if it is
122:             * returns this namespace URI
123:             * @param node 
124:             * @param namespaceURI 
125:             * @param deep 
126:             * @return
127:             */
128:            public static String getPrefixForNamespaceURI(Node node,
129:                    String namespaceURI) {
130:                String result = "";
131:
132:                // Search in root node attributes
133:                NamedNodeMap attributes = node.getAttributes();
134:                int i = 0;
135:                if (attributes != null) {
136:                    while (i < attributes.getLength()) {
137:                        Node attr = attributes.item(i++);
138:                        if (namespaceURI.equals(attr.getNodeValue())) {
139:                            String nodeName = attr.getNodeName();
140:                            if (nodeName.startsWith("xmlns:")) {
141:                                result = nodeName.replaceFirst("xmlns:", "")
142:                                        + ":";
143:                                return result;
144:                            } else if (nodeName.startsWith("xmlns")) {
145:                                return result;
146:                            }
147:                        }
148:                    }
149:                }
150:                // Search in child nodes attributes
151:                i = 0;
152:                NodeList nl = node.getChildNodes();
153:                while (i < nl.getLength()) {
154:                    Node tmpNode = nl.item(i++);
155:                    String prefix = getPrefixForNamespaceURI(tmpNode,
156:                            namespaceURI);
157:                    if (prefix != null) {
158:                        return prefix;
159:                    }
160:                }
161:                return null;
162:
163:            }
164:
165:            public static String getPrefixForNamespaceURIRecursive(Node node,
166:                    String namespaceURI) {
167:                String result = "";
168:                if (namespaceURI != null && !"".equals(namespaceURI)) {
169:                    while (node.getParentNode() != null) {
170:                        node = node.getParentNode();
171:                    }
172:                    // Search in root node attributes
173:                    NamedNodeMap attributes = node.getAttributes();
174:                    int i = 0;
175:                    if (attributes != null) {
176:                        while (i < attributes.getLength()) {
177:                            Node attr = attributes.item(i++);
178:                            if (namespaceURI.equals(attr.getNodeValue())) {
179:                                String nodeName = attr.getNodeName();
180:                                if (nodeName.startsWith("xmlns:")) {
181:                                    result = nodeName
182:                                            .replaceFirst("xmlns:", "")
183:                                            + ":";
184:                                    return result;
185:                                } else if (nodeName.startsWith("xmlns")) {
186:                                    return result;
187:                                }
188:                            }
189:                        }
190:                    }
191:                    // Search in child nodes attributes
192:                    i = 0;
193:                    NodeList nl = node.getChildNodes();
194:                    while (i < nl.getLength()) {
195:                        Node tmpNode = nl.item(i++);
196:                        String prefix = getPrefixForNamespaceURI(tmpNode,
197:                                namespaceURI);
198:                        if (prefix != null) {
199:                            return prefix;
200:                        }
201:                    }
202:                }
203:
204:                return result;
205:            }
206:
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.