1 7 8 package org.cyberneko.html.filters; 9 10 import java.lang.reflect.InvocationTargetException ; 11 import java.lang.reflect.Method ; 12 13 import org.cyberneko.html.HTMLComponent; 14 15 import org.apache.xerces.xni.Augmentations; 16 import org.apache.xerces.xni.NamespaceContext; 17 import org.apache.xerces.xni.QName; 18 import org.apache.xerces.xni.XMLAttributes; 19 import org.apache.xerces.xni.XMLDocumentHandler; 20 import org.apache.xerces.xni.XMLLocator; 21 import org.apache.xerces.xni.XMLResourceIdentifier; 22 import org.apache.xerces.xni.XMLString; 23 import org.apache.xerces.xni.XNIException; 24 import org.apache.xerces.xni.parser.XMLComponentManager; 25 import org.apache.xerces.xni.parser.XMLConfigurationException; 26 import org.apache.xerces.xni.parser.XMLDocumentFilter; 27 import org.apache.xerces.xni.parser.XMLDocumentSource; 28 29 38 public class DefaultFilter 39 implements XMLDocumentFilter, HTMLComponent { 40 41 45 46 protected XMLDocumentHandler fDocumentHandler; 47 48 49 protected XMLDocumentSource fDocumentSource; 50 51 55 56 public void setDocumentHandler(XMLDocumentHandler handler) { 57 fDocumentHandler = handler; 58 } 60 62 63 public XMLDocumentHandler getDocumentHandler() { 64 return fDocumentHandler; 65 } 67 68 public void setDocumentSource(XMLDocumentSource source) { 69 fDocumentSource = source; 70 } 72 73 public XMLDocumentSource getDocumentSource() { 74 return fDocumentSource; 75 } 77 81 83 84 public void startDocument(XMLLocator locator, String encoding, 85 NamespaceContext nscontext, Augmentations augs) 86 throws XNIException { 87 if (fDocumentHandler != null) { 88 try { 89 Class cls = fDocumentHandler.getClass(); 93 Class [] types = { 94 XMLLocator.class, String .class, 95 NamespaceContext.class, Augmentations.class 96 }; 97 Method method = cls.getMethod("startDocument", types); 98 Object [] params = { 99 locator, encoding, 100 nscontext, augs 101 }; 102 method.invoke(fDocumentHandler, params); 103 } 104 catch (IllegalAccessException e) { 105 throw new XNIException(e); 106 } 107 catch (InvocationTargetException e) { 108 throw new XNIException(e); 109 } 110 catch (NoSuchMethodException e) { 111 try { 112 Class cls = fDocumentHandler.getClass(); 116 Class [] types = { 117 XMLLocator.class, String .class, Augmentations.class 118 }; 119 Method method = cls.getMethod("startDocument", types); 120 Object [] params = { 121 locator, encoding, augs 122 }; 123 method.invoke(fDocumentHandler, params); 124 } 125 catch (NoSuchMethodException ex) { 126 throw new XNIException(ex); 128 } 129 catch (IllegalAccessException ex) { 130 throw new XNIException(ex); 132 } 133 catch (InvocationTargetException ex) { 134 throw new XNIException(ex); 136 } 137 } 138 } 139 } 141 143 144 public void xmlDecl(String version, String encoding, String standalone, Augmentations augs) 145 throws XNIException { 146 if (fDocumentHandler != null) { 147 fDocumentHandler.xmlDecl(version, encoding, standalone, augs); 148 } 149 } 151 152 public void doctypeDecl(String root, String publicId, String systemId, Augmentations augs) 153 throws XNIException { 154 if (fDocumentHandler != null) { 155 fDocumentHandler.doctypeDecl(root, publicId, systemId, augs); 156 } 157 } 159 160 public void comment(XMLString text, Augmentations augs) 161 throws XNIException { 162 if (fDocumentHandler != null) { 163 fDocumentHandler.comment(text, augs); 164 } 165 } 167 168 public void processingInstruction(String target, XMLString data, Augmentations augs) 169 throws XNIException { 170 if (fDocumentHandler != null) { 171 fDocumentHandler.processingInstruction(target, data, augs); 172 } 173 } 175 176 public void startElement(QName element, XMLAttributes attributes, Augmentations augs) 177 throws XNIException { 178 if (fDocumentHandler != null) { 179 fDocumentHandler.startElement(element, attributes, augs); 180 } 181 } 183 184 public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) 185 throws XNIException { 186 if (fDocumentHandler != null) { 187 fDocumentHandler.emptyElement(element, attributes, augs); 188 } 189 } 191 192 public void characters(XMLString text, Augmentations augs) 193 throws XNIException { 194 if (fDocumentHandler != null) { 195 fDocumentHandler.characters(text, augs); 196 } 197 } 199 200 public void ignorableWhitespace(XMLString text, Augmentations augs) 201 throws XNIException { 202 if (fDocumentHandler != null) { 203 fDocumentHandler.ignorableWhitespace(text, augs); 204 } 205 } 207 208 public void startGeneralEntity(String name, XMLResourceIdentifier id, String encoding, Augmentations augs) 209 throws XNIException { 210 if (fDocumentHandler != null) { 211 fDocumentHandler.startGeneralEntity(name, id, encoding, augs); 212 } 213 } 215 216 public void textDecl(String version, String encoding, Augmentations augs) 217 throws XNIException { 218 if (fDocumentHandler != null) { 219 fDocumentHandler.textDecl(version, encoding, augs); 220 } 221 } 223 224 public void endGeneralEntity(String name, Augmentations augs) 225 throws XNIException { 226 if (fDocumentHandler != null) { 227 fDocumentHandler.endGeneralEntity(name, augs); 228 } 229 } 231 232 public void startCDATA(Augmentations augs) throws XNIException { 233 if (fDocumentHandler != null) { 234 fDocumentHandler.startCDATA(augs); 235 } 236 } 238 239 public void endCDATA(Augmentations augs) throws XNIException { 240 if (fDocumentHandler != null) { 241 fDocumentHandler.endCDATA(augs); 242 } 243 } 245 246 public void endElement(QName element, Augmentations augs) 247 throws XNIException { 248 if (fDocumentHandler != null) { 249 fDocumentHandler.endElement(element, augs); 250 } 251 } 253 254 public void endDocument(Augmentations augs) throws XNIException { 255 if (fDocumentHandler != null) { 256 fDocumentHandler.endDocument(augs); 257 } 258 } 260 262 263 public void startDocument(XMLLocator locator, String encoding, Augmentations augs) 264 throws XNIException { 265 startDocument(locator, encoding, null, augs); 266 } 268 269 public void startPrefixMapping(String prefix, String uri, Augmentations augs) 270 throws XNIException { 271 if (fDocumentHandler != null) { 272 Class cls = fDocumentHandler.getClass(); 273 Class [] types = { String .class, String .class, Augmentations.class }; 274 try { 275 Method method = cls.getMethod("startPrefixMapping", types); 276 Object [] args = { prefix, uri, augs }; 277 method.invoke(fDocumentHandler, args); 278 } 279 catch (NoSuchMethodException e) { 280 } 282 catch (IllegalAccessException e) { 283 } 285 catch (InvocationTargetException e) { 286 } 288 } 289 } 291 292 public void endPrefixMapping(String prefix, Augmentations augs) 293 throws XNIException { 294 if (fDocumentHandler != null) { 295 Class cls = fDocumentHandler.getClass(); 296 Class [] types = { String .class, Augmentations.class }; 297 try { 298 Method method = cls.getMethod("endPrefixMapping", types); 299 Object [] args = { prefix, augs }; 300 method.invoke(fDocumentHandler, args); 301 } 302 catch (NoSuchMethodException e) { 303 } 305 catch (IllegalAccessException e) { 306 } 308 catch (InvocationTargetException e) { 309 } 311 } 312 } 314 318 323 public String [] getRecognizedFeatures() { 324 return null; 325 } 327 332 public Boolean getFeatureDefault(String featureId) { 333 return null; 334 } 336 341 public String [] getRecognizedProperties() { 342 return null; 343 } 345 350 public Object getPropertyDefault(String propertyId) { 351 return null; 352 } 354 363 public void reset(XMLComponentManager componentManager) 364 throws XMLConfigurationException { 365 } 367 383 public void setFeature(String featureId, boolean state) 384 throws XMLConfigurationException { 385 } 387 403 public void setProperty(String propertyId, Object value) 404 throws XMLConfigurationException { 405 } 407 411 415 protected static String [] merge(String [] array1, String [] array2) { 416 417 if (array1 == array2) { 419 return array1; 420 } 421 if (array1 == null) { 422 return array2; 423 } 424 if (array2 == null) { 425 return array1; 426 } 427 428 String [] array3 = new String [array1.length + array2.length]; 430 System.arraycopy(array1, 0, array3, 0, array1.length); 431 System.arraycopy(array2, 0, array3, array1.length, array2.length); 432 433 return array3; 434 435 } 437 } | Popular Tags |