KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ecs > vxml > TestBed3


1 /*
2  * ====================================================================
3  *
4  * The Apache Software License, Version 1.1
5  *
6  * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
7  * reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution, if
22  * any, must include the following acknowlegement:
23  * "This product includes software developed by the
24  * Apache Software Foundation (http://www.apache.org/)."
25  * Alternately, this acknowlegement may appear in the software itself,
26  * if and wherever such third-party acknowlegements normally appear.
27  *
28  * 4. The names "The Jakarta Project", "Jakarta Element Construction Set",
29  * "Jakarta ECS" , and "Apache Software Foundation" must not be used
30  * to endorse or promote products derived
31  * from this software without prior written permission. For written
32  * permission, please contact apache@apache.org.
33  *
34  * 5. Products derived from this software may not be called "Apache",
35  * "Jakarta Element Construction Set" nor "Jakarta ECS" nor may "Apache"
36  * appear in their names without prior written permission of the Apache Group.
37  *
38  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
39  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
42  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
45  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
46  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
48  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49  * SUCH DAMAGE.
50  * ====================================================================
51  *
52  * This software consists of voluntary contributions made by many
53  * individuals on behalf of the Apache Software Foundation. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  *
57  */

58 package org.apache.ecs.vxml;
59
60 /**
61     This class contains some simple tests of the vxml generation package
62
63     @author Written by <a HREF="mailto:jcarol@us.ibm.com">Carol Jones</a>
64 */

65 public class TestBed3
66 {
67         
68     public void EmptyElements()
69     {
70     System.out.println("\nEmptyElements.vxml");
71
72     VXMLDocument doc = new VXMLDocument();
73     Vxml vxml = new Vxml("1.0");
74
75     vxml.addElement(new Block());
76     vxml.addElement(new Reprompt());
77     vxml.addElement(new Disconnect());
78
79     doc.addElement(vxml);
80
81     System.out.println(doc.toString());
82     }
83
84     public void MiscElements()
85     {
86     System.out.println("\nMiscElements.vxml");
87
88     VXMLDocument doc = new VXMLDocument();
89     Vxml vxml = new Vxml("1.0");
90
91     Initial init = new Initial("bypass_init");
92     init.addElement(new Audio("hello.wav"));
93     init.addElement(new Break("medium"));
94     vxml.addElement(init);
95     
96     Dtmf dtmf = new Dtmf("application/x-jsgf");
97     dtmf.addElement("1 {van} | 2 {choc} | 3 {straw}");
98     vxml.addElement(dtmf);
99     vxml.addElement(new Div("sentence"));
100     vxml.addElement(new Emp("Hello!"));
101     vxml.addElement(new Sayas("currency", "$123.50"));
102     vxml.addElement(new Noinput("I didn't hear anything, please try again"));
103     vxml.addElement(new Nomatch("Nothing matched, try again.", "1"));
104     vxml.addElement(new Error JavaDoc("An Error has occurred"));
105     vxml.addElement(new Throw("nomatch"));
106     org.apache.ecs.vxml.Object obj = new org.apache.ecs.vxml.Object();
107     obj.setName("debit");
108     obj.setClassid("method://credit_card/gather_and_debit");
109     obj.setData("http://www.recordings.example/prompts/credit/jesse.jar");
110     obj.addElement (new Param("amount", "document.amt"));
111     obj.addElement (new Param("vendor", "vendor_num"));
112     vxml.addElement(obj);
113
114
115     doc.addElement(vxml);
116     System.out.println(doc.toString());
117     }
118
119     public void IfTest()
120     {
121     System.out.println("\nIfTest.vxml");
122
123     VXMLDocument doc = new VXMLDocument();
124     Vxml vxml = new Vxml("1.0");
125
126     If iftag = new If("city == 'LA'");
127     iftag.addElement(new Assign("city", "Los Angeles"));
128     iftag.addElement(new Elseif("city == 'Philly'"));
129     iftag.addElement(new Assign("city", "Philadelphia"));
130     iftag.addElement(new Else());
131     iftag.addElement(new Assign("city", "Unknown"));
132     vxml.addElement(iftag);
133
134     doc.addElement(vxml);
135
136     System.out.println(doc.toString());
137     }
138
139     public void ScriptTest()
140     {
141     System.out.println("\nScript.vxml");
142
143     VXMLDocument doc = new VXMLDocument();
144     Vxml vxml = new Vxml("1.0");
145     
146     Script script = new Script();
147     script.addElement("<![CDATA[\n" +
148                       "function factorial(n) { return (n <= 1)? 1 : n * factorial(n-1); }" +
149                       "]]>");
150
151     vxml.addElement(script);
152     doc.addElement(vxml);
153
154     doc.output(System.out);
155     }
156
157
158     public static void main(String JavaDoc[] args)
159     {
160     TestBed3 tb = new TestBed3();
161     
162     tb.EmptyElements();
163     tb.MiscElements();
164     tb.IfTest();
165     tb.ScriptTest();
166     }
167 }
168
Popular Tags