Source Code Cross Referenced for XMLUtils.java in  » Testing » sqlunit » net » sourceforge » sqlunit » utils » 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 » Testing » sqlunit » net.sourceforge.sqlunit.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: XMLUtils.java,v 1.6 2006/04/30 22:25:56 spal Exp $
003:         * $Source: /cvsroot/sqlunit/sqlunit/src/net/sourceforge/sqlunit/utils/XMLUtils.java,v $
004:         * SQLUnit - a test harness for unit testing database stored procedures.
005:         * Copyright (C) 2003  The SQLUnit Team
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License
009:         * as published by the Free Software Foundation; either version 2
010:         * of the License, or (at your option) any later version.
011:         * 
012:         * This program is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         * GNU General Public License for more details.
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020:         */
021:        package net.sourceforge.sqlunit.utils;
022:
023:        import net.sourceforge.sqlunit.HandlerFactory;
024:        import net.sourceforge.sqlunit.IHandler;
025:        import net.sourceforge.sqlunit.SymbolTable;
026:
027:        import org.apache.log4j.Logger;
028:        import org.jdom.Element;
029:        import org.jdom.output.XMLOutputter;
030:        import org.jdom.output.Format;
031:
032:        import java.io.ByteArrayOutputStream;
033:        import java.io.IOException;
034:
035:        /**
036:         * Provides commonly used functionality for methods which have to deal
037:         * with JDOM elements.
038:         * @author Sujit Pal (spal@users.sourceforge.net)
039:         * @version $Revision: 1.6 $
040:         */
041:        public final class XMLUtils {
042:
043:            private static final Logger LOG = Logger.getLogger(XMLUtils.class);
044:
045:            /**
046:             * Private Constructor. Cannot be instantiated.
047:             */
048:            private XMLUtils() {
049:                // private constructor, cannot instantiate
050:            }
051:
052:            /**
053:             * Wrapper over Element.getAttributeValue(attributeName) which tests
054:             * to see if the attributeName is a variable, if so, does another
055:             * lookup of the symbol table to return the value of the variable.
056:             * @param element the JDOM Element.
057:             * @param attribute the name of the attribute.
058:             * @return the value of the attribute, or the value for the variable
059:             * stored in the SymbolTable if the value is a variable.
060:             */
061:            public static String getAttributeValue(final Element element,
062:                    final String attribute) {
063:                LOG.debug(">> getAttributeValue(Element " + element.getName()
064:                        + "," + attribute + ")");
065:                String value = element.getAttributeValue(attribute);
066:                if (SymbolTable.isVariableName(value)) {
067:                    String symValue = SymbolTable.getValue(value);
068:                    if (symValue == null) {
069:                        return value;
070:                    } else {
071:                        return symValue;
072:                    }
073:                } else {
074:                    return value;
075:                }
076:            }
077:
078:            /**
079:             * Wrapper over Element.getText() which tests to see if the body text
080:             * returned is a variable, if so, does another lookup of the symbol
081:             * table to return the value of the variable.
082:             * @param element the JDOM Element.
083:             * @return the value of the body text, or the value for the variable
084:             * stored in the SymbolTable if the value is a variable.
085:             */
086:            public static String getText(final Element element) {
087:                LOG.debug(">> getText(Element "
088:                        + (element == null ? "NULL" : element.getName()) + ")");
089:                if (element == null) {
090:                    return null;
091:                }
092:                String text = element.getText();
093:                if (SymbolTable.isVariableName(text)) {
094:                    String symValue = SymbolTable.getValue(text);
095:                    if (symValue != null) {
096:                        return symValue;
097:                    } else {
098:                        return text;
099:                    }
100:                } else {
101:                    return text;
102:                }
103:            }
104:
105:            /**
106:             * Converts the Element to a formatted XML String.
107:             * @param element the JDOM Element.
108:             * @return a formatted XML String representing the Element.
109:             */
110:            public static String toXMLString(final Element element) {
111:                LOG.debug(">> toXMLString(Element " + element.getName() + ")");
112:                XMLOutputter outputter = new XMLOutputter(Format
113:                        .getPrettyFormat());
114:                ByteArrayOutputStream bos = new ByteArrayOutputStream();
115:                try {
116:                    outputter.output(element, bos);
117:                } catch (IOException e) {
118:                    return "** IOException from XMLUtils.toXMLString("
119:                            + element.getName() + ")";
120:                }
121:                return bos.toString();
122:            }
123:
124:            /**
125:             * Replaces all occurences of CRLF, CR and LF with a single space
126:             * and returns the trimmed result string.
127:             * @param unstripped the unstripped string.
128:             * @return the stripped string.
129:             */
130:            public static String stripCRLF(final String unstripped) {
131:                if (unstripped == null) {
132:                    return null;
133:                }
134:                return unstripped.replaceAll("\r\n", " ").replaceAll("\r", " ")
135:                        .replaceAll("\n", " ").trim();
136:            }
137:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.