Source Code Cross Referenced for Util.java in  » Workflow-Engines » obe-1.0 » org » obe » xpdl » parser » dom4j » 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 » obe 1.0 » org.obe.xpdl.parser.dom4j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*--
002:
003:         Copyright (C) 2002-2005 Adrian Price.
004:         All rights reserved.
005:
006:         Redistribution and use in source and binary forms, with or without
007:         modification, are permitted provided that the following conditions
008:         are met:
009:
010:         1. Redistributions of source code must retain the above copyright
011:            notice, this list of conditions, and the following disclaimer.
012:
013:         2. Redistributions in binary form must reproduce the above copyright
014:            notice, this list of conditions, and the disclaimer that follows
015:            these conditions in the documentation and/or other materials
016:            provided with the distribution.
017:
018:         3. The names "OBE" and "Open Business Engine" must not be used to
019:         	endorse or promote products derived from this software without prior
020:         	written permission.  For written permission, please contact
021:         	adrianprice@sourceforge.net.
022:
023:         4. Products derived from this software may not be called "OBE" or
024:         	"Open Business Engine", nor may "OBE" or "Open Business Engine"
025:         	appear in their name, without prior written permission from
026:         	Adrian Price (adrianprice@users.sourceforge.net).
027:
028:         THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
029:         WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
030:         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
031:         DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
032:         INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
033:         (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
034:         SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
035:         HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
036:         STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
037:         IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
038:         POSSIBILITY OF SUCH DAMAGE.
039:
040:         For more information on OBE, please see
041:         <http://obe.sourceforge.net/>.
042:
043:         */
044:
045:        package org.obe.xpdl.parser.dom4j;
046:
047:        import org.dom4j.Element;
048:        import org.dom4j.QName;
049:        import org.dom4j.io.OutputFormat;
050:        import org.dom4j.io.XMLWriter;
051:        import org.obe.util.DateUtilities;
052:        import org.obe.xpdl.model.misc.Duration;
053:        import org.obe.xpdl.model.misc.DurationUnit;
054:        import org.obe.xpdl.parser.XPDLParserException;
055:
056:        import java.io.IOException;
057:        import java.io.StringWriter;
058:        import java.net.MalformedURLException;
059:        import java.net.URL;
060:        import java.text.ParseException;
061:        import java.util.Date;
062:        import java.util.List;
063:
064:        public class Util {
065:            /**
066:             * Return the child element with the given name.  The element must be in the
067:             * same name space as the parent element.
068:             *
069:             * @param element The parent element
070:             * @param name    The child element name
071:             * @return The child element
072:             */
073:            public static Element child(Element element, String name) {
074:                // Now that we're using a default namespace, none of the XPDL elements
075:                // have a qualified name.
076:                //        return element.element(new QName(name, element.getNamespace()));
077:                return element.element(name);
078:            }
079:
080:            /**
081:             * Return the child elements with the given name.  The elements must be in
082:             * the same name space as the parent element.
083:             *
084:             * @param element The parent element
085:             * @param name    The child element name
086:             * @return The child elements
087:             */
088:            public static List children(Element element, String name) {
089:                // Now that we're using a default namespace, none of the XPDL elements
090:                // have a qualified name.
091:                //        return element.elements(new QName(name, element.getNamespace()));
092:                return element.elements(name);
093:            }
094:
095:            /**
096:             * Detaches an element from its parent and returns a child node.
097:             *
098:             * @param element The element to detach.
099:             * @param qname   The qualified name of the child element to return.
100:             * @return The child element.
101:             */
102:            public static Element detach(Element element, QName qname) {
103:                element.detach();
104:                return element.element(qname);
105:            }
106:
107:            // Conversion
108:
109:            /**
110:             * Return the value of the child element with the given name.  The element
111:             * must be in the same name space as the parent element.
112:             *
113:             * @param element The parent element
114:             * @param name    The child element name
115:             * @return The child element value
116:             */
117:            public static String elementAsString(Element element, String name) {
118:                String s = element.elementTextTrim(new QName(name, element
119:                        .getNamespace()));
120:                return s == null || s.length() == 0 ? null : s;
121:            }
122:
123:            public static Date elementAsDate(Element element, String name)
124:                    throws XPDLParserException {
125:
126:                String text = elementAsString(element, name);
127:                if (text == null)
128:                    return null;
129:
130:                try {
131:                    return DateUtilities.getInstance().parse(text);
132:                } catch (ParseException e) {
133:                    throw new XPDLParserException(
134:                            "Error parsing date: " + text, e);
135:                }
136:            }
137:
138:            public static int elementAsInteger(Element element, String name) {
139:                String text = elementAsString(element, name);
140:                if (text == null)
141:                    return 0;
142:
143:                return Integer.parseInt(text);
144:            }
145:
146:            public static boolean elementAsBoolean(Element element, String name) {
147:                String text = elementAsString(element, name);
148:                if (text == null)
149:                    return false;
150:
151:                return Boolean.valueOf(text).booleanValue();
152:            }
153:
154:            public static URL elementAsURL(Element element, String name)
155:                    throws XPDLParserException {
156:
157:                String text = elementAsString(element, name);
158:                if (text == null)
159:                    return null;
160:
161:                try {
162:                    return new URL(text);
163:                } catch (MalformedURLException e) {
164:                    throw new XPDLParserException("Invalid URL: " + text, e);
165:                }
166:            }
167:
168:            public static Duration elementAsDuration(Element element,
169:                    String name) throws XPDLParserException {
170:
171:                String text = elementAsString(element, name);
172:                if (text == null)
173:                    return null;
174:
175:                try {
176:                    return Duration.valueOf(text);
177:                } catch (NumberFormatException e) {
178:                    throw new XPDLParserException("Error parsing duration", e);
179:                }
180:            }
181:
182:            public static DurationUnit elementAsDurationUnit(Element element,
183:                    String name) throws XPDLParserException {
184:
185:                String text = elementAsString(element, name);
186:                if (text == null)
187:                    return null;
188:
189:                try {
190:                    return DurationUnit.valueOf(text);
191:                } catch (NumberFormatException e) {
192:                    throw new XPDLParserException(
193:                            "Error parsing duration unit", e);
194:                }
195:            }
196:
197:            public static String exportToText(Element element)
198:                    throws XPDLParserException {
199:
200:                StringWriter out = new StringWriter();
201:                OutputFormat format = new OutputFormat("    ", true);
202:                format.setTrimText(true);
203:                XMLWriter writer = new XMLWriter(out, format);
204:                try {
205:                    writer.write(element);
206:                } catch (IOException e) {
207:                    throw new XPDLParserException(e);
208:                }
209:                out.flush();
210:                return out.toString();
211:            }
212:
213:            private Util() {
214:            }
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.