Source Code Cross Referenced for XMLWriter.java in  » Database-ORM » MMBase » org » mmbase » util » xml » 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 ORM » MMBase » org.mmbase.util.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         
003:        This software is OSI Certified Open Source Software.
004:        OSI Certified is a certification mark of the Open Source Initiative.
005:         
006:        The license (Mozilla version 1.0) can be read at the MMBase site.
007:        See http://www.MMBase.org/license
008:         
009:         */
010:        package org.mmbase.util.xml;
011:
012:        import java.io.*;
013:
014:        import org.w3c.dom.*;
015:
016:        import javax.xml.transform.*;
017:        import javax.xml.transform.dom.DOMSource;
018:        import javax.xml.transform.stream.StreamResult;
019:
020:        import org.mmbase.util.logging.*;
021:
022:        /**
023:         * Util class to serialize xml (wrapper around javax.xml.transform.Transformer)
024:         * @author Kees Jongenburger <keesj@dds.nl>
025:         * @since MMBase-1.7
026:         **/
027:        public class XMLWriter {
028:            private static Logger log = Logging
029:                    .getLoggerInstance(XMLWriter.class);
030:
031:            /**
032:             * defaulting version of {@link #write(Node, Writer, boolean, boolean)}. (Not ommitting xml declaration).
033:             */
034:            public static void write(Node node, Writer writer, boolean indent)
035:                    throws TransformerConfigurationException,
036:                    TransformerException {
037:                write(node, writer, indent, false);
038:            }
039:
040:            /**
041:             * static method to serialize an DOM document
042:             * @param node the node to serialize
043:             * @param writer the writer to write the node to
044:             * @param indent if true the document wil be indented
045:             * @param omitxml
046:             **/
047:            public static void write(Node node, Writer writer, boolean indent,
048:                    boolean omitxml) throws TransformerConfigurationException,
049:                    TransformerException {
050:                TransformerFactory transformerFactory = TransformerFactory
051:                        .newInstance();
052:                try {
053:                    transformerFactory.setAttribute(
054:                            "http://saxon.sf.net/feature/version-warning",
055:                            false);
056:                } catch (IllegalArgumentException iae) {
057:                    // never mind
058:                }
059:                Transformer transformer = transformerFactory.newTransformer();
060:                transformer.setOutputProperty(OutputKeys.INDENT, indent ? "yes"
061:                        : "no");
062:                transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
063:                        omitxml ? "yes" : "no");
064:                if (!omitxml) {
065:                    Document d = node.getOwnerDocument();
066:                    if (d != null) {
067:                        DocumentType dt = d.getDoctype();
068:                        if (dt != null) {
069:                            transformer
070:                                    .setOutputProperty(
071:                                            OutputKeys.DOCTYPE_PUBLIC, dt
072:                                                    .getPublicId());
073:                            transformer
074:                                    .setOutputProperty(
075:                                            OutputKeys.DOCTYPE_SYSTEM, dt
076:                                                    .getSystemId());
077:                        }
078:                    }
079:                }
080:                transformer.transform(new DOMSource(node), new StreamResult(
081:                        writer));
082:            }
083:
084:            /**
085:             * Defaulting version of {@link #write(Node, boolean, boolean)}. (Not ommitting xml
086:             * declaration).
087:             */
088:            public static String write(Node node, boolean indent) {
089:                return write(node, indent, false);
090:            }
091:
092:            /**
093:             * static method to serialize a node to a string
094:             * @param node the node to serialize
095:             * @param indent , if true the node wil be indented
096:             * @param omitxml
097:             * @return the string represneation of the xml of null if an error occured
098:             **/
099:            public static String write(Node node, boolean indent,
100:                    boolean omitxml) {
101:                try {
102:                    StringWriter sw = new StringWriter();
103:                    write(node, sw, indent, omitxml);
104:                    return sw.toString();
105:                } catch (Exception e) {
106:                    //sorry for this message. but this is a util class that just has to do the jobs
107:                    //if it fails i can't help it
108:                    log
109:                            .fatal("error in XMLWriter. it must be possible to write any node to xml withoud errors:{"
110:                                    + e.getMessage()
111:                                    + "} "
112:                                    + Logging.stackTrace(e));
113:                }
114:                return null;
115:            }
116:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.