Source Code Cross Referenced for OctopusXMLUtil.java in  » Database-JDBC-Connection-Pool » octopus » org » webdocwf » util » loader » 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 » Database JDBC Connection Pool » octopus » org.webdocwf.util.loader 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:          OctopusXMLUtil - Utils for reading attributes form xml tags.
003:
004:            Copyright (C) 2002-2003  Together
005:
006:            This library is free software; you can redistribute it and/or
007:            modify it under the terms of the GNU Lesser General Public
008:            License as published by the Free Software Foundation; either
009:            version 2.1 of the License, or (at your option) any later version.
010:
011:            This library is distributed in the hope that it will be useful,
012:            but WITHOUT ANY WARRANTY; without even the implied warranty of
013:            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:            Lesser General Public License for more details.
015:
016:            You should have received a copy of the GNU Lesser General Public
017:            License along with this library; if not, write to the Free Software
018:            Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:
020:         OctopusXMLUtil.java
021:         Date: 20.5.2003.
022:         @version 1.0.0
023:         @author: Zoran Milakovic zoran@prozone.co.yu
024:         */package org.webdocwf.util.loader;
025:
026:        import java.util.Vector;
027:        import org.w3c.dom.*;
028:
029:        /**
030:         * Class has utility methods.
031:         *
032:         * @author     Zoran Milakovic
033:         * @version    1.1
034:         */
035:        public class OctopusXMLUtil {
036:
037:            /**
038:             * Gets attribute values from specified tags.
039:             * @param tags NodeList of tags to check for attribute
040:             * @param attrName name of attribute
041:             * @param defaultValue defaultValue if attribute is not defined
042:             * @return vector which contains values
043:             */
044:            public static Vector getAttributeValues(NodeList tags,
045:                    String attrName, String defaultValue) {
046:                Vector vecValues = new Vector();
047:                String nodeValue = "";
048:                if (attrName != null) {
049:                    for (int i = 0; i < tags.getLength(); i++) {
050:                        NamedNodeMap attrs = tags.item(i).getAttributes();
051:                        Node nodeResult = attrs.getNamedItem(attrName);
052:                        if (nodeResult != null)
053:                            nodeValue = nodeResult.getNodeValue();
054:                        else
055:                            nodeValue = defaultValue;
056:                        vecValues.addElement(nodeValue);
057:                    }
058:                }
059:                return vecValues;
060:            }
061:
062:            /**
063:             * Method importAttributeValue reads value for strAttrName attribute in strTagName tag.
064:             * This method return this value.
065:             * @param doc Parsed import XML file.
066:             * @param strTagName The name of tag where attribute is situated.
067:             * @param strAttrName The name of tag attribute which reads input value.
068:             * @param iImportJobItem Number of ImportDefinition tag which is processed.
069:             * @return String - importing value.
070:             */
071:            public static String importAttributeValue(Document doc,
072:                    String strTagName, String strAttrName, int iImportJobItem) {
073:                String strValue = "";
074:                NodeList tagBasic = doc.getElementsByTagName(strTagName);
075:                Element docFragment = (Element) tagBasic.item(iImportJobItem);
076:                if (docFragment != null)
077:                    strValue = docFragment.getAttribute(strAttrName);
078:                return strValue;
079:            }
080:
081:            /**
082:             * Method importAttribute reads value for strAttrName attribute in strTagName tag.
083:             * This method return this value.
084:             * @param doc Parsed import XML file.
085:             * @param strTagName The name of tag where attribute is situated.
086:             * @param strAttrName The name of tag attribute which reads input value.
087:             * @param iImportJobItem Number of ImportDefinition tag which is processed.
088:             * @return String - importing value.
089:             */
090:            public static String importAttribute(Document doc,
091:                    String strTagName, String strAttrName, int iImportJobItem) {
092:                String strValue = "";
093:                NodeList tagBasic = doc
094:                        .getElementsByTagName("importDefinition");
095:                if (tagBasic.getLength() != 0) {
096:                    Element docFragment = (Element) tagBasic
097:                            .item(iImportJobItem);
098:                    //      NodeList tag = docFragment.getElementsByTagName(tagName);
099:                    //      for (int i = 0; i < tag.getLength(); i++) {
100:
101:                    tagBasic = docFragment.getElementsByTagName(strTagName);
102:                    if (tagBasic.getLength() != 0) {
103:                        docFragment = (Element) tagBasic.item(0);
104:                        if (docFragment != null)
105:                            strValue = docFragment.getAttribute(strAttrName);
106:                    }
107:                }
108:                return strValue;
109:            }
110:
111:            /**
112:             * Method importValue reads values from desired XML tag and puts them into Vector.
113:             * @param doc Parsed import XML file.
114:             * @param tagName The name of XML tag.
115:             * @param strAttrName The name of tag attribute which reads input strValue.
116:             * @param iImportJobItem Number of ImportDefinition tag which is processed.
117:             * @return Vector of importing values.
118:             */
119:            public static Vector importValue(Document doc, String tagName,
120:                    String strAttrName, int iImportJobItem) {
121:                Vector strValue = new Vector();
122:                NodeList tagBasic = doc
123:                        .getElementsByTagName("importDefinition");
124:                if (tagBasic.getLength() != 0) {
125:                    Element docFragment = (Element) tagBasic
126:                            .item(iImportJobItem);
127:                    NodeList tag = docFragment.getElementsByTagName(tagName);
128:                    for (int i = 0; i < tag.getLength(); i++) {
129:                        String nodeValue = "";
130:                        if (strAttrName != null) {
131:                            NamedNodeMap attrs = tag.item(i).getAttributes();
132:                            Node nodeResult = attrs.getNamedItem(strAttrName);
133:                            if (nodeResult != null)
134:                                nodeValue = nodeResult.getNodeValue();
135:                            strValue.addElement(nodeValue);
136:                        } else {
137:                            NodeList nodeText = tag.item(i).getChildNodes();
138:                            if (nodeText.item(0) != null) {
139:                                nodeValue = nodeText.item(0).getNodeValue();
140:                                strValue.addElement(nodeValue);
141:                            }
142:                        }
143:                    }
144:                }
145:                return strValue;
146:            }
147:
148:            /**
149:             * Method importValue reads values from desired XML tag and puts them into Vector.
150:             * @param docFragment Parsed import XML file.
151:             * @param tagName The name of XML tag.
152:             * @param strAttrName The name of tag attribute which reads input strValue.
153:             * @return Vector of importing values.
154:             */
155:            public static Vector importValueForTransform(Element docFragment,
156:                    String tagName, String strAttrName) {
157:
158:                Vector strValue = new Vector();
159:                NodeList tag = docFragment.getElementsByTagName(tagName);
160:                for (int i = 0; i < tag.getLength(); i++) {
161:                    String nodeValue = "";
162:                    if (strAttrName != null) {
163:                        NamedNodeMap attrs = tag.item(i).getAttributes();
164:                        Node nodeResult = attrs.getNamedItem(strAttrName);
165:                        if (nodeResult != null)
166:                            nodeValue = nodeResult.getNodeValue();
167:                        strValue.addElement(nodeValue);
168:                    } else {
169:                        NodeList nodeText = tag.item(i).getChildNodes();
170:                        if (nodeText.item(0) != null) {
171:                            nodeValue = nodeText.item(0).getNodeValue();
172:                            strValue.addElement(nodeValue);
173:                        }
174:                    }
175:                }
176:                return strValue;
177:            }
178:
179:            /**
180:             * Method importValue reads values from desired XML tag and puts them into Vector.
181:             * @param doc Parsed import XML file.
182:             * @param tagName The name of XML tag.
183:             * @param strAttrName The name of tag attribute which reads input strValue.
184:             * @param iImportJobItem Number of ImportDefinition tag which is processed.
185:             * @param defaultValue The default value of strattrname attribute.
186:             * @return Vector of importing values.
187:             */
188:            public static Vector importValue(Document doc, String tagName,
189:                    String strAttrName, int iImportJobItem, String defaultValue) {
190:                Vector strValue = new Vector();
191:                NodeList tagBasic = doc
192:                        .getElementsByTagName("importDefinition");
193:                if (tagBasic.getLength() != 0) {
194:                    Element docFragment = (Element) tagBasic
195:                            .item(iImportJobItem);
196:                    NodeList tag = docFragment.getElementsByTagName(tagName);
197:                    for (int i = 0; i < tag.getLength(); i++) {
198:                        String nodeValue = "";
199:                        if (strAttrName != null) {
200:                            NamedNodeMap attrs = tag.item(i).getAttributes();
201:                            Node nodeResult = attrs.getNamedItem(strAttrName);
202:                            if (nodeResult != null)
203:                                nodeValue = nodeResult.getNodeValue();
204:                            else
205:                                nodeValue = defaultValue;
206:                            strValue.addElement(nodeValue);
207:                        } else {
208:                            NodeList nodeText = tag.item(i).getChildNodes();
209:                            if (nodeText.item(0) != null) {
210:                                nodeValue = nodeText.item(0).getNodeValue();
211:                                strValue.addElement(nodeValue);
212:                            }
213:                        }
214:                    }
215:                }
216:                return strValue;
217:            }
218:
219:            /**
220:             * @return Vector of importing values.
221:             * 
222:             */
223:            //ZK change this 16.04.2004.Change Return type from Document to Element 
224:            public static Element getDocumentFragment(Document doc,
225:                    String tagName, int iCurrent, int iImportJobItem) {
226:
227:                NodeList tagBasic = doc
228:                        .getElementsByTagName("importDefinition");
229:                if (tagBasic.getLength() != 0) {
230:                    Element docFragment = (Element) tagBasic
231:                            .item(iImportJobItem);
232:                    NodeList tag = docFragment.getElementsByTagName(tagName);
233:                    if (iCurrent < tag.getLength())
234:                        return (Element) tag.item(iCurrent);
235:                    else
236:                        return null;
237:                } else
238:                    return null;
239:            }
240:
241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.