1 58 59 package org.enhydra.apache.xerces.jaxp; 60 61 import java.util.Enumeration ; 62 import java.util.Hashtable ; 63 64 import javax.xml.parsers.SAXParserFactory ; 65 66 import org.xml.sax.HandlerBase ; 67 import org.xml.sax.Parser ; 68 import org.xml.sax.SAXException ; 69 import org.xml.sax.SAXNotRecognizedException ; 70 import org.xml.sax.SAXNotSupportedException ; 71 import org.xml.sax.XMLReader ; 72 import org.xml.sax.helpers.XMLReaderAdapter ; 73 74 79 80 84 public class SAXParserImpl extends javax.xml.parsers.SAXParser { 85 private XMLReader xmlReader; 86 private Parser parser = null; 87 88 private boolean validating = false; 89 private boolean namespaceAware = false; 90 91 95 SAXParserImpl(SAXParserFactory spf, Hashtable features) 96 throws SAXException 97 { 98 xmlReader = new org.enhydra.apache.xerces.parsers.SAXParser(); 101 102 validating = spf.isValidating(); 104 String validation = "http://xml.org/sax/features/validation"; 105 106 if (validating) { 110 xmlReader.setErrorHandler(new DefaultValidationErrorHandler()); 111 } 112 113 xmlReader.setFeature(validation, validating); 115 116 namespaceAware = spf.isNamespaceAware(); 120 String namespaces = "http://xml.org/sax/features/namespaces"; 121 xmlReader.setFeature(namespaces, namespaceAware); 122 123 if (namespaceAware == false) { 126 String prefixes = "http://xml.org/sax/features/namespace-prefixes"; 127 xmlReader.setFeature(prefixes, true); 128 } 129 130 setFeatures(features); 131 } 132 133 140 private void setFeatures(Hashtable features) 141 throws SAXNotSupportedException , SAXNotRecognizedException 142 { 143 if (features != null) { 144 for (Enumeration e = features.keys(); e.hasMoreElements();) { 145 String feature = (String )e.nextElement(); 146 boolean value = ((Boolean )features.get(feature)).booleanValue(); 147 xmlReader.setFeature(feature, value); 148 } 149 } 150 } 151 152 public Parser getParser() throws SAXException { 153 if (parser == null) { 154 parser = new XMLReaderAdapter (xmlReader); 156 157 parser.setDocumentHandler(new HandlerBase ()); 160 } 161 return parser; 162 } 163 164 168 public XMLReader getXMLReader() { 169 return xmlReader; 170 } 171 172 public boolean isNamespaceAware() { 173 return namespaceAware; 174 } 175 176 public boolean isValidating() { 177 return validating; 178 } 179 180 184 public void setProperty(String name, Object value) 185 throws SAXNotRecognizedException , SAXNotSupportedException 186 { 187 xmlReader.setProperty(name, value); 188 } 189 190 194 public Object getProperty(String name) 195 throws SAXNotRecognizedException , SAXNotSupportedException 196 { 197 return xmlReader.getProperty(name); 198 } 199 } 200 | Popular Tags |