1 22 23 package org.enhydra.wireless.wml; 24 25 import java.util.HashSet ; 26 import java.util.StringTokenizer ; 27 28 import org.enhydra.apache.xerces.dom.DocumentTypeImpl; 29 import org.enhydra.wireless.wml.dom.WMLDocument; 30 import org.enhydra.wireless.wml.dom.xerces.WMLDOMImplementationImpl; 31 import org.enhydra.xml.xmlc.XMLCError; 32 import org.enhydra.xml.xmlc.dom.XMLCDomFactory; 33 import org.enhydra.xml.xmlc.dom.xerces.XercesDomFactory; 34 import org.w3c.dom.DOMImplementation ; 35 import org.w3c.dom.Document ; 36 import org.w3c.dom.DocumentType ; 37 import org.w3c.dom.Element ; 38 import org.w3c.dom.Node ; 39 40 50 public class WMLDomFactory extends XercesDomFactory { 51 54 private static String [] URL_ATTRIBUTES = { 55 "onenterforward", "onenterbackward", 56 "ontimer", "href", 57 "onpick", "src" 58 }; 59 60 63 private static final HashSet urlAttributes; 64 65 66 private static final String IMPL_CLASS_SUFFIX = "Impl"; 67 private static final String WML_IMPLEMENTATION_DOT = "org.enhydra.wireless.wml.dom.xerces"; 68 private static final String WML_INTERFACE_DOT = "org.enhydra.wireless.wml.dom"; 69 70 73 static { 74 urlAttributes = new HashSet (URL_ATTRIBUTES.length); 75 for (int idx = 0; idx < URL_ATTRIBUTES.length; idx++) { 76 urlAttributes.add(URL_ATTRIBUTES[idx]); 77 } 78 } 79 80 83 public DocumentType createDocumentType(String qualifiedName, 84 String publicId, 85 String systemId, 86 String internalSubset) { 87 DOMImplementation domImpl = WMLDOMImplementationImpl.getDOMImplementation(); 88 DocumentTypeImpl docType = (DocumentTypeImpl)domImpl.createDocumentType(qualifiedName, publicId, systemId); 89 docType.setInternalSubset(internalSubset); 90 return docType; 91 } 92 93 96 public Document createDocument(String namespaceURI, 97 String qualifiedName, 98 DocumentType docType) { 99 DOMImplementation domImpl = WMLDOMImplementationImpl.getDOMImplementation(); 100 Document doc = domImpl.createDocument(namespaceURI, qualifiedName, 101 docType); 102 return doc; 103 } 104 105 108 public String getMIMEType() { 109 return "text/vnd.wap.wml"; 110 } 111 112 115 public String [] getInterfaceNames() { 116 return new String [] {WMLDocument.class.getName()}; 117 } 118 119 122 public String nodeClassToInterface(Node node) { 123 String ret = null; 124 125 String className = node.getClass().getName(); 126 if (className.startsWith(WML_IMPLEMENTATION_DOT)) { 127 int suffixIdx = className.lastIndexOf(IMPL_CLASS_SUFFIX); 128 if (suffixIdx < 0) { 129 throw new XMLCError("Class \"" + className 130 + "\" does not have suffix \"" + IMPL_CLASS_SUFFIX 131 + "\" (maybe be mismatch between XMLC code DOM implementation)"); 132 } 133 ret = WML_INTERFACE_DOT + 134 className.substring(WML_IMPLEMENTATION_DOT.length(), suffixIdx); 135 } else 136 ret = super.nodeClassToInterface(node); 137 return ret; 138 } 139 140 143 public String [] getElementClassNames(Element elem) { 144 String classNames = elem.getAttribute("class"); 145 if ((classNames == null) || (classNames.length() ==0)) { 146 return null; 147 } 148 149 StringTokenizer tokens = new StringTokenizer (classNames); 151 String [] names = new String [tokens.countTokens()]; 152 for (int idx = 0; idx < names.length; idx++) { 153 names[idx] = tokens.nextToken(); 154 } 155 return names; 156 } 157 158 161 public boolean isURLAttribute(Element element, 162 String attrName) { 163 return urlAttributes.contains(attrName); 164 } 165 } 166
| Popular Tags
|