Source Code Cross Referenced for DomXml.java in  » Sevlet-Container » tomcat-connectors » org » apache » naming » util » 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 » Sevlet Container » tomcat connectors » org.apache.naming.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright 1999-2004 The Apache Software Foundation
003:         *
004:         *  Licensed under the Apache License, Version 2.0 (the "License");
005:         *  you may not use this file except in compliance with the License.
006:         *  You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         *  Unless required by applicable law or agreed to in writing, software
011:         *  distributed under the License is distributed on an "AS IS" BASIS,
012:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         *  See the License for the specific language governing permissions and
014:         *  limitations under the License.
015:         */
016:
017:        package org.apache.naming.util;
018:
019:        import java.io.File;
020:        import java.io.IOException;
021:        import java.io.StringReader;
022:
023:        import javax.xml.parsers.DocumentBuilder;
024:        import javax.xml.parsers.DocumentBuilderFactory;
025:        import javax.xml.parsers.ParserConfigurationException;
026:
027:        import org.w3c.dom.Document;
028:        import org.w3c.dom.Node;
029:        import org.xml.sax.EntityResolver;
030:        import org.xml.sax.InputSource;
031:        import org.xml.sax.SAXException;
032:
033:        // moved from jk2 config package. 
034:
035:        /**
036:         *
037:         * @author Costin Manolache
038:         */
039:        public class DomXml {
040:            String file;
041:            String name;
042:
043:            // -------------------- Settings -------------------- 
044:
045:            /** 
046:             */
047:            public void setFile(String file) {
048:                this .file = file;
049:            }
050:
051:            /** 
052:             */
053:            public void setName(String name) {
054:                this .name = name;
055:            }
056:
057:            // -------------------- Implementation --------------------
058:            Node domN;
059:
060:            /** Return the top level node
061:             */
062:            public Node getNode() {
063:                return domN;
064:            }
065:
066:            // -------------------- ant wrapper --------------------
067:
068:            public void execute() {
069:                try {
070:                    if (file == null) {
071:                        log.error("No file attribute");
072:                        return;
073:                    }
074:
075:                    File docF = new File(file);
076:
077:                    Document doc = readXml(docF);
078:                    if (doc == null)
079:                        return;
080:
081:                    domN = doc.getDocumentElement();
082:                    if (domN == null) {
083:                        log.error("Can't find the root node");
084:                        return;
085:                    }
086:
087:                } catch (Exception ex) {
088:                    ex.printStackTrace();
089:                }
090:            }
091:
092:            private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
093:                    .getLog(DomXml.class);
094:
095:            // -------------------- DOM utils --------------------
096:
097:            /** Get the content of a node
098:             */
099:            public static String getContent(Node n) {
100:                if (n == null)
101:                    return null;
102:                Node n1 = n.getFirstChild();
103:                // XXX Check if it's a text node
104:
105:                String s1 = n1.getNodeValue();
106:                return s1.trim();
107:            }
108:
109:            /** Get the first child
110:             */
111:            public static Node getChild(Node parent, String name) {
112:                if (parent == null)
113:                    return null;
114:                Node first = parent.getFirstChild();
115:                if (first == null)
116:                    return null;
117:                for (Node node = first; node != null; node = node
118:                        .getNextSibling()) {
119:                    //System.out.println("getNode: " + name + " " + node.getNodeName());
120:                    if (name.equals(node.getNodeName())) {
121:                        return node;
122:                    }
123:                }
124:                return null;
125:            }
126:
127:            /** Get the first child's content ( i.e. it's included TEXT node )
128:             */
129:            public static String getChildContent(Node parent, String name) {
130:                Node first = parent.getFirstChild();
131:                if (first == null)
132:                    return null;
133:                for (Node node = first; node != null; node = node
134:                        .getNextSibling()) {
135:                    //System.out.println("getNode: " + name + " " + node.getNodeName());
136:                    if (name.equals(node.getNodeName())) {
137:                        return getContent(node);
138:                    }
139:                }
140:                return null;
141:            }
142:
143:            /** Get the node in the list of siblings
144:             */
145:            public static Node getNext(Node current) {
146:                Node first = current.getNextSibling();
147:                String name = current.getNodeName();
148:                if (first == null)
149:                    return null;
150:                for (Node node = first; node != null; node = node
151:                        .getNextSibling()) {
152:                    //System.out.println("getNode: " + name + " " + node.getNodeName());
153:                    if (name.equals(node.getNodeName())) {
154:                        return node;
155:                    }
156:                }
157:                return null;
158:            }
159:
160:            public static class NullResolver implements  EntityResolver {
161:                public InputSource resolveEntity(String publicId,
162:                        String systemId) throws SAXException, IOException {
163:                    if (log.isTraceEnabled())
164:                        log
165:                                .trace("ResolveEntity: " + publicId + " "
166:                                        + systemId);
167:                    return new InputSource(new StringReader(""));
168:                }
169:            }
170:
171:            public void saveXml(Node n, File xmlF) {
172:
173:            }
174:
175:            public static Document readXml(File xmlF) throws SAXException,
176:                    IOException, ParserConfigurationException {
177:                if (!xmlF.exists()) {
178:                    log.error("No xml file " + xmlF);
179:                    return null;
180:                }
181:                DocumentBuilderFactory dbf = DocumentBuilderFactory
182:                        .newInstance();
183:
184:                dbf.setValidating(false);
185:                dbf.setIgnoringComments(false);
186:                dbf.setIgnoringElementContentWhitespace(true);
187:                //dbf.setCoalescing(true);
188:                //dbf.setExpandEntityReferences(true);
189:
190:                DocumentBuilder db = null;
191:                db = dbf.newDocumentBuilder();
192:                db.setEntityResolver(new NullResolver());
193:
194:                // db.setErrorHandler( new MyErrorHandler());
195:
196:                Document doc = db.parse(xmlF);
197:                return doc;
198:            }
199:
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.