Source Code Cross Referenced for XmlUtils.java in  » J2EE » Pustefix » de » schlund » pfixcore » util » basicapp » helper » 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 » Pustefix » de.schlund.pfixcore.util.basicapp.helper 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of PFIXCORE.
003:         *
004:         * PFIXCORE is free software; you can redistribute it and/or modify
005:         * it under the terms of the GNU Lesser General Public License as published by
006:         * the Free Software Foundation; either version 2 of the License, or
007:         * (at your option) any later version.
008:         *
009:         * PFIXCORE is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         * GNU Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public License
015:         * along with PFIXCORE; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         *
018:         */
019:
020:        package de.schlund.pfixcore.util.basicapp.helper;
021:
022:        import org.w3c.dom.Document;
023:        import org.w3c.dom.Element;
024:        import org.w3c.dom.Node;
025:        import org.w3c.dom.NodeList;
026:
027:        /**
028:         * Like @see de.schlund.pfixcore.util.basicapp.helper.StringUtils 
029:         * there also exists a XmlUtils Object with static methods 
030:         * (it's this one ;o) to convert the current dom 
031:         * 
032:         * @author <a href="mailto:rapude@schlund.de">Ralf Rapude</a>
033:         * @version $Id: XmlUtils.java 1089 2004-06-07 14:04:39Z rrapude $
034:         */
035:        public class XmlUtils {
036:
037:            /**
038:             * Changing the attribute of a document in order to apply
039:             * the changes made by the user
040:             * @param domDoc The current document
041:             * @param tagName The name of the tag changing the related attribute
042:             * @param attribute The attribtute to change
043:             * @param secNodeListItem TODO
044:             * @param docName The name of the document in order to
045:             * avoid problems if a node occurs in different files with the
046:             * same name
047:             */
048:            public static Document changeAttributes(Document domDoc,
049:                    String tagName, String attribute, String newValue,
050:                    boolean secNodeListItem) {
051:                System.out.println("Changing the attribute " + attribute);
052:
053:                NodeList nodeList = domDoc.getElementsByTagName(tagName);
054:                String myNodeName = null;
055:                Element element = null;
056:
057:                if (!secNodeListItem) {
058:
059:                    for (int i = 0; i < nodeList.getLength(); i++) {
060:                        element = (Element) nodeList.item(i);
061:                        myNodeName = element.getNodeName();
062:
063:                        if (myNodeName.equals(tagName)) {
064:                            element.setAttribute(attribute, newValue);
065:                        }
066:                    }
067:                } else {
068:                    element = (Element) nodeList.item(1);
069:                    element.setAttribute(attribute, newValue);
070:                }
071:
072:                System.out.println("Changing attribute has been successfull");
073:                return domDoc;
074:            }
075:
076:            /**
077:             * Changing the text nodes of the config files
078:             * @param domDoc a Document containing the dom
079:             * @param tagName the tag to change
080:             * @param value The nodes new content
081:             */
082:            public static Document changeTextValues(Document domDoc,
083:                    String tagName, String value, boolean firstChild) {
084:                System.out.println("Changing the value of the tag " + tagName);
085:
086:                NodeList nodeList = domDoc.getElementsByTagName(tagName);
087:                String myNodeName = null;
088:                Node oldValue = null;
089:                Node newValue = domDoc.createTextNode(value);
090:
091:                // running through the doms nodes
092:                for (int i = 0; i < nodeList.getLength(); i++) {
093:                    Element element = (Element) nodeList.item(i);
094:                    myNodeName = element.getNodeName();
095:
096:                    // pick the right one out
097:                    if (myNodeName.equals(tagName)) {
098:                        // firstChild is a boolean given as an argument
099:                        if (firstChild) {
100:                            if (element.getFirstChild() != null) {
101:                                oldValue = element.getFirstChild();
102:                            } else {
103:                                oldValue = element.getNextSibling();
104:                            }
105:                        } else {
106:                            oldValue = element.getLastChild();
107:                        }
108:                        element.replaceChild(newValue, oldValue);
109:                    }
110:
111:                }
112:                System.out.println("Changing Textnode has been successfull\n");
113:                return domDoc;
114:            }
115:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.