KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > repository > testsupport > DOMBuilder


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.repository.testsupport;
17
18 import org.w3c.dom.Document JavaDoc;
19 import org.w3c.dom.Node JavaDoc;
20 import org.xml.sax.ContentHandler JavaDoc;
21 import org.xml.sax.SAXException JavaDoc;
22 import org.xml.sax.Locator JavaDoc;
23 import org.xml.sax.Attributes JavaDoc;
24
25 import javax.xml.transform.dom.DOMResult JavaDoc;
26 import javax.xml.transform.sax.SAXTransformerFactory JavaDoc;
27 import javax.xml.transform.sax.TransformerHandler JavaDoc;
28
29 /**
30  * Helper class to build a DOM from SAX events.
31  */

32 public class DOMBuilder implements ContentHandler JavaDoc {
33     private TransformerHandler JavaDoc handler;
34     private DOMResult JavaDoc result;
35
36     public DOMBuilder() throws Exception JavaDoc {
37         SAXTransformerFactory JavaDoc factory = (SAXTransformerFactory JavaDoc)SAXTransformerFactory.newInstance();
38         handler = factory.newTransformerHandler();
39         result = new DOMResult JavaDoc();
40         handler.setResult(result);
41     }
42
43     public Document JavaDoc getDocument() {
44         return (Document JavaDoc)result.getNode();
45     }
46
47     public Node JavaDoc getNode() {
48         return result.getNode();
49     }
50
51     public void endDocument() throws SAXException JavaDoc {
52         handler.endDocument();
53     }
54
55     public void startDocument () throws SAXException JavaDoc {
56         handler.startDocument();
57     }
58
59     public void characters (char ch[], int start, int length) throws SAXException JavaDoc {
60         handler.characters(ch, start, length);
61     }
62
63     public void ignorableWhitespace (char ch[], int start, int length) throws SAXException JavaDoc {
64         handler.ignorableWhitespace(ch, start, length);
65     }
66
67     public void endPrefixMapping (String JavaDoc prefix) throws SAXException JavaDoc {
68         handler.endPrefixMapping(prefix);
69     }
70
71     public void skippedEntity (String JavaDoc name) throws SAXException JavaDoc {
72         handler.skippedEntity(name);
73     }
74
75     public void setDocumentLocator (Locator JavaDoc locator) {
76         handler.setDocumentLocator(locator);
77     }
78
79     public void processingInstruction (String JavaDoc target, String JavaDoc data) throws SAXException JavaDoc {
80         handler.processingInstruction(target, data);
81     }
82
83     public void startPrefixMapping (String JavaDoc prefix, String JavaDoc uri) throws SAXException JavaDoc {
84         handler.startPrefixMapping(prefix, uri);
85     }
86
87     public void endElement (String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName) throws SAXException JavaDoc {
88         handler.endElement(namespaceURI, localName, qName);
89     }
90
91     public void startElement (String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName, Attributes JavaDoc atts) throws SAXException JavaDoc {
92         handler.startElement(namespaceURI, localName, qName, atts);
93     }
94
95 }
96
Popular Tags