1 28 29 package com.caucho.xml2.jaxp; 30 31 import com.caucho.xml2.XMLReaderImpl; 32 33 import org.xml.sax.Parser ; 34 import org.xml.sax.SAXNotRecognizedException ; 35 import org.xml.sax.XMLReader ; 36 37 import javax.xml.parsers.SAXParser ; 38 import javax.xml.parsers.SAXParserFactory ; 39 40 43 public class SAXParserFactoryImpl extends SAXParserFactory { 44 private int _namespaces = -1; 45 private int _namespacePrefixes = -1; 46 private int _validation = -1; 47 48 51 public SAXParser newSAXParser() 52 { 53 return new XmlSAXParser(); 54 } 55 56 59 public Object getProperty(String key) 60 { 61 return null; 62 } 63 64 67 public void setProperty(String key, Object value) 68 { 69 } 70 71 74 public boolean getFeature(String key) 75 { 76 if (key.equals("http://xml.org/sax/features/namespaces")) 77 return isNamespaceAware(); 78 else if (key.equals("http://xml.org/sax/features/namespace-prefixes")) 79 return isNamespacePrefixes(); 80 else if (key.equals("http://xml.org/sax/features/validation")) 81 return _validation != 0; 82 else 83 return false; 84 } 85 86 89 public void setFeature(String key, boolean value) 90 throws SAXNotRecognizedException 91 { 92 if (key.equals("http://xml.org/sax/features/namespaces")) 93 _namespaces = value ? 1 : 0; 94 else if (key.equals("http://xml.org/sax/features/namespace-prefixes")) 95 _namespacePrefixes = value ? 1 : 0; 96 else if (key.equals("http://xml.org/sax/features/validation")) 97 _validation = value ? 1 : 0; 98 else 99 throw new SAXNotRecognizedException (key); 100 } 101 102 105 public boolean isNamespacePrefixes() 106 { 107 if (_namespacePrefixes >= 0) 108 return _namespacePrefixes == 1; 109 else if (_namespaces >= 0) 110 return _namespaces == 1; 111 else 112 return false; 113 } 114 115 public boolean isNamespaceAware() 116 { 117 if (_namespacePrefixes >= 0) 118 return true; 119 else if (_namespaces >= 0) 120 return _namespaces == 1; 121 else 122 return super.isNamespaceAware(); 123 } 124 125 public class XmlSAXParser extends SAXParser { 126 private XMLReaderImpl _reader; 127 128 XmlSAXParser() 129 { 130 _reader = new XMLReaderImpl(); 131 137 } 138 139 142 public Object getProperty(String name) 143 { 144 return null; 145 } 146 147 153 public void setProperty(String name, Object value) 154 { 155 } 156 157 160 public Parser getParser() 161 { 162 return null; 163 } 164 165 168 public XMLReader getXMLReader() 169 { 170 return _reader; 171 } 172 173 176 public boolean isNamespaceAware() 177 { 178 return SAXParserFactoryImpl.this.isNamespaceAware(); 179 } 180 181 184 public boolean isValidating() 185 { 186 return SAXParserFactoryImpl.this.isValidating(); 187 } 188 } 189 } 190 | Popular Tags |