01: /*
02: * The contents of this file are subject to the terms
03: * of the Common Development and Distribution License
04: * (the "License"). You may not use this file except
05: * in compliance with the License.
06: *
07: * You can obtain a copy of the license at
08: * https://jwsdp.dev.java.net/CDDLv1.0.html
09: * See the License for the specific language governing
10: * permissions and limitations under the License.
11: *
12: * When distributing Covered Code, include this CDDL
13: * HEADER in each file and include the License file at
14: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
15: * add the following below this CDDL HEADER, with the
16: * fields enclosed by brackets "[]" replaced with your
17: * own identifying information: Portions Copyright [yyyy]
18: * [name of copyright owner]
19: */
20:
21: package com.sun.xml.txw2.output;
22:
23: import java.io.PrintStream;
24:
25: /**
26: * Shows the call sequence of {@link XmlSerializer} methods.
27: *
28: * Useful for debugging and learning how TXW works.
29: *
30: * @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
31: */
32: public class DumpSerializer implements XmlSerializer {
33: private final PrintStream out;
34:
35: public DumpSerializer(PrintStream out) {
36: this .out = out;
37: }
38:
39: public void beginStartTag(String uri, String localName,
40: String prefix) {
41: out.println('<' + prefix + ':' + localName);
42: }
43:
44: public void writeAttribute(String uri, String localName,
45: String prefix, StringBuilder value) {
46: out.println('@' + prefix + ':' + localName + '=' + value);
47: }
48:
49: public void writeXmlns(String prefix, String uri) {
50: out.println("xmlns:" + prefix + '=' + uri);
51: }
52:
53: public void endStartTag(String uri, String localName, String prefix) {
54: out.println('>');
55: }
56:
57: public void endTag() {
58: out.println("</ >");
59: }
60:
61: public void text(StringBuilder text) {
62: out.println(text);
63: }
64:
65: public void cdata(StringBuilder text) {
66: out.println("<![CDATA[");
67: out.println(text);
68: out.println("]]>");
69: }
70:
71: public void comment(StringBuilder comment) {
72: out.println("<!--");
73: out.println(comment);
74: out.println("-->");
75: }
76:
77: public void startDocument() {
78: out.println("<?xml?>");
79: }
80:
81: public void endDocument() {
82: out.println("done");
83: }
84:
85: public void flush() {
86: out.println("flush");
87: }
88: }
|