KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > wireless > voicexml > VoiceXMLDomFactory


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Original Code is DigitalSesame
15  * Portions created by DigitalSesame are Copyright (C) 1997-2000 DigitalSesame
16  * All Rights Reserved.
17  *
18  * Contributor(s):
19  *
20  * $Id: VoiceXMLDomFactory.java,v 1.2 2005/01/26 08:28:45 jkjome Exp $
21  */

22
23 package org.enhydra.wireless.voicexml;
24
25 import java.util.HashSet JavaDoc;
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 JavaDoc;
34 import org.w3c.dom.Document JavaDoc;
35 import org.w3c.dom.DocumentType JavaDoc;
36 import org.w3c.dom.Element JavaDoc;
37 import org.w3c.dom.Node JavaDoc;
38
39 /**
40  * XMLC DOM factory for creating VoiceXML-specified DocumentType and Document
41  * objects. Specifying this class as the <code>XMLCDomFctory</code> to xmlc
42  * will produce XMLC document class that are <code>VoiceXMLDocument</code> classes.
43  * This is specified using:
44  *
45  * <pre>
46  * xmlc&nbsp;-dom-factory&nbsp;org.enhydra.wireless.voicexml.VoiceXMLDomFactory
47  * </pre>
48  */

49 public class VoiceXMLDomFactory extends XercesDomFactory {
50     /**
51      * XHTML URL attributes.
52      */

53     private static String JavaDoc[] URL_ATTRIBUTES = {
54         "next", "application", "base", "fetchaudio", "recsrc", "src",
55         "dest", "classid", "codebase", "data", "archive"
56     };
57
58     /**
59      * HashSet built from URL_ATTRIBUTES.
60      */

61     private static final HashSet JavaDoc urlAttributes;
62     
63     private static final String JavaDoc IMPL_CLASS_SUFFIX = "Impl";
64     private static final String JavaDoc VOICEXML_IMPLEMENTATION_DOT = "org.enhydra.wireless.voicexml.dom.xerces";
65     private static final String JavaDoc VOICEXML_INTERFACE_DOT = "org.enhydra.wireless.voicexml.dom";
66
67     /**
68      * Class initializer.
69      */

70     static {
71         urlAttributes = new HashSet JavaDoc(URL_ATTRIBUTES.length);
72         for (int idx = 0; idx < URL_ATTRIBUTES.length; idx++) {
73             urlAttributes.add(URL_ATTRIBUTES[idx]);
74         }
75     }
76         
77     /**
78      * @see XMLCDomFactory#createDocumentType
79      */

80     public DocumentType JavaDoc createDocumentType(String JavaDoc qualifiedName,
81                                            String JavaDoc publicId,
82                                            String JavaDoc systemId,
83                                            String JavaDoc internalSubset) {
84         DOMImplementation JavaDoc domImpl = VoiceXMLDOMImplementationImpl.getDOMImplementation();
85         DocumentTypeImpl docType =
86             (DocumentTypeImpl)domImpl.createDocumentType(qualifiedName, publicId, systemId);
87         docType.setInternalSubset(internalSubset);
88         return docType;
89     }
90
91     /**
92      * @see XMLCDomFactory#createDocument
93      */

94     public Document createDocument(String JavaDoc namespaceURI,
95                                    String JavaDoc qualifiedName,
96                                    DocumentType JavaDoc docType) {
97     DOMImplementation JavaDoc domImpl = VoiceXMLDOMImplementationImpl.getDOMImplementation();
98     return domImpl.createDocument(namespaceURI, qualifiedName, docType);
99     }
100
101     /**
102      * @see XMLCDomFactory#getMIMEType
103      */

104     public String JavaDoc getMIMEType() {
105         return "text/xml";
106     }
107
108     /**
109      * @see XMLCDomFactory#getInterfaceNames
110      */

111     public String JavaDoc[] getInterfaceNames() {
112         return new String JavaDoc[] {VoiceXMLDocument.class.getName()};
113     }
114
115     /**
116      * @see XMLCDomFactory#nodeClassToInterface
117      */

118     public String JavaDoc nodeClassToInterface(Node JavaDoc node) {
119     String JavaDoc ret = null;
120
121         String JavaDoc 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     /**
137      * @see XMLCDomFactory#isURLAttribute
138      */

139     public boolean isURLAttribute(Element JavaDoc element,
140                                   String JavaDoc attrName) {
141         return urlAttributes.contains(attrName);
142     }
143 }
144
Popular Tags