Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
XMLStringWriter |
|
| 1.8888888888888888;1.889 |
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 | 0 | return new XMLStringWriter(new StringWriter()); |
42 | } | |
43 | ||
44 | private StringWriter sw; | |
45 | ||
46 | private XMLStringWriter(StringWriter sw) { | |
47 | 0 | super(sw); |
48 | 0 | this.sw = sw; |
49 | 0 | } |
50 | ||
51 | /** Gets the string representation of your written XML. */ | |
52 | public String toString() { | |
53 | try { | |
54 | 0 | flush(); |
55 | 0 | } catch (IOException ioe) { |
56 | // won't happen... | |
57 | 0 | } |
58 | 0 | sw.flush(); |
59 | 0 | return sw.toString(); |
60 | } | |
61 | ||
62 | public void writeXMLDeclaration() { | |
63 | try { | |
64 | 0 | super.writeXMLDeclaration(); |
65 | 0 | } catch (IOException ioe) { |
66 | // won't happen... | |
67 | 0 | } |
68 | 0 | } |
69 | ||
70 | public void writeProlog(String prolog) { | |
71 | try { | |
72 | 0 | super.writeProlog(prolog); |
73 | 0 | } catch (IOException ioe) { |
74 | // won't happen... | |
75 | 0 | } |
76 | 0 | } |
77 | ||
78 | public void writeNl() { | |
79 | try { | |
80 | 0 | super.writeNl(); |
81 | 0 | } catch (IOException ioe) { |
82 | // won't happen... | |
83 | 0 | } |
84 | 0 | } |
85 | ||
86 | public void writeComment(String comment) { | |
87 | try { | |
88 | 0 | super.writeComment(comment); |
89 | 0 | } catch (IOException ioe) { |
90 | // won't happen... | |
91 | 0 | } |
92 | 0 | } |
93 | ||
94 | public void writePI(String target, String data) { | |
95 | try { | |
96 | 0 | super.writePI(target, data); |
97 | 0 | } catch (IOException ioe) { |
98 | // won't happen... | |
99 | 0 | } |
100 | 0 | } |
101 | ||
102 | public void writeStartTag(String startTag, boolean nl) { | |
103 | try { | |
104 | 0 | super.writeStartTag(startTag, nl); |
105 | 0 | } catch (IOException ioe) { |
106 | // won't happen... | |
107 | 0 | } |
108 | 0 | } |
109 | ||
110 | public void writeStartTag(String startTag) { | |
111 | try { | |
112 | 0 | super.writeStartTag(startTag); |
113 | 0 | } catch (IOException ioe) { |
114 | // won't happen... | |
115 | 0 | } |
116 | 0 | } |
117 | ||
118 | public void writeEndTag(String endTag, boolean nl) { | |
119 | try { | |
120 | 0 | super.writeEndTag(endTag, nl); |
121 | 0 | } catch (IOException ioe) { |
122 | // won't happen... | |
123 | 0 | } |
124 | 0 | } |
125 | ||
126 | public void writeEndTag(String endTag) { | |
127 | try { | |
128 | 0 | super.writeEndTag(endTag); |
129 | 0 | } catch (IOException ioe) { |
130 | // won't happen... | |
131 | 0 | } |
132 | 0 | } |
133 | ||
134 | public void writeEmptyElement(String emptyTag, boolean nl) { | |
135 | try { | |
136 | 0 | super.writeEmptyElement(emptyTag, nl); |
137 | 0 | } catch (IOException ioe) { |
138 | // won't happen... | |
139 | 0 | } |
140 | 0 | } |
141 | ||
142 | public void writeEmptyElement(String emptyTag) { | |
143 | try { | |
144 | 0 | super.writeEmptyElement(emptyTag); |
145 | 0 | } catch (IOException ioe) { |
146 | // won't happen... | |
147 | 0 | } |
148 | 0 | } |
149 | ||
150 | public void writeCData(String cData) { | |
151 | try { | |
152 | 0 | super.writeCData(cData); |
153 | 0 | } catch (IOException ioe) { |
154 | // won't happen... | |
155 | 0 | } |
156 | 0 | } |
157 | ||
158 | public void writePCData(String pcData) { | |
159 | try { | |
160 | 0 | super.writePCData(pcData); |
161 | 0 | } catch (IOException ioe) { |
162 | // won't happen... | |
163 | 0 | } |
164 | 0 | } |
165 | ||
166 | public void writeElementWithCData(String startTag, String cData, String endTag) { | |
167 | try { | |
168 | 0 | super.writeElementWithCData(startTag, cData, endTag); |
169 | 0 | } catch (IOException ioe) { |
170 | // won't happen... | |
171 | 0 | } |
172 | 0 | } |
173 | ||
174 | public void writeElementWithPCData(String startTag, String pcData, String endTag) { | |
175 | try { | |
176 | 0 | super.writeElementWithPCData(startTag, pcData, endTag); |
177 | 0 | } catch (IOException ioe) { |
178 | // won't happen... | |
179 | 0 | } |
180 | 0 | } |
181 | ||
182 | } |