1 2 package com.icl.saxon; 3 import com.icl.saxon.om.*; 4 import com.icl.saxon.output.Outputter; 5 import com.icl.saxon.output.GeneralOutputter; 6 import org.xml.sax.*; 7 import org.w3c.dom.Document ; 8 9 10 import java.util.Properties ; 11 12 import javax.xml.transform.TransformerException ; 13 import javax.xml.transform.sax.SAXResult ; 14 15 16 23 24 public class TreeDriver extends DOMDriver 25 { 26 27 private Outputter outputter; 28 29 32 33 public void setDocument(Document doc) { 34 root = doc; 35 if (!(doc instanceof DocumentInfo)) { 36 throw new IllegalArgumentException ("TreeDriver can only be used with a Saxon tree"); 37 } 38 } 39 40 43 44 48 53 54 public void parse() throws SAXException 55 { 56 if (root==null) { 57 throw new SAXException("TreeDriver: no start node defined"); 58 } 59 if (contentHandler==null) { 60 throw new SAXException("DOMDriver: no content handler defined"); 61 } 62 contentHandler.setDocumentLocator(this); 63 DocumentInfo doc = (DocumentInfo)root; 64 try { 65 GeneralOutputter outputter = new GeneralOutputter(doc.getNamePool()); 66 SAXResult result = new SAXResult (contentHandler); 67 result.setSystemId(systemId); 68 outputter.setOutputDestination(new Properties (), result); 69 doc.copy(outputter); 70 outputter.close(); 71 } catch (TransformerException err) { 72 throw new SAXException(err); 73 } 74 } 75 76 } 77 | Popular Tags |