Source Code Cross Referenced for XmlUtil.java in  » Test-Coverage » NoUnit » net » firstpartners » nounit » utility » 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 » Test Coverage » NoUnit » net.firstpartners.nounit.utility 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.firstpartners.nounit.utility;
002:
003:        /**
004:         * Title:        NoUnit - Identify Classes that are not being unit Tested
005:         *
006:         * Copyright (C) 2001  Paul Browne , FirstPartners.net
007:         *
008:         *
009:         * This program is free software; you can redistribute it and/or 
010:         * modify it under the terms of the GNU General Public License
011:         * as published by the Free Software Foundation; either version 2
012:         * of the License, or (at your option) any later version.
013:         *
014:         * This program is distributed in the hope that it will be useful,
015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017:         * GNU General Public License for more details.
018:         *
019:         * You should have received a copy of the GNU General Public License
020:         * along with this program; if not, write to the Free Software
021:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
022:         *
023:         * @author Paul Browne
024:         * @version 0.7
025:         */
026:
027:        import java.util.HashMap;
028:        import java.util.HashSet;
029:        import java.util.List;
030:        import java.util.ListIterator;
031:        import java.util.Vector;
032:
033:        import org.jdom.Attribute;
034:        import org.jdom.Document;
035:        import org.jdom.Element;
036:
037:        /**
038:         * General XML Utility Functions
039:         */
040:        public class XmlUtil {
041:
042:            /**
043:             * indexes the nodes in the document that is passed in , via a HashMap mapping
044:             * mapping is in the format <index> as String , handle to <element> of node<BR>
045:             * Strings are used as they are better lookup in the hashmap.
046:             * @param inXmlDocument to generated the hashmap from
047:             * @param uniqueAttribute to do the index on (i.e. key in HashMap). Examples
048:             *        of uniqueAttributes are id's or names.
049:             * @return HashMap containing mappings
050:             */
051:            public static HashMap getNodeIndex(Document inXmlDocument,
052:                    String uniqueAttribute) {
053:
054:                //Internal Variables
055:                int stackPointer = 0;
056:                String locationId = null;
057:                Attribute tmpAttribute = null;
058:                Element this Element = null;
059:                ListIterator deepestList = null;
060:
061:                HashMap mappings = new HashMap();
062:                List stack = new Vector();
063:
064:                //Get the list information for the entire document
065:                stack.add(inXmlDocument.getContent().listIterator());
066:
067:                //Loop though the elements on list
068:                while (!stack.isEmpty()) {
069:
070:                    //Get the last list on the stack
071:                    deepestList = (ListIterator) stack.get(stack.size() - 1);
072:
073:                    //Does this list have more elements?
074:                    if (deepestList.hasNext()) {
075:
076:                        //if so Get Next element from this list
077:                        this Element = (Element) deepestList.next();
078:
079:                        //Add Mapping for this element to hashtable
080:                        tmpAttribute = this Element
081:                                .getAttribute(uniqueAttribute);
082:
083:                        //Attibute can be null for non folder elements (e.g. root element) - if so ignore
084:                        if (tmpAttribute != null) {
085:                            locationId = tmpAttribute.getValue();
086:                            if ((locationId != null) && (locationId != "")) {
087:                                mappings
088:                                        .put(locationId.toString(), this Element);
089:
090:                            }
091:                        } //end add mapping
092:
093:                        //does this list have children ?
094:                        if (this Element.hasChildren()) {
095:
096:                            //if so add to the stack
097:                            stackPointer++;
098:                            stack.add(this Element.getChildren().listIterator());
099:                        }
100:                    } else {
101:                        //if not , remove this list from the stack
102:                        stack.remove(stackPointer);
103:                        stackPointer--;
104:
105:                    } // end if stack has more elements
106:
107:                }
108:
109:                return mappings;
110:            }
111:
112:            /**
113:             * gets all elements in the XML Document Being Passed in <BR>
114:             * @param inXmlDocument to generated the hashmap from
115:             * @return nodeList containing nodes
116:             */
117:            public static HashSet getAllNodes(Document inXmlDocument) {
118:
119:                //Internal Variables
120:                int stackPointer = 0;
121:                int index = 1;
122:                String locationId = null;
123:                Element currentElement = null;
124:                Element parentElement = null;
125:                Element this Element = null;
126:                Attribute tmpAttribute = null;
127:                List elementList = null;
128:                ListIterator deepestList = null;
129:
130:                HashMap mappings = new HashMap();
131:                HashSet nodeList = new HashSet();
132:                List stack = new Vector(); //Implements list interface
133:
134:                //Get the list information for the entire document - kick start loop
135:                stack.add(inXmlDocument.getContent().listIterator());
136:
137:                //Loop though the elements on list
138:                while (!stack.isEmpty()) {
139:
140:                    //Get the last list on the stack
141:                    deepestList = (ListIterator) stack.get(stack.size() - 1);
142:
143:                    //Does this list have more elements?
144:                    if (deepestList.hasNext()) {
145:
146:                        //if so Get Next element from this list
147:                        this Element = (Element) deepestList.next();
148:
149:                        // add this element to the list
150:                        nodeList.add(this Element);
151:
152:                        //does this list have children ?
153:                        if (this Element.hasChildren()) {
154:
155:                            //if so add to the stack
156:                            stackPointer++;
157:                            stack.add(this Element.getChildren().listIterator());
158:                        }
159:                    } else {
160:                        //if not , remove this list from the stack
161:                        stack.remove(stackPointer);
162:                        stackPointer--;
163:
164:                    } // end if stack has more elements
165:
166:                }
167:
168:                return nodeList;
169:            }
170:
171:            /**
172:             * Search for Nodes within Jdom Document<BR>
173:             * @param inDocumentToSearch XML-JDOM Document  
174:             * @param  uniqueIdentifierName we can use to index the document (unique
175:             *    attribute like id or name present on the node we are searching for)
176:             * @param uniqueIdentifierToFind in the indexed document
177:             */
178:            public static Element findNode(Document inDocumentToSearch,
179:                    String uniqueIdentifierName, String uniqueIdentifierToFind) {
180:
181:                // index document                        
182:                HashMap index = getNodeIndex(inDocumentToSearch,
183:                        uniqueIdentifierName);
184:
185:                // Now get required element from index
186:                return (Element) index.get(uniqueIdentifierToFind);
187:
188:            }
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.