Source Code Cross Referenced for XmlUtil.java in  » Workflow-Engines » jbpm-jpdl-3.2.2 » org » jbpm » 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 » Workflow Engines » jbpm jpdl 3.2.2 » org.jbpm.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source
003:         * Copyright 2005, JBoss Inc., and individual contributors as indicated
004:         * by the @authors tag. See the copyright.txt in the distribution for a
005:         * full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
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 GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jbpm.util;
023:
024:        import java.io.ByteArrayInputStream;
025:        import java.io.InputStream;
026:        import java.io.PrintWriter;
027:        import java.io.StringWriter;
028:        import java.util.ArrayList;
029:        import java.util.Iterator;
030:        import java.util.List;
031:
032:        import javax.xml.parsers.DocumentBuilder;
033:        import javax.xml.parsers.DocumentBuilderFactory;
034:        import javax.xml.parsers.FactoryConfigurationError;
035:        import javax.xml.parsers.ParserConfigurationException;
036:        import javax.xml.transform.Result;
037:        import javax.xml.transform.Source;
038:        import javax.xml.transform.Transformer;
039:        import javax.xml.transform.TransformerFactory;
040:        import javax.xml.transform.dom.DOMSource;
041:        import javax.xml.transform.stream.StreamResult;
042:
043:        import org.w3c.dom.CharacterData;
044:        import org.w3c.dom.Document;
045:        import org.w3c.dom.Element;
046:        import org.w3c.dom.Node;
047:        import org.w3c.dom.NodeList;
048:        import org.xml.sax.InputSource;
049:
050:        public abstract class XmlUtil {
051:
052:            public static Document parseXmlText(String xml) {
053:                ByteArrayInputStream bais = new ByteArrayInputStream(xml
054:                        .getBytes());
055:                return parseXmlInputSource(new InputSource(bais));
056:            }
057:
058:            public static Document parseXmlResource(String resource) {
059:                InputStream inputStream = ClassLoaderUtil.getStream(resource);
060:                InputSource inputSource = new InputSource(inputStream);
061:                return parseXmlInputSource(inputSource);
062:            }
063:
064:            public static Document parseXmlInputStream(InputStream inputStream) {
065:                Document document = null;
066:                try {
067:                    document = getDocumentBuilder().parse(inputStream);
068:                } catch (Exception e) {
069:                    throw new XmlException("couldn't parse xml", e);
070:                }
071:                return document;
072:            }
073:
074:            public static Document parseXmlInputSource(InputSource inputSource) {
075:                Document document = null;
076:                try {
077:                    document = getDocumentBuilder().parse(inputSource);
078:                } catch (Exception e) {
079:                    throw new XmlException("couldn't parse xml", e);
080:                }
081:                return document;
082:            }
083:
084:            public static DocumentBuilder getDocumentBuilder()
085:                    throws FactoryConfigurationError,
086:                    ParserConfigurationException {
087:                DocumentBuilderFactory factory = DocumentBuilderFactory
088:                        .newInstance();
089:                return factory.newDocumentBuilder();
090:            }
091:
092:            public static Iterator elementIterator(Element element,
093:                    String tagName) {
094:                return elements(element, tagName).iterator();
095:            }
096:
097:            public static List elements(Element element, String tagName) {
098:                NodeList nodeList = element.getElementsByTagName(tagName);
099:                List elements = new ArrayList(nodeList.getLength());
100:                for (int i = 0; i < nodeList.getLength(); i++) {
101:                    Node child = nodeList.item(i);
102:                    if (child.getParentNode() == element) {
103:                        elements.add(child);
104:                    }
105:                }
106:                return elements;
107:            }
108:
109:            public static Element element(Element element, String name) {
110:                Element childElement = null;
111:                NodeList nodeList = element.getElementsByTagName(name);
112:                if (nodeList.getLength() > 0) {
113:                    childElement = (Element) nodeList.item(0);
114:                }
115:                return childElement;
116:            }
117:
118:            public static Iterator elementIterator(Element element) {
119:                return elements(element).iterator();
120:            }
121:
122:            public static List elements(Element element) {
123:                List elements = new ArrayList();
124:                NodeList nodeList = element.getChildNodes();
125:                for (int i = 0; i < nodeList.getLength(); i++) {
126:                    Node node = nodeList.item(i);
127:                    if ((node instanceof  Element)
128:                            && (element == node.getParentNode())) {
129:                        elements.add(node);
130:                    }
131:                }
132:                return elements;
133:            }
134:
135:            public static Element element(Element element) {
136:                Element onlyChild = null;
137:                List elements = elements(element);
138:                if (!elements.isEmpty()) {
139:                    onlyChild = (Element) elements.get(0);
140:                }
141:                return onlyChild;
142:            }
143:
144:            public static String toString(Element element) {
145:                if (element == null)
146:                    return "null";
147:
148:                Source source = new DOMSource(element);
149:
150:                StringWriter stringWriter = new StringWriter();
151:                PrintWriter printWriter = new PrintWriter(stringWriter);
152:                Result result = new StreamResult(printWriter);
153:
154:                try {
155:                    Transformer transformer = TransformerFactory.newInstance()
156:                            .newTransformer();
157:                    transformer.transform(source, result);
158:                } catch (Exception e) {
159:                    throw new XmlException("couldn't write element '"
160:                            + element.getTagName() + "' to string", e);
161:                }
162:
163:                printWriter.close();
164:
165:                return stringWriter.toString();
166:            }
167:
168:            public static String getContentText(Element element) {
169:                StringBuffer buffer = new StringBuffer();
170:                NodeList nodeList = element.getChildNodes();
171:                for (int i = 0; i < nodeList.getLength(); i++) {
172:                    Node node = nodeList.item(i);
173:                    if (node instanceof  CharacterData) {
174:                        CharacterData characterData = (CharacterData) node;
175:                        buffer.append(characterData.getData());
176:                    }
177:                }
178:                return buffer.toString();
179:            }
180:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.