Source Code Cross Referenced for JAXPTransformer.java in  » Database-ORM » toplink » oracle » toplink » essentials » platform » xml » jaxp » 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 » toplink » oracle.toplink.essentials.platform.xml.jaxp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         * 
004:         * // Copyright (c) 1998, 2007, Oracle. All rights reserved.
005:         * 
006:         *
007:         * The contents of this file are subject to the terms of either the GNU
008:         * General Public License Version 2 only ("GPL") or the Common Development
009:         * and Distribution License("CDDL") (collectively, the "License").  You
010:         * may not use this file except in compliance with the License. You can obtain
011:         * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
012:         * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
013:         * language governing permissions and limitations under the License.
014:         * 
015:         * When distributing the software, include this License Header Notice in each
016:         * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
017:         * Sun designates this particular file as subject to the "Classpath" exception
018:         * as provided by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code.  If applicable, add the following below the License
020:         * Header, with the fields enclosed by brackets [] replaced by your own
021:         * identifying information: "Portions Copyrighted [year]
022:         * [name of copyright owner]"
023:         * 
024:         * Contributor(s):
025:         * 
026:         * If you wish your version of this file to be governed by only the CDDL or
027:         * only the GPL Version 2, indicate your decision by adding "[Contributor]
028:         * elects to include this software in this distribution under the [CDDL or GPL
029:         * Version 2] license."  If you don't indicate a single choice of license, a
030:         * recipient has the option to distribute your version of this file under
031:         * either the CDDL, the GPL Version 2 or to extend the choice of license to
032:         * its licensees as provided above.  However, if you add GPL Version 2 code
033:         * and therefore, elected the GPL Version 2 license, then the option applies
034:         * only if the new code is made subject to such option by the copyright
035:         * holder.
036:         */
037:        package oracle.toplink.essentials.platform.xml.jaxp;
038:
039:        import java.io.OutputStream;
040:        import java.io.Writer;
041:        import java.net.URL;
042:        import javax.xml.transform.OutputKeys;
043:        import javax.xml.transform.Result;
044:        import javax.xml.transform.Source;
045:        import javax.xml.transform.Transformer;
046:        import javax.xml.transform.TransformerConfigurationException;
047:        import javax.xml.transform.TransformerException;
048:        import javax.xml.transform.TransformerFactory;
049:        import javax.xml.transform.dom.DOMResult;
050:        import javax.xml.transform.dom.DOMSource;
051:        import javax.xml.transform.sax.SAXResult;
052:        import javax.xml.transform.stream.StreamResult;
053:        import javax.xml.transform.stream.StreamSource;
054:        import oracle.toplink.essentials.platform.xml.XMLPlatformException;
055:        import oracle.toplink.essentials.platform.xml.XMLTransformer;
056:        import org.w3c.dom.Document;
057:        import org.w3c.dom.Node;
058:        import org.xml.sax.ContentHandler;
059:
060:        public class JAXPTransformer implements  XMLTransformer {
061:            private boolean fragment;
062:            private static final String NO = "no";
063:            private static final String YES = "yes";
064:            private Transformer transformer;
065:
066:            public JAXPTransformer() {
067:                super ();
068:                try {
069:                    TransformerFactory transformerFactory = TransformerFactory
070:                            .newInstance();
071:                    transformer = transformerFactory.newTransformer();
072:                } catch (TransformerConfigurationException e) {
073:                    throw XMLPlatformException.xmlPlatformTransformException(e);
074:                }
075:            }
076:
077:            public String getEncoding() {
078:                return transformer.getOutputProperty(OutputKeys.ENCODING);
079:            }
080:
081:            public void setEncoding(String encoding) {
082:                transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
083:            }
084:
085:            public boolean isFormattedOutput() {
086:                return transformer.getOutputProperty(OutputKeys.INDENT).equals(
087:                        YES);
088:            }
089:
090:            public void setFormattedOutput(boolean shouldFormat) {
091:                if (shouldFormat) {
092:                    transformer.setOutputProperty(OutputKeys.INDENT, YES);
093:                } else {
094:                    transformer.setOutputProperty(OutputKeys.INDENT, NO);
095:                }
096:            }
097:
098:            public String getVersion() {
099:                return transformer.getOutputProperty(OutputKeys.VERSION);
100:            }
101:
102:            public void setVersion(String version) {
103:                transformer.setOutputProperty(OutputKeys.VERSION, version);
104:            }
105:
106:            public void transform(Node sourceNode,
107:                    OutputStream resultOutputStream)
108:                    throws XMLPlatformException {
109:                DOMSource source = new DOMSource(sourceNode);
110:                StreamResult result = new StreamResult(resultOutputStream);
111:                if (isFragment()) {
112:                    transformer.setOutputProperty(
113:                            OutputKeys.OMIT_XML_DECLARATION, "yes");
114:                }
115:                transform(source, result);
116:            }
117:
118:            public void transform(Node sourceNode,
119:                    ContentHandler resultContentHandler)
120:                    throws XMLPlatformException {
121:                DOMSource source = new DOMSource(sourceNode);
122:                SAXResult result = new SAXResult(resultContentHandler);
123:
124:                transform(source, result);
125:            }
126:
127:            public void transform(Node sourceNode, Result result)
128:                    throws XMLPlatformException {
129:                DOMSource source = null;
130:                if ((isFragment()) && (result instanceof  SAXResult)) {
131:                    if (sourceNode instanceof  Document) {
132:                        source = new DOMSource(((Document) sourceNode)
133:                                .getDocumentElement());
134:                    }
135:                } else {
136:                    source = new DOMSource(sourceNode);
137:                }
138:                transform(source, result);
139:            }
140:
141:            public void transform(Node sourceNode, Writer resultWriter)
142:                    throws XMLPlatformException {
143:                DOMSource source = new DOMSource(sourceNode);
144:                StreamResult result = new StreamResult(resultWriter);
145:
146:                if (isFragment()) {
147:                    transformer.setOutputProperty(
148:                            OutputKeys.OMIT_XML_DECLARATION, "yes");
149:                }
150:                transform(source, result);
151:            }
152:
153:            public void transform(Source source, Result result)
154:                    throws XMLPlatformException {
155:                try {
156:                    if ((result instanceof  StreamResult) && (isFragment())) {
157:                        transformer.setOutputProperty(
158:                                OutputKeys.OMIT_XML_DECLARATION, "yes");
159:                    }
160:                    transformer.transform(source, result);
161:                } catch (TransformerException e) {
162:                    throw XMLPlatformException.xmlPlatformTransformException(e);
163:                }
164:            }
165:
166:            public void transform(Document sourceDocument,
167:                    Node resultParentNode, URL stylesheet)
168:                    throws XMLPlatformException {
169:                try {
170:                    TransformerFactory transformerFactory = TransformerFactory
171:                            .newInstance();
172:                    StreamSource stylesheetSource = new StreamSource(stylesheet
173:                            .openStream());
174:                    Transformer transformer = transformerFactory
175:                            .newTransformer(stylesheetSource);
176:                    DOMSource source = new DOMSource(sourceDocument);
177:                    DOMResult result = new DOMResult(resultParentNode);
178:                    transformer.transform(source, result);
179:                } catch (Exception e) {
180:                    throw XMLPlatformException.xmlPlatformTransformException(e);
181:                }
182:            }
183:
184:            public void setFragment(boolean fragment) {
185:                this .fragment = fragment;
186:            }
187:
188:            public boolean isFragment() {
189:                return fragment;
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.