KickJava   Java API By Example, From Geeks To Geeks.

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


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 TestBed2
66 {
67         
68     public void WeatherTest()
69     {
70     System.out.println("\nWeather.vxml");
71
72     VXMLDocument doc = new VXMLDocument();
73     Vxml vxml = new Vxml("1.0");
74     Form form = new Form("weather_info");
75     Block block = new Block();
76     block.addElement("Welcome to the weather information service.");
77     Field field = new Field("city");
78     Prompt prompt = new Prompt("What city?");
79     Grammar grammar = new Grammar("city.gram","application/x-jsgf");
80     Catch catchtag = new Catch("help");
81     catchtag.addElement("Please speak the city for which you want the weather.");
82     field.addElement(prompt);
83     field.addElement(grammar);
84     field.addElement(catchtag);
85
86     form.addElement(block);
87     form.addElement(field);
88     form.addElement(new Block().addElement(new Submit("/servlet/weather", "city")));
89     vxml.addElement(form);
90
91     doc.addElement(vxml);
92
93     System.out.println(doc.toString());
94     }
95     
96     public void CreditCard()
97     {
98     System.out.println("\nCreditCard.vxml");
99
100     VXMLDocument doc = new VXMLDocument();
101     Vxml vxml = new Vxml("1.0");
102     Form form = new Form("get_card_info");
103     Block block = new Block();
104     block.addElement("We now need your credit card type, number, and expiration date.");
105     form.addElement(block);
106     
107     Field field = new Field("card_type");
108     Prompt prompt1 = new Prompt("What kind of credit card do you have?");
109     Prompt prompt2 = new Prompt("Type of card?");
110     prompt1.setBargein("false");
111     prompt1.setCount("1");
112     prompt2.setCount("2");
113     
114     Grammar grammar = new Grammar();
115     grammar.addElement("visa {visa}");
116     grammar.addElement("| master [card] {mastercard}");
117     grammar.addElement("| amex {amex}");
118     grammar.addElement("| american [express] {amex}");
119     Help help = new Help("Please say Visa, Mastercard, or American Express.");
120     field.addElement(prompt1);
121     field.addElement(prompt2);
122     field.addElement(grammar);
123     field.addElement(help);
124     form.addElement(field);
125
126
127     vxml.addElement(form);
128
129     doc.addElement(vxml);
130
131     System.out.println(doc.toString());
132     }
133     
134     public void MenuTest()
135     {
136     System.out.println("\nMenuTest.vxml");
137
138     VXMLDocument doc = new VXMLDocument();
139     Vxml vxml = new Vxml("1.0");
140     Menu menu1 = new Menu();
141     Property prop = new Property();
142     prop.setInputmodes("dtmf");
143     menu1.addElement(prop);
144     Prompt prompt = new Prompt("For sports press 1, For weather press 2, For Stargazer astrophysics press 3.");
145     menu1.addElement(prompt);
146     menu1.addElement(new Choice("1","http://www.sports.example/vxml/start.vxml"));
147     menu1.addElement(new Choice("2","http://www.weather.example/intro.vxml"));
148     menu1.addElement(new Choice("3","http://www.stargazer.example/voice/astronews.vxml"));
149     vxml.addElement(menu1);
150     
151     Menu menu2 = new Menu("true");
152     menu2.addElement(prop);
153     menu2.addElement(prompt);
154     menu2.addElement(new Choice("http://www.sports.example/vxml/start.vxml"));
155     menu2.addElement(new Choice("http://www.weather.example/intro.vxml"));
156     menu2.addElement(new Choice("http://www.stargazer.example/voice/astronews.vxml"));
157     vxml.addElement(menu2);
158     
159     Menu menu3 = new Menu("true");
160     Prompt prompt2 = new Prompt("Welcome Home");
161     Enumerate enum = new Enumerate();
162     enum.addElement("For ");
163     enum.addElement(new Value("_prompt"));
164     enum.addElement(", press ");
165     enum.addElement(new Value("_dtmf"));
166     prompt2.addElement(enum);
167     menu3.addElement(prompt2);
168     Choice choice1 = new Choice("http://www.sports.example/vxml/start.vxml");
169     Choice choice2 = new Choice("http://www.weather.example/intro.vxml");
170     Choice choice3 = new Choice("http://www.stargazer.example/voice/astronews.vxml");
171     choice1.addElement("sports");
172     choice2.addElement("weather");
173     choice3.addElement("Stargazer astrophysics news");
174     menu3.addElement(choice1);
175     menu3.addElement(choice2);
176     menu3.addElement(choice3);
177
178     vxml.addElement(menu3);
179
180     System.out.println(vxml.toString());
181     }
182
183     public void RepromptTest()
184     {
185     System.out.println("\nRepromptTest.vxml");
186
187     VXMLDocument doc = new VXMLDocument();
188     Vxml vxml = new Vxml("1.0");
189
190     vxml.addElement(new Reprompt());
191
192     doc.addElement(vxml);
193
194     System.out.println(doc.toString());
195     }
196
197     
198     public static void main(String[] args)
199     {
200     TestBed2 tb = new TestBed2();
201     
202     tb.WeatherTest();
203     tb.CreditCard();
204     tb.MenuTest();
205     tb.RepromptTest();
206     }
207 }
208
Popular Tags