KickJava   Java API By Example, From Geeks To Geeks.

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


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 TestBed1
66 {
67     
68     public void HelloWorldTest()
69     {
70     System.out.println("\nHelloWorld.vxml");
71
72     VXMLDocument doc = new VXMLDocument();
73     Vxml vxml = new Vxml("1.0");
74     Form form = new Form();
75     Block block = new Block();
76     block.addElement("Hello World!");
77     form.addElement(block);
78     vxml.addElement(form);
79     doc.addElement(vxml);
80
81     System.out.println(doc.toString());
82     }
83     
84     public void DrinkTest()
85     {
86     System.out.println("\nDrink.vxml");
87
88     VXMLDocument doc = new VXMLDocument();
89     Vxml vxml = new Vxml("1.0");
90     Form form = new Form();
91     Field field = new Field("drink");
92     Prompt prompt = new Prompt();
93     prompt.addElement("Would you like coffee, tea, milk, or nothing?");
94     Grammar grammar = new Grammar("drink.gram", "application/x-jsgf");
95     Block block = new Block();
96     block.addElement(new Submit("http://www.drink.example/drink2.asp"));
97     field.addElement(prompt);
98     field.addElement(grammar);
99     form.addElement(field);
100     form.addElement(block);
101     vxml.addElement(form);
102
103     doc.addElement(vxml);
104
105     System.out.println(doc.toString());
106     
107     }
108     
109     public void MetaTest()
110     {
111     System.out.println("\nMeta.vxml");
112
113     VXMLDocument doc = new VXMLDocument();
114     Vxml vxml = new Vxml("1.0");
115     vxml.addElement(new Meta().setAuthor("John Doe"));
116     vxml.addElement(new Meta().setMaintainer("hello-support@hi.example"));
117     vxml.addElement(new Var("hi", "'Hello World!'"));
118     Form form = new Form();
119     Block block = new Block();
120     block.addElement(new Value("hi"));
121     block.addElement(new Goto("#say_goodbye"));
122     form.addElement(block);
123     vxml.addElement(form);
124     Form form2 = new Form("say_goodbye");
125     Block block2 = new Block();
126     block2.addElement("Goodbye!");
127     form2.addElement(block2);
128     vxml.addElement(form2);
129
130     doc.addElement(vxml);
131
132     System.out.println(doc.toString());
133     }
134     
135     public void LinkTest()
136     {
137     System.out.println("\nLink.vxml");
138
139     VXMLDocument doc = new VXMLDocument();
140     Vxml vxml = new Vxml("1.0");
141     Var var = new Var("bye", "'Ciao'");
142     Link link = new Link();
143     link.setNext("operator_xfer.vxml");
144     Grammar grammar = new Grammar();
145     grammar.addElement(" operator ");
146     link.addElement(grammar);
147     vxml.addElement(var);
148     vxml.addElement(link);
149     
150     doc.addElement(vxml);
151
152     System.out.println(doc.toString());
153     }
154     
155     public void ExitTest()
156     {
157     System.out.println("\nExit.vxml");
158
159     VXMLDocument doc = new VXMLDocument();
160     Vxml vxml = new Vxml("1.0");
161     Form form = new Form("say_goodbye");
162     Field field = new Field("answer", "boolean");
163     Prompt prompt = new Prompt();
164     prompt.addElement("Shall we say ");
165     prompt.addElement(new Value("application.bye"));
166     Filled filled = new Filled();
167     If iftag = new If("answer");
168     iftag.addElement(new Exit());
169     filled.addElement(iftag);
170     filled.addElement(new Clear("answer"));
171     
172     field.addElement(prompt);
173     field.addElement(filled);
174     form.addElement(field);
175     vxml.addElement(form);
176
177     doc.addElement(vxml);
178
179     System.out.println(doc.toString());
180     }
181     
182     public void FilledTest()
183     {
184     System.out.println("\nFilled.vxml");
185
186     VXMLDocument doc = new VXMLDocument();
187     Vxml vxml = new Vxml("1.0");
188     Form form = new Form("billing_adjustment");
189     Var var1 = new Var("account_number");
190     Var var2 = new Var("home_phone");
191     Subdialog sub = new Subdialog();
192     sub.setName("accountinfo");
193     sub.setSrc("acct_info.vxml#basic");
194     Filled filled = new Filled();
195     filled.addElement (new Assign("account_number", "accountinfo.acctnum"));
196     filled.addElement (new Assign("home_phone", "accountinfo.acctphone"));
197     sub.addElement(filled);
198     Field field = new Field();
199     field.setName("adjustment_amount");
200     field.setType("currency");
201     Prompt prompt = new Prompt(" What is the value of your account adjustment?");
202     Filled filled2 = new Filled();
203     filled2.addElement(new Submit("/cgi-bin/updateaccount"));
204     field.addElement(prompt);
205     field.addElement(filled2);
206     
207     form.addElement(var1);
208     form.addElement(var2);
209     form.addElement(sub);
210     form.addElement(field);
211     vxml.addElement(form);
212     
213     doc.addElement(vxml);
214
215     System.out.println(doc.toString());
216     }
217     
218     public void ReturnTest()
219     {
220     System.out.println("\nReturn.vxml");
221
222     VXMLDocument doc = new VXMLDocument();
223     Vxml vxml = new Vxml("1.0");
224     Form form = new Form("basic");
225     form.addElement(
226         new Field("acctnum", "digits").addElement(
227                 new Prompt(" What is your account number?")));
228     Field field = new Field("acctphone", "phone");
229     field.addElement(new Prompt(" What is your home telephone number?"));
230     Filled filled = new Filled();
231     filled.addElement(new Return("acctnum acctphone"));
232     field.addElement(filled);
233     form.addElement(field);
234     vxml.addElement(form);
235     
236     doc.addElement(vxml);
237
238     System.out.println(doc.toString());
239     }
240         
241     public static void main(String JavaDoc[] args)
242     {
243     TestBed1 tb = new TestBed1();
244     
245     tb.HelloWorldTest();
246     tb.DrinkTest();
247     tb.MetaTest();
248     tb.LinkTest();
249     tb.ExitTest();
250     tb.FilledTest();
251     tb.ReturnTest();
252     }
253 }
254
Popular Tags