Source Code Cross Referenced for Util.java in  » Workflow-Engines » obe-1.0 » org » obe » xpdl » serializer » 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.serializer.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.serializer.dom4j;
046:
047:        import org.dom4j.*;
048:        import org.dom4j.io.SAXReader;
049:        import org.obe.util.DateUtilities;
050:        import org.obe.xpdl.model.misc.Duration;
051:        import org.obe.xpdl.parser.dom4j.DOM4JNames;
052:
053:        import java.io.StringReader;
054:        import java.net.URL;
055:        import java.util.Date;
056:        import java.util.List;
057:
058:        /**
059:         * Dom4J XPDL Serializer utility class.
060:         *
061:         * @author Anthony Eden
062:         * @author Adrian Price
063:         */
064:        final class Util {
065:            /**
066:             * Adds a child element with the specific name to the given parent element
067:             * and returns the child element.  This method will use the namespace of the
068:             * parent element for the child element's namespace.
069:             *
070:             * @param parent The parent element
071:             * @param name   The new child element name
072:             * @return The child element
073:             */
074:            static Element addElement(Element parent, String name) {
075:                //        Namespace namespace = parent.getNamespace();
076:                //        return namespace == Namespace.NO_NAMESPACE
077:                //            ? parent.addElement(name)
078:                //            : parent.addElement(new QName(name, namespace));
079:                return parent.addElement(name);
080:            }
081:
082:            /**
083:             * Adds a child element with the specific name and the given value to the
084:             * given parent element and returns the child element.  This method will use
085:             * the namespace of the parent element for the child element's namespace.
086:             *
087:             * @param parent The parent element
088:             * @param name   The new child element name
089:             * @param value  The value
090:             * @return The child element
091:             */
092:            static Element addElement(Element parent, String name, Date value) {
093:                return addElement(parent, name, value, null);
094:            }
095:
096:            /**
097:             * Adds a child element with the specific name and the given value to the
098:             * given parent element and returns the child element.  This method will use
099:             * the namespace of the parent element for the child element's namespace.
100:             * If the given value is null then the default value is used.  If the value
101:             * is null then this method will not add the child element and will return
102:             * null.
103:             *
104:             * @param parent       The parent element
105:             * @param name         The new child element name
106:             * @param value        The value
107:             * @param defaultValue The default value (if the value is null)
108:             * @return The child element
109:             */
110:            static Element addElement(Element parent, String name, Date value,
111:                    Date defaultValue) {
112:
113:                Element child = null;
114:
115:                if (value == null)
116:                    value = defaultValue;
117:
118:                if (value != null) {
119:                    child = addElement(parent, name);
120:                    child.addText(DateUtilities.getInstance().format(value));
121:                }
122:
123:                return child;
124:            }
125:
126:            /**
127:             * Adds a child element with the specific name and the given value to the
128:             * given parent element and returns the child element.  This method will use
129:             * the namespace of the parent element for the child element's namespace.
130:             *
131:             * @param parent The parent element
132:             * @param name   The new child element name
133:             * @param value  The value
134:             * @return The child element
135:             */
136:            static Element addElement(Element parent, String name, String value) {
137:                return addElement(parent, name, value, null);
138:            }
139:
140:            /**
141:             * Adds a child element with the specific name and the given value to the
142:             * given parent element and returns the child element.  This method will use
143:             * the namespace of the parent element for the child element's namespace.
144:             * If the given value is null then the default value is used.  If the value
145:             * is null then this method will not add the child element and will return
146:             * null.
147:             *
148:             * @param parent       The parent element
149:             * @param name         The new child element name
150:             * @param value        The value
151:             * @param defaultValue The default value (if the value is null)
152:             * @return The child element
153:             */
154:            static Element addElement(Element parent, String name,
155:                    String value, String defaultValue) {
156:
157:                Element child = null;
158:
159:                if (value == null)
160:                    value = defaultValue;
161:
162:                if (value != null) {
163:                    child = addElement(parent, name);
164:                    child.addText(value);
165:                }
166:
167:                return child;
168:            }
169:
170:            /**
171:             * Adds a child element with the specific name and the given value to the
172:             * given parent element and returns the child element.  This method will use
173:             * the namespace of the parent element for the child element's namespace.
174:             *
175:             * @param parent The parent element
176:             * @param name   The new child element name
177:             * @param value  The value
178:             * @return The child element
179:             */
180:            static Element addElement(Element parent, String name, URL value) {
181:                return addElement(parent, name, value, null);
182:            }
183:
184:            /**
185:             * Adds a child element with the specific name and the given value to the
186:             * given parent element and returns the child element.  This method will use
187:             * the namespace of the parent element for the child element's namespace.
188:             * If the given value is null then the default value is used.  If the value
189:             * is null then this method will not add the child element and will return
190:             * null.
191:             *
192:             * @param parent       The parent element
193:             * @param name         The new child element name
194:             * @param value        The value
195:             * @param defaultValue The default value (if the value is null)
196:             * @return The child element
197:             */
198:            static Element addElement(Element parent, String name, URL value,
199:                    URL defaultValue) {
200:                Element child = null;
201:
202:                if (value == null)
203:                    value = defaultValue;
204:
205:                if (value != null) {
206:                    child = addElement(parent, name);
207:                    child.addText(value.toString());
208:                }
209:
210:                return child;
211:            }
212:
213:            /**
214:             * Adds a child element with the specific name and the given value to the
215:             * given parent element and returns the child element.  This method will use
216:             * the namespace of the parent element for the child element's namespace.
217:             *
218:             * @param parent The parent element
219:             * @param name   The new child element name
220:             * @param value  The value
221:             * @return The child element
222:             */
223:            static Element addElement(Element parent, String name,
224:                    Duration value) {
225:                return addElement(parent, name, value, null);
226:            }
227:
228:            /**
229:             * Adds a child element with the specific name and the given value to the
230:             * given parent element and returns the child element.  This method will use
231:             * the namespace of the parent element for the child element's namespace.
232:             * If the given value is null then the default value is used.  If the value
233:             * is null then this method will not add the child element and will return
234:             * null.
235:             *
236:             * @param parent       The parent element
237:             * @param name         The new child element name
238:             * @param value        The value
239:             * @param defaultValue The default value (if the value is null)
240:             * @return The child element
241:             */
242:            static Element addElement(Element parent, String name,
243:                    Duration value, Duration defaultValue) {
244:                Element child = null;
245:
246:                if (value == null)
247:                    value = defaultValue;
248:
249:                if (value != null) {
250:                    child = addElement(parent, name);
251:                    child.addText(value.toString());
252:                }
253:
254:                return child;
255:            }
256:
257:            static void importFromText(String text, Element parent)
258:                    throws DocumentException {
259:
260:                if (text == null || text.length() == 0)
261:                    return;
262:
263:                SAXReader reader = new SAXReader(DocumentFactory.getInstance());
264:                reader.setStripWhitespaceText(true);
265:                reader.setMergeAdjacentText(true);
266:                Document document = reader.read(new StringReader(text));
267:                Element docElem = document.getRootElement();
268:                Namespace ns = docElem.getNamespace();
269:                normalizeNSPrefix(docElem,
270:                        ns == Namespace.NO_NAMESPACE ? DOM4JNames.XPDL_NS : ns);
271:                parent.add(docElem.detach());
272:            }
273:
274:            static void normalizeNSPrefix(Element elem, Namespace ns) {
275:                Namespace elemNS = elem.getNamespace();
276:                /*if (elemNS.equals(ns))
277:                    elem.setQName(new QName(elem.getName(), ns));
278:                else*/
279:                if (!elemNS.equals(ns)
280:                        && elem.getNamespaceURI().equals(ns.getURI())) {
281:
282:                    elem.setQName(new QName(elem.getName(), ns));
283:                }
284:                List children = elem.elements();
285:                for (int i = 0; i < children.size(); i++) {
286:                    Element child = (Element) children.get(i);
287:                    normalizeNSPrefix(child, ns);
288:                }
289:            }
290:
291:            private Util() {
292:            }
293:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.