1 29 30 package com.caucho.xml.parsers; 31 32 import com.caucho.xml.Xml; 33 import com.caucho.xml.XmlParser; 34 35 import org.xml.sax.Parser ; 36 import org.xml.sax.SAXNotRecognizedException ; 37 import org.xml.sax.XMLReader ; 38 39 import javax.xml.parsers.SAXParser ; 40 import javax.xml.parsers.SAXParserFactory ; 41 42 45 public class XmlSAXParserFactory extends SAXParserFactory { 46 private int _namespaces = -1; 47 private int _namespacePrefixes = -1; 48 private int _validation = -1; 49 50 public XmlSAXParserFactory() 51 { 52 } 53 54 57 public SAXParser newSAXParser() 58 { 59 return new XmlSAXParser(this); 60 } 61 62 public Object getProperty(String key) 63 { 64 return null; 65 } 66 67 public void setProperty(String key, Object value) 68 { 69 } 70 71 public boolean getFeature(String key) 72 { 73 if (key.equals("http://xml.org/sax/features/namespaces")) 74 return isNamespaceAware(); 75 else if (key.equals("http://xml.org/sax/features/namespace-prefixes")) 76 return isNamespacePrefixes(); 77 else if (key.equals("http://xml.org/sax/features/validation")) 78 return _validation != 0; 79 else 80 return false; 81 } 82 83 public void setFeature(String key, boolean value) 84 throws SAXNotRecognizedException 85 { 86 if (key.equals("http://xml.org/sax/features/namespaces")) 87 _namespaces = value ? 1 : 0; 88 else if (key.equals("http://xml.org/sax/features/namespace-prefixes")) 89 _namespacePrefixes = value ? 1 : 0; 90 else if (key.equals("http://xml.org/sax/features/validation")) 91 _validation = value ? 1 : 0; 92 else 93 throw new SAXNotRecognizedException (key); 94 } 95 96 public boolean isNamespacePrefixes() 97 { 98 if (_namespacePrefixes >= 0) 99 return _namespacePrefixes == 1; 100 else if (_namespaces >= 0) 101 return _namespaces == 1; 102 else 103 return false; 104 } 105 106 public boolean isNamespaceAware() 107 { 108 if (_namespacePrefixes >= 0) 109 return true; 110 else if (_namespaces >= 0) 111 return _namespaces == 1; 112 else 113 return super.isNamespaceAware(); 114 } 115 116 public class XmlSAXParser extends SAXParser { 117 private XmlSAXParserFactory _factory; 118 private XmlParser _parser; 119 120 XmlSAXParser(XmlSAXParserFactory factory) 121 { 122 _factory = factory; 123 _parser = new Xml(); 124 _parser.setNamespaceAware(_factory.isNamespaceAware()); 125 _parser.setNamespacePrefixes(_factory.isNamespacePrefixes()); 126 _parser.setValidating(true); 128 } 129 130 public Object getProperty(String key) 131 { 132 return null; 133 } 134 135 public void setProperty(String key, Object value) 136 { 137 } 138 139 public Parser getParser() 140 { 141 return _parser; 142 } 143 144 public XMLReader getXMLReader() 145 { 146 return _parser; 147 } 148 149 152 public boolean isNamespaceAware() 153 { 154 return _factory.isNamespaceAware(); 155 } 156 157 160 public void setNamespaceAware(boolean isAware) 161 { 162 _factory.setNamespaceAware(isAware); 163 } 164 165 168 public boolean isValidating() 169 { 170 return _factory.isValidating(); 171 } 172 173 176 public void setValidating(boolean isValidating) 177 { 178 _factory.setValidating(isValidating); 179 } 180 } 181 } 182 | Popular Tags |