1 22 23 package org.enhydra.wireless.voicexml; 24 25 import java.util.HashSet ; 26 27 import org.enhydra.apache.xerces.dom.DocumentTypeImpl; 28 import org.enhydra.wireless.voicexml.dom.VoiceXMLDocument; 29 import org.enhydra.wireless.voicexml.dom.xerces.VoiceXMLDOMImplementationImpl; 30 import org.enhydra.xml.xmlc.XMLCError; 31 import org.enhydra.xml.xmlc.dom.XMLCDomFactory; 32 import org.enhydra.xml.xmlc.dom.xerces.XercesDomFactory; 33 import org.w3c.dom.DOMImplementation ; 34 import org.w3c.dom.Document ; 35 import org.w3c.dom.DocumentType ; 36 import org.w3c.dom.Element ; 37 import org.w3c.dom.Node ; 38 39 49 public class VoiceXMLDomFactory extends XercesDomFactory { 50 53 private static String [] URL_ATTRIBUTES = { 54 "next", "application", "base", "fetchaudio", "recsrc", "src", 55 "dest", "classid", "codebase", "data", "archive" 56 }; 57 58 61 private static final HashSet urlAttributes; 62 63 private static final String IMPL_CLASS_SUFFIX = "Impl"; 64 private static final String VOICEXML_IMPLEMENTATION_DOT = "org.enhydra.wireless.voicexml.dom.xerces"; 65 private static final String VOICEXML_INTERFACE_DOT = "org.enhydra.wireless.voicexml.dom"; 66 67 70 static { 71 urlAttributes = new HashSet (URL_ATTRIBUTES.length); 72 for (int idx = 0; idx < URL_ATTRIBUTES.length; idx++) { 73 urlAttributes.add(URL_ATTRIBUTES[idx]); 74 } 75 } 76 77 80 public DocumentType createDocumentType(String qualifiedName, 81 String publicId, 82 String systemId, 83 String internalSubset) { 84 DOMImplementation domImpl = VoiceXMLDOMImplementationImpl.getDOMImplementation(); 85 DocumentTypeImpl docType = 86 (DocumentTypeImpl)domImpl.createDocumentType(qualifiedName, publicId, systemId); 87 docType.setInternalSubset(internalSubset); 88 return docType; 89 } 90 91 94 public Document createDocument(String namespaceURI, 95 String qualifiedName, 96 DocumentType docType) { 97 DOMImplementation domImpl = VoiceXMLDOMImplementationImpl.getDOMImplementation(); 98 return domImpl.createDocument(namespaceURI, qualifiedName, docType); 99 } 100 101 104 public String getMIMEType() { 105 return "text/xml"; 106 } 107 108 111 public String [] getInterfaceNames() { 112 return new String [] {VoiceXMLDocument.class.getName()}; 113 } 114 115 118 public String nodeClassToInterface(Node node) { 119 String ret = null; 120 121 String className = node.getClass().getName(); 122 if (className.startsWith(VOICEXML_IMPLEMENTATION_DOT)) { 123 int suffixIdx = className.lastIndexOf(IMPL_CLASS_SUFFIX); 124 if (suffixIdx < 0) { 125 throw new XMLCError("Class \"" + className 126 + "\" does not have suffix \"" + IMPL_CLASS_SUFFIX 127 + "\" (maybe be mismatch between XMLC code DOM implementation)"); 128 } 129 ret = VOICEXML_INTERFACE_DOT + 130 className.substring(VOICEXML_IMPLEMENTATION_DOT.length(), suffixIdx); 131 } else 132 ret = super.nodeClassToInterface(node); 133 return ret; 134 } 135 136 139 public boolean isURLAttribute(Element element, 140 String attrName) { 141 return urlAttributes.contains(attrName); 142 } 143 } 144
| Popular Tags
|