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 XHTMLDomFactory 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."; 44 45 private static final String XHTML_INTERFACE_DOT = "org.enhydra.xml.xhtml.dom."; 46 47 private java.util.HashMap ClassNameMap = new java.util.HashMap (); 48 49 53 private static final String [][] CLASS_INTERFACE_MAP = { 54 60 }; 61 62 65 public DocumentType createDocumentType(String qualifiedName, 66 String publicId, 67 String systemId, 68 String internalSubset) { 69 DOMImplementation domImpl = XHTMLDOMImplementationImpl.getHTMLDOMImplementation(); 70 DocumentTypeImpl docType = 71 (DocumentTypeImpl)domImpl.createDocumentType(qualifiedName, publicId, systemId); 72 docType.setInternalSubset(internalSubset); 73 return docType; 74 } 75 76 79 public Document createDocument(String namespaceURI, 80 String qualifiedName, 81 DocumentType docType) { 82 if (qualifiedName == null) { 83 throw new XMLCError("qualifiedName is null for XHTML document;" 84 + " maybe trying to use a HTML parser on XHTML"); 85 } 86 87 DOMImplementation domImpl = XHTMLDOMImplementationImpl.getHTMLDOMImplementation(); 88 return domImpl.createDocument(namespaceURI, qualifiedName, docType); 89 } 90 91 98 public String getMIMEType() { 99 101 return "application/xhtml+xml"; 103 } 104 105 108 public String getBaseClassName() { 109 return HTMLDomFactoryMethods.getBaseClassName(); 110 } 111 112 115 public String [] getInterfaceNames() { 116 return HTMLDomFactoryMethods.getInterfaceNames(); 117 } 118 119 122 public String nodeClassToInterface(Node node) { 123 String className = node.getClass().getName(); 124 125 for (int idx = 0; idx < CLASS_INTERFACE_MAP.length; idx++) { 127 if (className.equals(CLASS_INTERFACE_MAP[idx][0])) { 128 return CLASS_INTERFACE_MAP[idx][1]; 129 } 130 } 131 132 if (className.startsWith(XHTML_IMPLEMENTATION_DOT)) { 133 int suffixIdx = className.lastIndexOf(IMPL_CLASS_SUFFIX); 134 if (suffixIdx < 0) { 135 throw new XMLCError("Class \"" + className 136 + "\" does not have suffix \"" + IMPL_CLASS_SUFFIX 137 + "\" (maybe be mismatch between XMLC code DOM implementation)"); 138 } 139 return XHTML_INTERFACE_DOT + 140 className.substring(XHTML_IMPLEMENTATION_DOT.length(), suffixIdx); 141 142 } else { 143 throw new XMLCError("Can't determine DOM interface for node of class \"" 146 + className 147 + "\" (maybe be mismatch between XMLCDomFactory DOM implementation)"); 148 149 } 150 } 151 152 155 public String [] getElementClassNames(Element element) { 156 return HTMLDomFactoryMethods.getElementClassNames(element); 157 } 158 159 162 public boolean isURLAttribute(Element element, 163 String attrName) { 164 return HTMLDomFactoryMethods.isURLAttribute(element, attrName); 165 } 166 } 167 | Popular Tags |