1 16 package org.apache.cocoon.components.validation.jing; 17 18 import java.io.IOException ; 19 import java.util.Stack ; 20 21 import javax.xml.parsers.ParserConfigurationException ; 22 import javax.xml.parsers.SAXParserFactory ; 23 24 import org.xml.sax.ContentHandler ; 25 import org.xml.sax.DTDHandler ; 26 import org.xml.sax.ErrorHandler ; 27 import org.xml.sax.InputSource ; 28 import org.xml.sax.SAXException ; 29 import org.xml.sax.SAXNotRecognizedException ; 30 import org.xml.sax.SAXNotSupportedException ; 31 import org.xml.sax.XMLReader ; 32 33 import com.thaiopensource.xml.sax.DraconianErrorHandler; 34 35 40 final class JingReader implements XMLReader { 41 42 43 private final XMLReader reader; 44 45 private final JingResolver context; 46 47 51 protected JingReader(JingResolver context) 52 throws SAXException { 53 57 try { 58 SAXParserFactory factory = SAXParserFactory.newInstance(); 59 factory.setNamespaceAware(true); 60 factory.setValidating(false); 61 this.reader = factory.newSAXParser().getXMLReader(); 62 this.setEntityResolver(context); 63 this.setErrorHandler(new DraconianErrorHandler()); 64 this.context = context; 65 } catch (ParserConfigurationException exception) { 66 throw new SAXException ("Can't create XML reader instance", exception); 67 } 68 } 69 70 public boolean getFeature(String feature) 71 throws SAXNotRecognizedException , SAXNotSupportedException { 72 return this.reader.getFeature(feature); 73 } 74 75 public void setFeature(String feature, boolean value) 76 throws SAXNotRecognizedException , SAXNotSupportedException { 77 this.reader.setFeature(feature, value); 78 } 79 80 public Object getProperty(String property) 81 throws SAXNotRecognizedException , SAXNotSupportedException { 82 return this.reader.getProperty(property); 83 } 84 85 public void setProperty(String property, Object value) 86 throws SAXNotRecognizedException , SAXNotSupportedException { 87 this.reader.setProperty(property, value); 88 } 89 90 public void setEntityResolver(org.xml.sax.EntityResolver resolver) { 91 this.reader.setEntityResolver(resolver); 92 } 93 94 public org.xml.sax.EntityResolver getEntityResolver() { 95 return this.reader.getEntityResolver(); 96 } 97 98 public void setDTDHandler(DTDHandler handler) { 99 this.reader.setDTDHandler(handler); 100 } 101 102 public DTDHandler getDTDHandler() { 103 return this.reader.getDTDHandler(); 104 } 105 106 public void setContentHandler(ContentHandler handler) { 107 this.reader.setContentHandler(handler); 108 } 109 110 public ContentHandler getContentHandler() { 111 return this.reader.getContentHandler(); 112 } 113 114 public void setErrorHandler(ErrorHandler handler) { 115 this.reader.setErrorHandler(handler); 116 } 117 118 public ErrorHandler getErrorHandler() { 119 return this.reader.getErrorHandler(); 120 } 121 122 public void parse(InputSource source) 123 throws IOException , SAXException { 124 this.context.pushInputSource(source); 125 this.reader.parse(source); 126 this.context.popInputSource(); 127 } 128 129 public void parse(String source) 130 throws IOException , SAXException { 131 this.parse(this.getEntityResolver().resolveEntity(null, source)); 132 } 133 } | Popular Tags |