Clover coverage report - dom4j - 1.6.1
Coverage timestamp: ma mei 16 2005 14:23:01 GMT+01:00

file stats: | LOC: | 287 |  | Methods: | 27
| NCLOC: | 180 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

SAXModifyContentHandler.java

0%

0%

0%

0%

1 |  | /*
2 |  | * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
3 |  | *
4 |  | * This software is open source.
5 |  | * See the bottom of this file for the licence.
6 |  | */
7 |  |
8 |  | package org.dom4j.io;
9 |  |
10 |  | import java.io.IOException;
11 |  |
12 |  | import org.dom4j.DocumentFactory;
13 |  | import org.dom4j.Element;
14 |  | import org.dom4j.ElementHandler;
15 |  |
16 |  | import org.xml.sax.Attributes;
17 |  | import org.xml.sax.Locator;
18 |  | import org.xml.sax.SAXException;
19 |  |
20 |  | /**
21 |  | * This extension of the SAXContentHandler writes SAX events immediately to the
22 |  | * provided XMLWriter, unless some {@link org.dom4.ElementHandler}is still
23 |  | * handling the current Element.
24 |  | *
25 |  | * @author Wonne Keysers (Realsoftware.be)
26 |  | *
27 |  | * @see org.dom4j.io.SAXContentHandler
28 |  | */
29 |  | class SAXModifyContentHandler extends SAXContentHandler {
30 |  | private XMLWriter xmlWriter;
31 |  |
32 | 0 | public SAXModifyContentHandler() {
33 |  | }
34 |  |
35 | 0 | public SAXModifyContentHandler(DocumentFactory documentFactory) {
36 | 0 | super(documentFactory);
37 |  | }
38 |  |
39 | 0 | public SAXModifyContentHandler(DocumentFactory documentFactory,
40 |  | ElementHandler elementHandler) {
41 | 0 | super(documentFactory, elementHandler);
42 |  | }
43 |  |
44 | 0 | public SAXModifyContentHandler(DocumentFactory documentFactory,
45 |  | ElementHandler elementHandler, ElementStack elementStack) {
46 | 0 | super(documentFactory, elementHandler, elementStack);
47 |  | }
48 |  |
49 | 0 | public void setXMLWriter(XMLWriter writer) {
50 | 0 | this.xmlWriter = writer;
51 |  | }
52 |  |
53 | 0 | public void startCDATA() throws SAXException {
54 | 0 | super.startCDATA();
55 |  |
56 | 0 | if (!activeHandlers() && (xmlWriter != null)) {
57 | 0 | xmlWriter.startCDATA();
58 |  | }
59 |  | }
60 |  |
61 | 0 | public void startDTD(String name, String publicId, String systemId)
62 |  | throws SAXException {
63 | 0 | super.startDTD(name, publicId, systemId);
64 |  |
65 | 0 | if (xmlWriter != null) {
66 | 0 | xmlWriter.startDTD(name, publicId, systemId);
67 |  | }
68 |  | }
69 |  |
70 | 0 | public void endDTD() throws org.xml.sax.SAXException {
71 | 0 | super.endDTD();
72 |  |
73 | 0 | if (xmlWriter != null) {
74 | 0 | xmlWriter.endDTD();
75 |  | }
76 |  | }
77 |  |
78 | 0 | public void comment(char[] characters, int parm2, int parm3)
79 |  | throws SAXException {
80 | 0 | super.comment(characters, parm2, parm3);
81 |  |
82 | 0 | if (!activeHandlers() && (xmlWriter != null)) {
83 | 0 | xmlWriter.comment(characters, parm2, parm3);
84 |  | }
85 |  | }
86 |  |
87 | 0 | public void startEntity(String name) throws SAXException {
88 | 0 | super.startEntity(name);
89 |  |
90 | 0 | if (xmlWriter != null) {
91 | 0 | xmlWriter.startEntity(name);
92 |  | }
93 |  | }
94 |  |
95 | 0 | public void endCDATA() throws org.xml.sax.SAXException {
96 | 0 | super.endCDATA();
97 |  |
98 | 0 | if (!activeHandlers() && (xmlWriter != null)) {
99 | 0 | xmlWriter.endCDATA();
100 |  | }
101 |  | }
102 |  |
103 | 0 | public void endEntity(String name) throws SAXException {
104 | 0 | super.endEntity(name);
105 |  |
106 | 0 | if (xmlWriter != null) {
107 | 0 | xmlWriter.endEntity(name);
108 |  | }
109 |  | }
110 |  |
111 | 0 | public void unparsedEntityDecl(String name, String publicId,
112 |  | String systemId, String notation) throws SAXException {
113 | 0 | super.unparsedEntityDecl(name, publicId, systemId, notation);
114 |  |
115 | 0 | if (!activeHandlers() && (xmlWriter != null)) {
116 | 0 | xmlWriter.unparsedEntityDecl(name, publicId, systemId, notation);
117 |  | }
118 |  | }
119 |  |
120 | 0 | public void notationDecl(String name, String publicId, String systemId)
121 |  | throws SAXException {
122 | 0 | super.notationDecl(name, publicId, systemId);
123 |  |
124 | 0 | if (xmlWriter != null) {
125 | 0 | xmlWriter.notationDecl(name, publicId, systemId);
126 |  | }
127 |  | }
128 |  |
129 | 0 | public void startElement(String uri, String localName, String qName,
130 |  | Attributes atts) throws SAXException {
131 | 0 | super.startElement(uri, localName, qName, atts);
132 |  |
133 | 0 | if (!activeHandlers() && (xmlWriter != null)) {
134 | 0 | xmlWriter.startElement(uri, localName, qName, atts);
135 |  | }
136 |  | }
137 |  |
138 | 0 | public void startDocument() throws SAXException {
139 | 0 | super.startDocument();
140 |  |
141 | 0 | if (xmlWriter != null) {
142 | 0 | xmlWriter.startDocument();
143 |  | }
144 |  | }
145 |  |
146 | 0 | public void ignorableWhitespace(char[] parm1, int parm2, int parm3)
147 |  | throws SAXException {
148 | 0 | super.ignorableWhitespace(parm1, parm2, parm3);
149 |  |
150 | 0 | if (!activeHandlers() && (xmlWriter != null)) {
151 | 0 | xmlWriter.ignorableWhitespace(parm1, parm2, parm3);
152 |  | }
153 |  | }
154 |  |
155 | 0 | public void processingInstruction(String target, String data)
156 |  | throws SAXException {
157 | 0 | super.processingInstruction(target, data);
158 |  |
159 | 0 | if (!activeHandlers() && (xmlWriter != null)) {
160 | 0 | xmlWriter.processingInstruction(target, data);
161 |  | }
162 |  | }
163 |  |
164 | 0 | public void setDocumentLocator(Locator locator) {
165 | 0 | super.setDocumentLocator(locator);
166 |  |
167 | 0 | if (xmlWriter != null) {
168 | 0 | xmlWriter.setDocumentLocator(locator);
169 |  | }
170 |  | }
171 |  |
172 | 0 | public void skippedEntity(String name) throws SAXException {
173 | 0 | super.skippedEntity(name);
174 |  |
175 | 0 | if (!activeHandlers() && (xmlWriter != null)) {
176 | 0 | xmlWriter.skippedEntity(name);
177 |  | }
178 |  | }
179 |  |
180 | 0 | public void endDocument() throws SAXException {
181 | 0 | super.endDocument();
182 |  |
183 | 0 | if (xmlWriter != null) {
184 | 0 | xmlWriter.endDocument();
185 |  | }
186 |  | }
187 |  |
188 | 0 | public void startPrefixMapping(String prefix, String uri)
189 |  | throws SAXException {
190 | 0 | super.startPrefixMapping(prefix, uri);
191 |  |
192 | 0 | if (xmlWriter != null) {
193 | 0 | xmlWriter.startPrefixMapping(prefix, uri);
194 |  | }
195 |  | }
196 |  |
197 | 0 | public void endElement(String uri, String localName, String qName)
198 |  | throws SAXException {
199 | 0 | ElementHandler currentHandler = getElementStack().getDispatchHandler()
200 |  | .getHandler(getElementStack().getPath());
201 |  |
202 | 0 | super.endElement(uri, localName, qName);
203 |  |
204 | 0 | if (!activeHandlers()) {
205 | 0 | if (xmlWriter != null) {
206 | 0 | if (currentHandler == null) {
207 | 0 | xmlWriter.endElement(uri, localName, qName);
208 | 0 | } else if (currentHandler instanceof SAXModifyElementHandler) {
209 | 0 | SAXModifyElementHandler modifyHandler
210 |  | = (SAXModifyElementHandler) currentHandler;
211 | 0 | Element modifiedElement = modifyHandler
212 |  | .getModifiedElement();
213 |  |
214 | 0 | try {
215 | 0 | xmlWriter.write(modifiedElement);
216 |  | } catch (IOException ex) {
217 | 0 | throw new SAXModifyException(ex);
218 |  | }
219 |  | }
220 |  | }
221 |  | }
222 |  | }
223 |  |
224 | 0 | public void endPrefixMapping(String prefix) throws SAXException {
225 | 0 | super.endPrefixMapping(prefix);
226 |  |
227 | 0 | if (xmlWriter != null) {
228 | 0 | xmlWriter.endPrefixMapping(prefix);
229 |  | }
230 |  | }
231 |  |
232 | 0 | public void characters(char[] parm1, int parm2, int parm3)
233 |  | throws SAXException {
234 | 0 | super.characters(parm1, parm2, parm3);
235 |  |
236 | 0 | if (!activeHandlers() && (xmlWriter != null)) {
237 | 0 | xmlWriter.characters(parm1, parm2, parm3);
238 |  | }
239 |  | }
240 |  |
241 | 0 | protected XMLWriter getXMLWriter() {
242 | 0 | return this.xmlWriter;
243 |  | }
244 |  |
245 | 0 | private boolean activeHandlers() {
246 | 0 | DispatchHandler handler = getElementStack().getDispatchHandler();
247 |  |
248 | 0 | return handler.getActiveHandlerCount() > 0;
249 |  | }
250 |  | }
251 |  |
252 |  | /*
253 |  | * Redistribution and use of this software and associated documentation
254 |  | * ("Software"), with or without modification, are permitted provided that the
255 |  | * following conditions are met:
256 |  | *
257 |  | * 1. Redistributions of source code must retain copyright statements and
258 |  | * notices. Redistributions must also contain a copy of this document.
259 |  | *
260 |  | * 2. Redistributions in binary form must reproduce the above copyright notice,
261 |  | * this list of conditions and the following disclaimer in the documentation
262 |  | * and/or other materials provided with the distribution.
263 |  | *
264 |  | * 3. The name "DOM4J" must not be used to endorse or promote products derived
265 |  | * from this Software without prior written permission of MetaStuff, Ltd. For
266 |  | * written permission, please contact dom4j-info@metastuff.com.
267 |  | *
268 |  | * 4. Products derived from this Software may not be called "DOM4J" nor may
269 |  | * "DOM4J" appear in their names without prior written permission of MetaStuff,
270 |  | * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
271 |  | *
272 |  | * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
273 |  | *
274 |  | * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
275 |  | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
276 |  | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
277 |  | * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
278 |  | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
279 |  | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
280 |  | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
281 |  | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
282 |  | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
283 |  | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
284 |  | * POSSIBILITY OF SUCH DAMAGE.
285 |  | *
286 |  | * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
287 |  | */