1 package net.sf.saxon.dom; 2 import net.sf.saxon.Configuration; 3 import net.sf.saxon.event.Builder; 4 import net.sf.saxon.event.PipelineConfiguration; 5 import net.sf.saxon.event.Sender; 6 import net.sf.saxon.om.NamePool; 7 import net.sf.saxon.tinytree.TinyBuilder; 8 import net.sf.saxon.tinytree.TinyDocumentImpl; 9 import net.sf.saxon.trans.XPathException; 10 import org.w3c.dom.DOMImplementation ; 11 import org.w3c.dom.Document ; 12 import org.xml.sax.EntityResolver ; 13 import org.xml.sax.ErrorHandler ; 14 import org.xml.sax.InputSource ; 15 import org.xml.sax.SAXException ; 16 17 import javax.xml.parsers.DocumentBuilder ; 18 import javax.xml.transform.sax.SAXSource ; 19 20 26 27 public class DocumentBuilderImpl extends DocumentBuilder { 28 29 private EntityResolver entityResolver; 30 private ErrorHandler errorHandler; 31 32 public boolean isNamespaceAware() { 33 return true; 34 } 35 36 public boolean isValidating() { 37 return false; 38 } 39 40 public Document newDocument() { 41 return new DocumentOverNodeInfo(); 59 } 60 61 public Document parse(InputSource in) throws SAXException { 62 try { 63 Builder builder = new TinyBuilder(); 64 Configuration config = new Configuration(); 65 NamePool pool = config.getNamePool(); 66 PipelineConfiguration pipe = config.makePipelineConfiguration(); 67 builder.setPipelineConfiguration(pipe); 68 SAXSource source = new SAXSource (in); 69 if (entityResolver != null) { 70 source.getXMLReader().setEntityResolver(entityResolver); 71 } 72 if (errorHandler != null) { 73 source.getXMLReader().setErrorHandler(errorHandler); 74 } 75 source.setSystemId(in.getSystemId()); 76 new Sender(pipe).send(source, builder); 77 TinyDocumentImpl doc = (TinyDocumentImpl)builder.getCurrentRoot(); 78 return (Document )DocumentOverNodeInfo.wrap(doc); 80 } catch (XPathException err) { 81 throw new SAXException (err); 82 } 83 } 84 85 public void setEntityResolver(EntityResolver er) { 86 entityResolver = er; 87 } 88 89 public void setErrorHandler(ErrorHandler eh) { 90 errorHandler = eh; 91 } 92 93 public DOMImplementation getDOMImplementation() { 94 return newDocument().getImplementation(); 95 } 96 } 97 98 99 | Popular Tags |