1 7 8 package org.cyberneko.html.parsers; 9 10 import org.cyberneko.html.HTMLConfiguration; 11 12 import org.apache.xerces.xni.Augmentations; 13 import org.apache.xerces.xni.XNIException; 14 15 import org.w3c.dom.DOMException ; 16 17 24 public class DOMParser 25 26 extends org.apache.xerces.parsers.DOMParser { 27 35 36 40 41 public DOMParser() { 42 super(new HTMLConfiguration()); 43 44 try { 45 setProperty("http://apache.org/xml/properties/dom/document-class-name", 46 "org.apache.html.dom.HTMLDocumentImpl"); 47 } 48 catch (org.xml.sax.SAXNotRecognizedException e) { 49 throw new RuntimeException ("http://apache.org/xml/properties/dom/document-class-name property not recognized"); 50 } 51 catch (org.xml.sax.SAXNotSupportedException e) { 52 throw new RuntimeException ("http://apache.org/xml/properties/dom/document-class-name property not supported"); 53 } 54 58 } 60 64 65 public void doctypeDecl(String root, String pubid, String sysid, 66 Augmentations augs) throws XNIException { 67 68 74 String VERSION = org.apache.xerces.impl.Version.fVersion; 75 boolean okay = true; 76 if (VERSION.startsWith("Xerces-J 2.")) { 77 okay = getParserSubVersion() > 5; 78 } 79 else if (VERSION.startsWith("XML4J")) { 83 okay = false; 84 } 85 86 if (okay) { 88 super.doctypeDecl(root, pubid, sysid, augs); 89 } 90 91 } 93 97 98 private static int getParserSubVersion() { 99 try { 100 String VERSION = org.apache.xerces.impl.Version.fVersion; 101 int index1 = VERSION.indexOf('.') + 1; 102 int index2 = VERSION.indexOf('.', index1); 103 if (index2 == -1) { index2 = VERSION.length(); } 104 return Integer.parseInt(VERSION.substring(index1, index2)); 105 } 106 catch (Exception e) { 107 return -1; 108 } 109 } 111 } | Popular Tags |