1 28 29 package com.caucho.xsl; 30 31 import com.caucho.util.L10N; 32 import com.caucho.xml.DOMBuilder; 33 import com.caucho.xml.QDocument; 34 35 import org.w3c.dom.Node ; 36 import org.xml.sax.*; 37 import org.xml.sax.ext.LexicalHandler ; 38 39 import javax.xml.transform.TransformerException ; 40 import java.io.IOException ; 41 42 public class SAXFilterImpl implements XMLFilter { 43 protected static L10N L = new L10N(SAXFilterImpl.class); 44 45 protected TransformerImpl transformer; 46 47 private XMLReader parent; 48 private ContentHandler contentHandler; 49 private LexicalHandler lexicalHandler; 50 private ErrorHandler errorHandler; 51 52 protected SAXFilterImpl(TransformerImpl transformer) 53 { 54 this.transformer = transformer; 55 } 56 57 public void setParent(XMLReader parent) 58 { 59 this.parent = parent; 60 } 61 62 public XMLReader getParent() 63 { 64 return parent; 65 } 66 67 public boolean getFeature(String name) 68 throws SAXNotRecognizedException, SAXNotSupportedException 69 { 70 return false; 71 } 72 73 public void setFeature(String name, boolean value) 74 throws SAXNotRecognizedException, SAXNotSupportedException 75 { 76 } 77 78 public Object getProperty(String name) 79 throws SAXNotRecognizedException, SAXNotSupportedException 80 { 81 return null; 82 } 83 84 public void setProperty(String name, Object value) 85 throws SAXNotRecognizedException, SAXNotSupportedException 86 { 87 } 88 89 public void setEntityResolver(EntityResolver resolver) 90 { 91 } 92 93 public EntityResolver getEntityResolver() 94 { 95 return null; 96 } 97 98 public void setDTDHandler(DTDHandler handler) 99 { 100 } 101 102 public DTDHandler getDTDHandler() 103 { 104 return null; 105 } 106 107 public void setContentHandler(ContentHandler handler) 108 { 109 this.contentHandler = handler; 110 } 111 112 public ContentHandler getContentHandler() 113 { 114 return contentHandler; 115 } 116 117 public void setErrorHandler(ErrorHandler handler) 118 { 119 this.errorHandler = handler; 120 } 121 122 public ErrorHandler getErrorHandler() 123 { 124 return errorHandler; 125 } 126 127 public void parse(InputSource input) 128 throws IOException , SAXException 129 { 130 DOMBuilder builder = new DOMBuilder(); 131 Node sourceNode = new QDocument(); 132 builder.init(sourceNode); 133 134 parent.setContentHandler(builder); 135 parent.parse(input); 136 137 try { 138 transformer.transform(sourceNode, contentHandler, lexicalHandler); 139 } catch (TransformerException e) { 140 throw new SAXException(String.valueOf(e)); 141 } 142 } 143 144 public void parse(String systemId) 145 throws IOException , SAXException 146 { 147 DOMBuilder builder = new DOMBuilder(); 148 Node sourceNode = new QDocument(); 149 builder.init(sourceNode); 150 151 parent.setContentHandler(builder); 152 153 parent.parse(systemId); 154 155 try { 156 transformer.transform(sourceNode, contentHandler, lexicalHandler); 157 } catch (TransformerException e) { 158 throw new SAXException(String.valueOf(e)); 159 } 160 } 161 } 162 | Popular Tags |