1 16 package org.apache.cocoon.xml; 17 18 import org.apache.cocoon.xml.dom.DOMStreamer; 19 import org.w3c.dom.Document ; 20 import org.w3c.dom.Node ; 21 import org.xml.sax.ContentHandler ; 22 import org.xml.sax.SAXException ; 23 24 import javax.xml.parsers.DocumentBuilder ; 25 import javax.xml.parsers.DocumentBuilderFactory ; 26 import javax.xml.parsers.ParserConfigurationException ; 27 28 39 public abstract class AbstractDOMFragment implements XMLFragment { 40 41 45 public void toSAX(ContentHandler handler) throws SAXException { 46 DocumentBuilder builder; 48 try { 49 builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 50 } catch (ParserConfigurationException e) { 51 throw new SAXException ("Couldn't get a DocumentBuilder", e); 52 } 53 54 Document doc = builder.newDocument(); 55 56 Node df = doc.createDocumentFragment(); 59 60 try { 62 toDOM(df); 63 } catch(Exception e) { 64 throw new SAXException ("Exception while converting object to DOM", e); 65 } 66 67 handler.startDocument(); 69 new DOMStreamer(handler).stream(df); 70 handler.endDocument(); 71 } 72 } 73 | Popular Tags |