1 7 8 package org.dom4j.io; 9 10 import javax.xml.transform.sax.SAXResult ; 11 12 import org.dom4j.Document; 13 14 import org.xml.sax.ContentHandler ; 15 import org.xml.sax.ext.LexicalHandler ; 16 17 26 public class DocumentResult extends SAXResult { 27 private SAXContentHandler contentHandler; 28 29 public DocumentResult() { 30 this(new SAXContentHandler()); 31 } 32 33 public DocumentResult(SAXContentHandler contentHandler) { 34 this.contentHandler = contentHandler; 35 super.setHandler(this.contentHandler); 36 super.setLexicalHandler(this.contentHandler); 37 } 38 39 44 public Document getDocument() { 45 return contentHandler.getDocument(); 46 } 47 48 public void setHandler(ContentHandler handler) { 51 if (handler instanceof SAXContentHandler) { 52 this.contentHandler = (SAXContentHandler) handler; 53 super.setHandler(this.contentHandler); 54 } 55 } 56 57 public void setLexicalHandler(LexicalHandler handler) { 58 if (handler instanceof SAXContentHandler) { 59 this.contentHandler = (SAXContentHandler) handler; 60 super.setLexicalHandler(this.contentHandler); 61 } 62 } 63 } 64 65 101 | Popular Tags |