Source Code Cross Referenced for XMLFragment.java in  » Build » ANT » org » apache » tools » ant » 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 » Build » ANT » org.apache.tools.ant.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:
019:        package org.apache.tools.ant.util;
020:
021:        import org.w3c.dom.Document;
022:        import org.w3c.dom.DocumentFragment;
023:        import org.w3c.dom.Element;
024:        import org.w3c.dom.Node;
025:        import org.w3c.dom.Text;
026:
027:        import org.apache.tools.ant.DynamicElementNS;
028:        import org.apache.tools.ant.ProjectComponent;
029:        import org.apache.tools.ant.DynamicConfiguratorNS;
030:
031:        /**
032:         * Use this class as a nested element if you want to get a literal DOM
033:         * fragment of something nested into your task/type.
034:         *
035:         * <p>This is useful for tasks that want to deal with the "real" XML
036:         * from the build file instead of objects.</p>
037:         *
038:         * <p>Code heavily influenced by code written by Dominique Devienne.</p>
039:         *
040:         * @since Ant 1.7
041:         */
042:        public class XMLFragment extends ProjectComponent implements 
043:                DynamicElementNS {
044:
045:            private Document doc;
046:            private DocumentFragment fragment;
047:
048:            /**
049:             * Constructor for XMLFragment object.
050:             */
051:            public XMLFragment() {
052:                doc = JAXPUtils.getDocumentBuilder().newDocument();
053:                fragment = doc.createDocumentFragment();
054:            }
055:
056:            /**
057:             * @return the DocumentFragment that corresponds to the nested
058:             *          structure.
059:             */
060:            public DocumentFragment getFragment() {
061:                return fragment;
062:            }
063:
064:            /**
065:             * Add nested text, expanding properties as we go
066:             * @param s the text to add
067:             */
068:            public void addText(String s) {
069:                addText(fragment, s);
070:            }
071:
072:            /**
073:             * Creates a nested element.
074:             * @param uri the uri of the nested element
075:             * @param name the localname of the nested element
076:             * @param qName the qualified name of the nested element
077:             * @return an object that the element is applied to
078:             */
079:            public Object createDynamicElement(String uri, String name,
080:                    String qName) {
081:                Element e = null;
082:                if (uri.equals("")) {
083:                    e = doc.createElement(name);
084:                } else {
085:                    e = doc.createElementNS(uri, qName);
086:                }
087:                fragment.appendChild(e);
088:                return new Child(e);
089:            }
090:
091:            /**
092:             * Add text to a node.
093:             * @param n node
094:             * @param s value
095:             */
096:            private void addText(Node n, String s) {
097:                s = getProject().replaceProperties(s);
098:                //only text nodes that are non null after property expansion are added
099:                if (s != null && !s.trim().equals("")) {
100:                    Text t = doc.createTextNode(s.trim());
101:                    n.appendChild(t);
102:                }
103:            }
104:
105:            /**
106:             * An object to handle (recursively) nested elements.
107:             */
108:            public class Child implements  DynamicConfiguratorNS {
109:                private Element e;
110:
111:                Child(Element e) {
112:                    this .e = e;
113:                }
114:
115:                /**
116:                 * Add nested text.
117:                 * @param s the text to add
118:                 */
119:                public void addText(String s) {
120:                    XMLFragment.this .addText(e, s);
121:                }
122:
123:                /**
124:                 * Sets the attribute
125:                 * @param uri the uri of the attribute
126:                 * @param name the localname of the attribute
127:                 * @param qName the qualified name of the attribute
128:                 * @param value the value of the attribute
129:                 */
130:                public void setDynamicAttribute(String uri, String name,
131:                        String qName, String value) {
132:                    if (uri.equals("")) {
133:                        e.setAttribute(name, value);
134:                    } else {
135:                        e.setAttributeNS(uri, qName, value);
136:                    }
137:                }
138:
139:                /**
140:                 * Creates a nested element.
141:                 * @param uri the uri of the nested element
142:                 * @param name the localname of the nested element
143:                 * @param qName the qualified name of the nested element
144:                 * @return an object that the element is applied to
145:                 */
146:                public Object createDynamicElement(String uri, String name,
147:                        String qName) {
148:                    Element e2 = null;
149:                    if (uri.equals("")) {
150:                        e2 = doc.createElement(name);
151:                    } else {
152:                        e2 = doc.createElementNS(uri, qName);
153:                    }
154:                    e.appendChild(e2);
155:                    return new Child(e2);
156:                }
157:            }
158:
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.