Source Code Cross Referenced for AntXMLUtil.java in  » J2EE » enhydra-IDE-plugin » org » enhydra » kelp » ant » 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 » J2EE » enhydra IDE plugin » org.enhydra.kelp.ant 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.enhydra.kelp.ant;
002:
003:        import java.io.FileOutputStream;
004:        import org.w3c.dom.Document;
005:        import org.w3c.dom.Node;
006:        import org.w3c.dom.NodeList;
007:
008:        import org.apache.xml.serialize.OutputFormat;
009:        import org.apache.xml.serialize.XMLSerializer;
010:        import org.apache.xerces.parsers.DOMParser;
011:        import org.apache.xml.serialize.Method;
012:
013:        /**
014:         * @author Tweety
015:         *
016:         * To change this generated comment edit the template variable "typecomment":
017:         * Window>Preferences>Java>Templates.
018:         * To enable and disable the creation of type comments go to
019:         * Window>Preferences>Java>Code Generation.
020:         */
021:        public class AntXMLUtil {
022:
023:            //xml document
024:            public Document document;
025:
026:            //xml document name
027:            private String xmlFileName;
028:
029:            AntXMLUtil() throws Exception {
030:                this ("");
031:            }
032:
033:            AntXMLUtil(String fileName) throws Exception {
034:
035:                this .xmlFileName = fileName;
036:                try {
037:                    DOMParser parser = new DOMParser();
038:                    parser.parse(xmlFileName);
039:                    document = parser.getDocument();
040:
041:                } catch (Exception e) {
042:                    throw e;
043:                }
044:
045:            }
046:
047:            /*
048:             * @return Node that represents project tag
049:             */
050:            public Node getProjectNode() {
051:                NodeList list = document.getElementsByTagName("project");
052:                if (list.getLength() > 0)
053:                    return list.item(0);
054:                else
055:                    return null;
056:            }
057:
058:            /*
059:             * @param propertyName name attribute of the property tag
060:             * @return Node that represents property tag
061:             */
062:            public Node getProjectProperty(String propertyName) {
063:                Node project = this .getProjectNode();
064:                NodeList childs = project.getChildNodes();
065:                for (int i = 0; i < childs.getLength(); i++) {
066:                    if (childs.item(i).getNodeName().equals("property")) {
067:                        Node nameAttribute = childs.item(i).getAttributes()
068:                                .getNamedItem("name");
069:                        if (nameAttribute != null
070:                                && nameAttribute.getNodeValue().equals(
071:                                        propertyName))
072:                            return childs.item(i);
073:                    }
074:                }
075:                return null;
076:            }
077:
078:            /*
079:             * @param targetName: name attribute of the searched target
080:             * @return Node that represents target with given name
081:             */
082:            public Node getTargetByName(String targetName) {
083:                NodeList allTargets = document.getElementsByTagName("target");
084:                for (int i = 0; i < allTargets.getLength(); i++) {
085:                    String nameValue = allTargets.item(i).getAttributes()
086:                            .getNamedItem("name").getNodeValue();
087:
088:                    if (nameValue.equals(targetName))
089:                        return allTargets.item(i);
090:                }
091:                return null;
092:            }
093:
094:            /*
095:             * This method finds child Node in given subtree, with given name
096:             * @param subRoot: root node
097:             * @param childName: child tag name
098:             */
099:            public Node getChildByTagName(Node subRoot, String tagName) {
100:                NodeList childs = subRoot.getChildNodes();
101:                for (int i = 0; i < childs.getLength(); i++) {
102:                    if (childs.item(i).getNodeName().equals(tagName)) {
103:                        return childs.item(i);
104:                    }
105:                }
106:                return null;
107:            }
108:
109:            /*
110:             * This method finds child attribute Node in given subtree, with given name
111:             * @param subRoot: root node
112:             * @param attributeName: name of attribute
113:             */
114:            public Node getAttributeByName(Node subRoot, String attributeName) {
115:                return subRoot.getAttributes().getNamedItem(attributeName);
116:            }
117:
118:            /*
119:             * This method finds patternset Node with given id
120:             * @param id: id of searched patternset
121:             */
122:            public Node getPatternsetById(String id) {
123:                Node projectNode = this .getProjectNode();
124:                NodeList childs = projectNode.getChildNodes();
125:                for (int i = 0; i < childs.getLength(); i++) {
126:                    if (childs.item(i).getNodeName().equals("patternset")) {
127:                        if (childs.item(i).getAttributes().getNamedItem("id")
128:                                .getNodeValue().equals(id))
129:                            return childs.item(i);
130:                    }
131:                }
132:
133:                return null;
134:            }
135:
136:            /*
137:             * This method finds filterset Node with given id
138:             * @param id: id of searched filterset
139:             */
140:            public Node getFiltersetById(String id) {
141:                Node projectNode = this .getProjectNode();
142:                NodeList childs = projectNode.getChildNodes();
143:                for (int i = 0; i < childs.getLength(); i++) {
144:                    if (childs.item(i).getNodeName().equals("filterset")) {
145:                        if (childs.item(i).getAttributes().getNamedItem("id")
146:                                .getNodeValue().equalsIgnoreCase(id))
147:                            return childs.item(i);
148:                    }
149:                }
150:
151:                return null;
152:            }
153:
154:            public boolean saveDocument() {
155:
156:                try {
157:                    FileOutputStream os = new FileOutputStream(xmlFileName);
158:                    OutputFormat of = new OutputFormat(); //xerces apache.xml.serializer
159:                    of.setIndenting(true);
160:                    of.setIndent(4);
161:                    of.setMethod(Method.XML);
162:                    of.setPreserveSpace(true);
163:                    XMLSerializer out = new XMLSerializer(os, of);
164:                    //IOException
165:                    out.serialize(document);
166:                } catch (Exception e) {
167:                    e.printStackTrace();
168:                    return false;
169:                }
170:                return true;
171:            }
172:
173:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.