1 /*
2 * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons-sandbox//xmlio/src/java/org/apache/commons/xmlio/out/XMLStringWriter.java,v 1.1 2004/10/08 11:56:20 ozeigermann Exp $
3 * $Revision: 155476 $
4 * $Date: 2005-02-26 13:31:24 +0000 (Sat, 26 Feb 2005) $
5 *
6 * ====================================================================
7 *
8 * Copyright 2004 The Apache Software Foundation
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 *
22 */
23
24 package org.apache.commons.xmlio.out;
25
26 import java.io.IOException;
27 import java.io.StringWriter;
28
29 /**
30 * This is a convenience class for writing XML to a string. As
31 * no IOExceptions will occur this class catches them for you
32 * doing nothing. Call {@link #toString} to finally get your string.
33 * As constructor for {@link XMLWriter} already needs writer call
34 * {@link #create} to get your objects instead of consructor.
35 *
36 */
37 public class XMLStringWriter extends XMLWriter {
38
39 /** Creates a new <code>XMLStringWriter</code> objects. */
40 public static XMLStringWriter create() {
41 return new XMLStringWriter(new StringWriter());
42 }
43
44 private StringWriter sw;
45
46 private XMLStringWriter(StringWriter sw) {
47 super(sw);
48 this.sw = sw;
49 }
50
51 /** Gets the string representation of your written XML. */
52 public String toString() {
53 try {
54 flush();
55 } catch (IOException ioe) {
56 // won't happen...
57 }
58 sw.flush();
59 return sw.toString();
60 }
61
62 public void writeXMLDeclaration() {
63 try {
64 super.writeXMLDeclaration();
65 } catch (IOException ioe) {
66 // won't happen...
67 }
68 }
69
70 public void writeProlog(String prolog) {
71 try {
72 super.writeProlog(prolog);
73 } catch (IOException ioe) {
74 // won't happen...
75 }
76 }
77
78 public void writeNl() {
79 try {
80 super.writeNl();
81 } catch (IOException ioe) {
82 // won't happen...
83 }
84 }
85
86 public void writeComment(String comment) {
87 try {
88 super.writeComment(comment);
89 } catch (IOException ioe) {
90 // won't happen...
91 }
92 }
93
94 public void writePI(String target, String data) {
95 try {
96 super.writePI(target, data);
97 } catch (IOException ioe) {
98 // won't happen...
99 }
100 }
101
102 public void writeStartTag(String startTag, boolean nl) {
103 try {
104 super.writeStartTag(startTag, nl);
105 } catch (IOException ioe) {
106 // won't happen...
107 }
108 }
109
110 public void writeStartTag(String startTag) {
111 try {
112 super.writeStartTag(startTag);
113 } catch (IOException ioe) {
114 // won't happen...
115 }
116 }
117
118 public void writeEndTag(String endTag, boolean nl) {
119 try {
120 super.writeEndTag(endTag, nl);
121 } catch (IOException ioe) {
122 // won't happen...
123 }
124 }
125
126 public void writeEndTag(String endTag) {
127 try {
128 super.writeEndTag(endTag);
129 } catch (IOException ioe) {
130 // won't happen...
131 }
132 }
133
134 public void writeEmptyElement(String emptyTag, boolean nl) {
135 try {
136 super.writeEmptyElement(emptyTag, nl);
137 } catch (IOException ioe) {
138 // won't happen...
139 }
140 }
141
142 public void writeEmptyElement(String emptyTag) {
143 try {
144 super.writeEmptyElement(emptyTag);
145 } catch (IOException ioe) {
146 // won't happen...
147 }
148 }
149
150 public void writeCData(String cData) {
151 try {
152 super.writeCData(cData);
153 } catch (IOException ioe) {
154 // won't happen...
155 }
156 }
157
158 public void writePCData(String pcData) {
159 try {
160 super.writePCData(pcData);
161 } catch (IOException ioe) {
162 // won't happen...
163 }
164 }
165
166 public void writeElementWithCData(String startTag, String cData, String endTag) {
167 try {
168 super.writeElementWithCData(startTag, cData, endTag);
169 } catch (IOException ioe) {
170 // won't happen...
171 }
172 }
173
174 public void writeElementWithPCData(String startTag, String pcData, String endTag) {
175 try {
176 super.writeElementWithPCData(startTag, pcData, endTag);
177 } catch (IOException ioe) {
178 // won't happen...
179 }
180 }
181
182 }