1 22 23 package org.enhydra.xml.xhtml; 24 25 import org.enhydra.apache.xerces.dom.DocumentTypeImpl; 26 import org.enhydra.xml.xhtml.dom.xerces.XHTMLDOMImplementationImpl; 27 import org.enhydra.xml.xmlc.XMLCError; 28 import org.enhydra.xml.xmlc.dom.HTMLDomFactoryMethods; 29 import org.enhydra.xml.xmlc.dom.XMLCDomFactory; 30 import org.enhydra.xml.xmlc.dom.xerces.XercesDomFactory; 31 import org.w3c.dom.DOMImplementation ; 32 import org.w3c.dom.Document ; 33 import org.w3c.dom.DocumentType ; 34 import org.w3c.dom.Element ; 35 import org.w3c.dom.Node ; 36 37 41 public class HTMLDomFactory extends XercesDomFactory implements XMLCDomFactory { 42 private static final String IMPL_CLASS_SUFFIX = "Impl"; 43 private static final String XHTML_IMPLEMENTATION_DOT = "org.enhydra.xml.xhtml.dom.xerces.X"; 44 45 private static final String XHTML_INTERFACE_DOT = "org.w3c.dom.html."; 46 47 private java.util.HashMap ClassNameMap = new java.util.HashMap (); 48 49 53 private static final String [][] CLASS_INTERFACE_MAP = { 54 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLEmElementImpl", "org.w3c.dom.html.HTMLElement"}, 58 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLSmallElementImpl", "org.w3c.dom.html.HTMLElement"}, 59 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLNoframesElementImpl", "org.w3c.dom.html.HTMLElement"}, 60 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLBdoElementImpl", "org.w3c.dom.html.HTMLElement"}, 61 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLDtElementImpl", "org.w3c.dom.html.HTMLElement"}, 62 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLSpanElementImpl", "org.w3c.dom.html.HTMLElement"}, 63 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLStrongElementImpl", "org.w3c.dom.html.HTMLElement"}, 64 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLKbdElementImpl", "org.w3c.dom.html.HTMLElement"}, 65 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLDdElementImpl", "org.w3c.dom.html.HTMLElement"}, 66 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLBigElementImpl", "org.w3c.dom.html.HTMLElement"}, 67 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLCodeElementImpl", "org.w3c.dom.html.HTMLElement"}, 68 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLTbodyElementImpl", "org.w3c.dom.html.HTMLTableSectionElement"}, 69 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLTheadElementImpl", "org.w3c.dom.html.HTMLTableSectionElement"}, 70 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLTfootElementImpl", "org.w3c.dom.html.HTMLTableSectionElement"}, 71 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLUElementImpl", "org.w3c.dom.html.HTMLElement"}, 72 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLSElementImpl", "org.w3c.dom.html.HTMLElement"}, 73 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLIElementImpl", "org.w3c.dom.html.HTMLElement"}, 74 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLBElementImpl", "org.w3c.dom.html.HTMLElement"}, 75 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLTtElementImpl", "org.w3c.dom.html.HTMLElement"}, 76 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLCenterElementImpl", "org.w3c.dom.html.HTMLElement"}, 77 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLSampElementImpl", "org.w3c.dom.html.HTMLElement"}, 78 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLDfnElementImpl", "org.w3c.dom.html.HTMLElement"}, 79 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLNoscriptElementImpl", "org.w3c.dom.html.HTMLElement"}, 80 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLSupElementImpl", "org.w3c.dom.html.HTMLElement"}, 81 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLStrikeElementImpl", "org.w3c.dom.html.HTMLElement"}, 82 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLAcronymElementImpl", "org.w3c.dom.html.HTMLElement"}, 83 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLSubElementImpl", "org.w3c.dom.html.HTMLElement"}, 84 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLCiteElementImpl", "org.w3c.dom.html.HTMLElement"}, 85 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLVarElementImpl", "org.w3c.dom.html.HTMLElement"}, 86 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLAbbrElementImpl", "org.w3c.dom.html.HTMLElement"}, 87 {"org.enhydra.xml.xhtml.dom.xerces.XHTMLAddressElementImpl", "org.w3c.dom.html.HTMLElement"}, 88 }; 89 90 93 public DocumentType createDocumentType(String qualifiedName, 94 String publicId, 95 String systemId, 96 String internalSubset) { 97 DOMImplementation domImpl = XHTMLDOMImplementationImpl.getHTMLDOMImplementation(); 98 DocumentTypeImpl docType = 99 (DocumentTypeImpl)domImpl.createDocumentType(qualifiedName, publicId, systemId); 100 docType.setInternalSubset(internalSubset); 101 return docType; 102 } 103 104 107 public Document createDocument(String namespaceURI, 108 String qualifiedName, 109 DocumentType docType) { 110 if (qualifiedName == null) { 111 throw new XMLCError("qualifiedName is null for XHTML document;" 112 + " maybe trying to use a HTML parser on XHTML"); 113 } 114 115 DOMImplementation domImpl = XHTMLDOMImplementationImpl.getHTMLDOMImplementation(); 116 return domImpl.createDocument(namespaceURI, qualifiedName, docType); 117 } 118 119 126 public String getMIMEType() { 127 129 return "text/html"; 132 } 133 134 137 public String getBaseClassName() { 138 return HTMLDomFactoryMethods.getBaseClassName(); 139 } 140 141 144 public String [] getInterfaceNames() { 145 return HTMLDomFactoryMethods.getInterfaceNames(); 146 } 147 148 151 public String nodeClassToInterface(Node node) { 152 String className = node.getClass().getName(); 153 154 for (int idx = 0; idx < CLASS_INTERFACE_MAP.length; idx++) { 156 if (className.equals(CLASS_INTERFACE_MAP[idx][0])) { 157 return CLASS_INTERFACE_MAP[idx][1]; 158 } 159 } 160 161 if (className.startsWith(XHTML_IMPLEMENTATION_DOT)) { 162 int suffixIdx = className.lastIndexOf(IMPL_CLASS_SUFFIX); 163 if (suffixIdx < 0) { 164 throw new XMLCError("Class \"" + className 165 + "\" does not have suffix \"" + IMPL_CLASS_SUFFIX 166 + "\" (maybe be mismatch between XMLC code DOM implementation)"); 167 } 168 return XHTML_INTERFACE_DOT + 169 className.substring(XHTML_IMPLEMENTATION_DOT.length(), suffixIdx); 170 171 } else { 172 throw new XMLCError("Can't determine DOM interface for node of class \"" 175 + className 176 + "\" (maybe be mismatch between XMLCDomFactory DOM implementation)"); 177 178 } 179 } 180 181 184 public String [] getElementClassNames(Element element) { 185 return HTMLDomFactoryMethods.getElementClassNames(element); 186 } 187 188 191 public boolean isURLAttribute(Element element, 192 String attrName) { 193 return HTMLDomFactoryMethods.isURLAttribute(element, attrName); 194 } 195 } 196 | Popular Tags |