001: /*
002: * Copyright 2004 Outerthought bvba and Schaubroeck nv
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.outerj.daisy.repository.testsupport;
017:
018: import org.w3c.dom.Document;
019: import org.w3c.dom.Node;
020: import org.xml.sax.ContentHandler;
021: import org.xml.sax.SAXException;
022: import org.xml.sax.Locator;
023: import org.xml.sax.Attributes;
024:
025: import javax.xml.transform.dom.DOMResult;
026: import javax.xml.transform.sax.SAXTransformerFactory;
027: import javax.xml.transform.sax.TransformerHandler;
028:
029: /**
030: * Helper class to build a DOM from SAX events.
031: */
032: public class DOMBuilder implements ContentHandler {
033: private TransformerHandler handler;
034: private DOMResult result;
035:
036: public DOMBuilder() throws Exception {
037: SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory
038: .newInstance();
039: handler = factory.newTransformerHandler();
040: result = new DOMResult();
041: handler.setResult(result);
042: }
043:
044: public Document getDocument() {
045: return (Document) result.getNode();
046: }
047:
048: public Node getNode() {
049: return result.getNode();
050: }
051:
052: public void endDocument() throws SAXException {
053: handler.endDocument();
054: }
055:
056: public void startDocument() throws SAXException {
057: handler.startDocument();
058: }
059:
060: public void characters(char ch[], int start, int length)
061: throws SAXException {
062: handler.characters(ch, start, length);
063: }
064:
065: public void ignorableWhitespace(char ch[], int start, int length)
066: throws SAXException {
067: handler.ignorableWhitespace(ch, start, length);
068: }
069:
070: public void endPrefixMapping(String prefix) throws SAXException {
071: handler.endPrefixMapping(prefix);
072: }
073:
074: public void skippedEntity(String name) throws SAXException {
075: handler.skippedEntity(name);
076: }
077:
078: public void setDocumentLocator(Locator locator) {
079: handler.setDocumentLocator(locator);
080: }
081:
082: public void processingInstruction(String target, String data)
083: throws SAXException {
084: handler.processingInstruction(target, data);
085: }
086:
087: public void startPrefixMapping(String prefix, String uri)
088: throws SAXException {
089: handler.startPrefixMapping(prefix, uri);
090: }
091:
092: public void endElement(String namespaceURI, String localName,
093: String qName) throws SAXException {
094: handler.endElement(namespaceURI, localName, qName);
095: }
096:
097: public void startElement(String namespaceURI, String localName,
098: String qName, Attributes atts) throws SAXException {
099: handler.startElement(namespaceURI, localName, qName, atts);
100: }
101:
102: }
|