Source Code Cross Referenced for DomParseUtils.java in  » Database-JDBC-Connection-Pool » c3p0 » com » mchange » v1 » xml » 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 » Database JDBC Connection Pool » c3p0 » com.mchange.v1.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Distributed as part of c3p0 v.0.9.1.2
003:         *
004:         * Copyright (C) 2005 Machinery For Change, Inc.
005:         *
006:         * Author: Steve Waldman <swaldman@mchange.com>
007:         *
008:         * This library is free software; you can redistribute it and/or modify
009:         * it under the terms of the GNU Lesser General Public License version 2.1, as 
010:         * published by the Free Software Foundation.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         * GNU Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public License
018:         * along with this software; see the file LICENSE.  If not, write to the
019:         * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020:         * Boston, MA 02111-1307, USA.
021:         */
022:
023:        package com.mchange.v1.xml;
024:
025:        import java.util.*;
026:        import org.xml.sax.*;
027:        import org.w3c.dom.*;
028:        import com.mchange.v1.util.DebugUtils;
029:
030:        public final class DomParseUtils {
031:            final static boolean DEBUG = true;
032:
033:            /**
034:             * @return null if child doesn't exist.
035:             */
036:            public static String allTextFromUniqueChild(Element elem,
037:                    String childTagName) throws DOMException {
038:                return allTextFromUniqueChild(elem, childTagName, false);
039:            }
040:
041:            /**
042:             * @return null if child doesn't exist.
043:             */
044:            public static String allTextFromUniqueChild(Element elem,
045:                    String childTagName, boolean trim) throws DOMException {
046:                Element uniqueChild = uniqueChildByTagName(elem, childTagName);
047:                if (uniqueChild == null)
048:                    return null;
049:                else
050:                    return DomParseUtils.allTextFromElement(uniqueChild, trim);
051:            }
052:
053:            public static Element uniqueChild(Element elem, String childTagName)
054:                    throws DOMException {
055:                return uniqueChildByTagName(elem, childTagName);
056:            }
057:
058:            /**
059:             * @deprecated use uniqueChild(Element elem, String childTagName)
060:             */
061:            public static Element uniqueChildByTagName(Element elem,
062:                    String childTagName) throws DOMException {
063:                NodeList nl = elem.getElementsByTagName(childTagName);
064:                int len = nl.getLength();
065:                if (DEBUG)
066:                    DebugUtils.myAssert(len <= 1, "There is more than one ("
067:                            + len + ") child with tag name: " + childTagName
068:                            + "!!!");
069:                return (len == 1 ? (Element) nl.item(0) : null);
070:            }
071:
072:            public static String allText(Element elem) throws DOMException {
073:                return allTextFromElement(elem);
074:            }
075:
076:            public static String allText(Element elem, boolean trim)
077:                    throws DOMException {
078:                return allTextFromElement(elem, trim);
079:            }
080:
081:            /** @deprecated use allText(Element elem) */
082:            public static String allTextFromElement(Element elem)
083:                    throws DOMException {
084:                return allTextFromElement(elem, false);
085:            }
086:
087:            /** @deprecated use allText(Element elem, boolean trim) */
088:            public static String allTextFromElement(Element elem, boolean trim)
089:                    throws DOMException {
090:                StringBuffer textBuf = new StringBuffer();
091:                NodeList nl = elem.getChildNodes();
092:                for (int j = 0, len = nl.getLength(); j < len; ++j) {
093:                    Node node = nl.item(j);
094:                    if (node instanceof  Text) //includes Text and CDATA!
095:                        textBuf.append(node.getNodeValue());
096:                }
097:                String out = textBuf.toString();
098:                return (trim ? out.trim() : out);
099:            }
100:
101:            public static String[] allTextFromImmediateChildElements(
102:                    Element parent, String tagName) throws DOMException {
103:                return allTextFromImmediateChildElements(parent, tagName, false);
104:            }
105:
106:            public static String[] allTextFromImmediateChildElements(
107:                    Element parent, String tagName, boolean trim)
108:                    throws DOMException {
109:                NodeList nl = immediateChildElementsByTagName(parent, tagName);
110:                int len = nl.getLength();
111:                String[] out = new String[len];
112:                for (int i = 0; i < len; ++i)
113:                    out[i] = allText((Element) nl.item(i), trim);
114:                return out;
115:            }
116:
117:            public static NodeList immediateChildElementsByTagName(
118:                    Element parent, String tagName) throws DOMException {
119:                return getImmediateChildElementsByTagName(parent, tagName);
120:            }
121:
122:            /**
123:             * @deprecated use immediateChildrenByTagName( Element parent, String tagName )
124:             */
125:            public static NodeList getImmediateChildElementsByTagName(
126:                    Element parent, String tagName) throws DOMException {
127:                final List nodes = new ArrayList();
128:                for (Node child = parent.getFirstChild(); child != null; child = child
129:                        .getNextSibling())
130:                    if (child instanceof  Element
131:                            && ((Element) child).getTagName().equals(tagName))
132:                        nodes.add(child);
133:                return new NodeList() {
134:                    public int getLength() {
135:                        return nodes.size();
136:                    }
137:
138:                    public Node item(int i) {
139:                        return (Node) nodes.get(i);
140:                    }
141:                };
142:            }
143:
144:            public static String allTextFromUniqueImmediateChild(Element elem,
145:                    String childTagName) throws DOMException {
146:                Element uniqueChild = uniqueImmediateChildByTagName(elem,
147:                        childTagName);
148:                if (uniqueChild == null)
149:                    return null;
150:                return DomParseUtils.allTextFromElement(uniqueChild);
151:            }
152:
153:            public static Element uniqueImmediateChild(Element elem,
154:                    String childTagName) throws DOMException {
155:                return uniqueImmediateChildByTagName(elem, childTagName);
156:            }
157:
158:            /**
159:             * @deprecated use uniqueImmediateChild(Element elem, String childTagName) 
160:             */
161:            public static Element uniqueImmediateChildByTagName(Element elem,
162:                    String childTagName) throws DOMException {
163:                NodeList nl = getImmediateChildElementsByTagName(elem,
164:                        childTagName);
165:                int len = nl.getLength();
166:                if (DEBUG)
167:                    DebugUtils.myAssert(len <= 1, "There is more than one ("
168:                            + len + ") child with tag name: " + childTagName
169:                            + "!!!");
170:                return (len == 1 ? (Element) nl.item(0) : null);
171:            }
172:
173:            /**
174:             * @deprecated use Element.getAttribute(String val)
175:             */
176:            public static String attrValFromElement(Element element,
177:                    String attrName) throws DOMException {
178:                Attr attr = element.getAttributeNode(attrName);
179:                return (attr == null ? null : attr.getValue());
180:            }
181:
182:            private DomParseUtils() {
183:            }
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.