/* * Copyright (c) 2000 The Java Apache Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the Java Apache * Project. " * * 4. The names "Java Apache Element Construction Set", "Java Apache ECS" and * "Java Apache Project" must not be used to endorse or promote products * derived from this software without prior written permission. * * 5. Products derived from this software may not be called * "Java Apache Element Construction Set" nor "Java Apache ECS" appear * in their names without prior written permission of the * Java Apache Project. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the Java Apache * Project. " * * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JAVA APACHE PROJECT OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many * individuals on behalf of the Java Apache Project. For more information * on the Java Apache Project please see . * */ import org.apache.ecs.vxml.*; import org.apache.ecs.html.Comment; /** This class contains some simple tests of the vxml generation package @author Written by Carol Jones */ public class VXMLTestBed { public void HelloWorldTest() { System.out.println("\n" + new org.apache.ecs.html.Comment("HelloWorld.vxml")); VXMLDocument doc = new VXMLDocument(); Vxml vxml = new Vxml("1.0"); Form form = new Form(); Block block = new Block(); block.addElement("Hello World!"); form.addElement(block); vxml.addElement(form); doc.addElement(vxml); System.out.println(doc.toString()); } public void DrinkTest() { System.out.println("\n" + new org.apache.ecs.html.Comment("Drink.vxml")); VXMLDocument doc = new VXMLDocument(); Vxml vxml = new Vxml("1.0"); Form form = new Form(); Field field = new Field("drink"); Prompt prompt = new Prompt(); prompt.addElement("Would you like coffee, tea, milk, or nothing?"); Grammar grammar = new Grammar("drink.gram", "application/x-jsgf"); Block block = new Block(); block.addElement(new Submit("http://www.drink.example/drink2.asp")); field.addElement(prompt); field.addElement(grammar); form.addElement(field); form.addElement(block); vxml.addElement(form); doc.addElement(vxml); System.out.println(doc.toString()); } public void MetaTest() { System.out.println("\n" + new org.apache.ecs.html.Comment("Meta.vxml")); VXMLDocument doc = new VXMLDocument(); Vxml vxml = new Vxml("1.0"); vxml.addElement(new Meta().setAuthor("John Doe")); vxml.addElement(new Meta().setMaintainer("hello-support@hi.example")); vxml.addElement(new Var("hi", "'Hello World!'")); Form form = new Form(); Block block = new Block(); block.addElement(new Value("hi")); block.addElement(new Goto("#say_goodbye")); form.addElement(block); vxml.addElement(form); Form form2 = new Form("say_goodbye"); Block block2 = new Block(); block2.addElement("Goodbye!"); form2.addElement(block2); vxml.addElement(form2); doc.addElement(vxml); System.out.println(doc.toString()); } public void LinkTest() { System.out.println("\n" + new org.apache.ecs.html.Comment("Link.vxml")); VXMLDocument doc = new VXMLDocument(); Vxml vxml = new Vxml("1.0"); Var var = new Var("bye", "'Ciao'"); Link link = new Link(); link.setNext("operator_xfer.vxml"); Grammar grammar = new Grammar(); grammar.addElement(" operator "); link.addElement(grammar); vxml.addElement(var); vxml.addElement(link); doc.addElement(vxml); System.out.println(doc.toString()); } public void ExitTest() { System.out.println("\n" + new org.apache.ecs.html.Comment("Exit.vxml")); VXMLDocument doc = new VXMLDocument(); Vxml vxml = new Vxml("1.0"); Form form = new Form("say_goodbye"); Field field = new Field("answer", "boolean"); Prompt prompt = new Prompt(); prompt.addElement("Shall we say "); prompt.addElement(new Value("application.bye")); Filled filled = new Filled(); If iftag = new If("answer"); iftag.addElement(new Exit()); filled.addElement(iftag); filled.addElement(new Clear("answer")); field.addElement(prompt); field.addElement(filled); form.addElement(field); vxml.addElement(form); doc.addElement(vxml); System.out.println(doc.toString()); } public void FilledTest() { System.out.println("\n" + new org.apache.ecs.html.Comment("Filled.vxml")); VXMLDocument doc = new VXMLDocument(); Vxml vxml = new Vxml("1.0"); Form form = new Form("billing_adjustment"); Var var1 = new Var("account_number"); Var var2 = new Var("home_phone"); Subdialog sub = new Subdialog(); sub.setName("accountinfo"); sub.setSrc("acct_info.vxml#basic"); Filled filled = new Filled(); filled.addElement (new Assign("account_number", "accountinfo.acctnum")); filled.addElement (new Assign("home_phone", "accountinfo.acctphone")); sub.addElement(filled); Field field = new Field(); field.setName("adjustment_amount"); field.setType("currency"); Prompt prompt = new Prompt(" What is the value of your account adjustment?"); Filled filled2 = new Filled(); filled2.addElement(new Submit("/cgi-bin/updateaccount")); field.addElement(prompt); field.addElement(filled2); form.addElement(var1); form.addElement(var2); form.addElement(sub); form.addElement(field); vxml.addElement(form); doc.addElement(vxml); System.out.println(doc.toString()); } public void ReturnTest() { System.out.println("\n" + new org.apache.ecs.html.Comment("Return.vxml")); VXMLDocument doc = new VXMLDocument(); Vxml vxml = new Vxml("1.0"); Form form = new Form("basic"); form.addElement( new Field("acctnum", "digits").addElement( new Prompt(" What is your account number?"))); Field field = new Field("acctphone", "phone"); field.addElement(new Prompt(" What is your home telephone number?")); Filled filled = new Filled(); filled.addElement(new Return("acctnum acctphone")); field.addElement(filled); form.addElement(field); vxml.addElement(form); doc.addElement(vxml); System.out.println(doc.toString()); } public void WeatherTest() { System.out.println("\n" + new org.apache.ecs.html.Comment("Weather.vxml")); VXMLDocument doc = new VXMLDocument(); Vxml vxml = new Vxml("1.0"); Form form = new Form("weather_info"); Block block = new Block(); block.addElement("Welcome to the weather information service."); Field field = new Field("city"); Prompt prompt = new Prompt("What city?"); Grammar grammar = new Grammar("city.gram","application/x-jsgf"); Catch catchtag = new Catch("help"); catchtag.addElement("Please speak the city for which you want the weather."); field.addElement(prompt); field.addElement(grammar); field.addElement(catchtag); form.addElement(block); form.addElement(field); form.addElement(new Block().addElement(new Submit("/servlet/weather", "city"))); vxml.addElement(form); doc.addElement(vxml); System.out.println(doc.toString()); } public void CreditCard() { System.out.println("\n" + new org.apache.ecs.html.Comment("CreditCard.vxml")); VXMLDocument doc = new VXMLDocument(); Vxml vxml = new Vxml("1.0"); Form form = new Form("get_card_info"); Block block = new Block(); block.addElement("We now need your credit card type, number, and expiration date."); form.addElement(block); Field field = new Field("card_type"); Prompt prompt1 = new Prompt("What kind of credit card do you have?"); Prompt prompt2 = new Prompt("Type of card?"); prompt1.setBargein("false"); prompt1.setCount("1"); prompt2.setCount("2"); Grammar grammar = new Grammar(); grammar.addElement("visa {visa}"); grammar.addElement("| master [card] {mastercard}"); grammar.addElement("| amex {amex}"); grammar.addElement("| american [express] {amex}"); Help help = new Help("Please say Visa, Mastercard, or American Express."); field.addElement(prompt1); field.addElement(prompt2); field.addElement(grammar); field.addElement(help); form.addElement(field); vxml.addElement(form); doc.addElement(vxml); System.out.println(doc.toString()); } public void MenuTest() { System.out.println("\n" + new org.apache.ecs.html.Comment("MenuTest.vxml")); VXMLDocument doc = new VXMLDocument(); Vxml vxml = new Vxml("1.0"); Menu menu1 = new Menu(); Property prop = new Property(); prop.setInputmodes("dtmf"); menu1.addElement(prop); Prompt prompt = new Prompt("For sports press 1, For weather press 2, For Stargazer astrophysics press 3."); menu1.addElement(prompt); menu1.addElement(new Choice("1","http://www.sports.example/vxml/start.vxml")); menu1.addElement(new Choice("2","http://www.weather.example/intro.vxml")); menu1.addElement(new Choice("3","http://www.stargazer.example/voice/astronews.vxml")); vxml.addElement(menu1); Menu menu2 = new Menu("true"); menu2.addElement(prop); menu2.addElement(prompt); menu2.addElement(new Choice("http://www.sports.example/vxml/start.vxml")); menu2.addElement(new Choice("http://www.weather.example/intro.vxml")); menu2.addElement(new Choice("http://www.stargazer.example/voice/astronews.vxml")); vxml.addElement(menu2); Menu menu3 = new Menu("true"); Prompt prompt2 = new Prompt("Welcome Home"); Enumerate enum = new Enumerate(); enum.addElement("For "); enum.addElement(new Value("_prompt")); enum.addElement(", press "); enum.addElement(new Value("_dtmf")); prompt2.addElement(enum); menu3.addElement(prompt2); Choice choice1 = new Choice("http://www.sports.example/vxml/start.vxml"); Choice choice2 = new Choice("http://www.weather.example/intro.vxml"); Choice choice3 = new Choice("http://www.stargazer.example/voice/astronews.vxml"); choice1.addElement("sports"); choice2.addElement("weather"); choice3.addElement("Stargazer astrophysics news"); menu3.addElement(choice1); menu3.addElement(choice2); menu3.addElement(choice3); vxml.addElement(menu3); System.out.println(vxml.toString()); } public void RepromptTest() { System.out.println("\n" + new org.apache.ecs.html.Comment("RepromptTest.vxml")); VXMLDocument doc = new VXMLDocument(); Vxml vxml = new Vxml("1.0"); vxml.addElement(new Reprompt()); doc.addElement(vxml); System.out.println(doc.toString()); } public void EmptyElements() { System.out.println("\n" + new org.apache.ecs.html.Comment("EmptyElements.vxml")); VXMLDocument doc = new VXMLDocument(); Vxml vxml = new Vxml("1.0"); vxml.addElement(new Block()); vxml.addElement(new Reprompt()); vxml.addElement(new Disconnect()); doc.addElement(vxml); System.out.println(doc.toString()); } public void MiscElements() { System.out.println("\n" + new org.apache.ecs.html.Comment("MiscElements.vxml")); VXMLDocument doc = new VXMLDocument(); Vxml vxml = new Vxml("1.0"); Initial init = new Initial("bypass_init"); init.addElement(new Audio("hello.wav")); init.addElement(new Break("medium")); vxml.addElement(init); Dtmf dtmf = new Dtmf("application/x-jsgf"); dtmf.addElement("1 {van} | 2 {choc} | 3 {straw}"); vxml.addElement(dtmf); vxml.addElement(new Div("sentence")); vxml.addElement(new Emp("Hello!")); vxml.addElement(new Sayas("currency", "$123.50")); vxml.addElement(new Noinput("I didn't hear anything, please try again")); vxml.addElement(new Nomatch("Nothing matched, try again.", "1")); vxml.addElement(new org.apache.ecs.vxml.Error("An Error has occurred")); vxml.addElement(new Throw("nomatch")); org.apache.ecs.vxml.Object obj = new org.apache.ecs.vxml.Object(); obj.setName("debit"); obj.setClassid("method://credit_card/gather_and_debit"); obj.setData("http://www.recordings.example/prompts/credit/jesse.jar"); obj.addElement (new Param("amount", "document.amt")); obj.addElement (new Param("vendor", "vendor_num")); vxml.addElement(obj); doc.addElement(vxml); System.out.println(doc.toString()); } public void IfTest() { System.out.println("\n" + new org.apache.ecs.html.Comment("IfTest.vxml")); VXMLDocument doc = new VXMLDocument(); Vxml vxml = new Vxml("1.0"); If iftag = new If("city == 'LA'"); iftag.addElement(new Assign("city", "Los Angeles")); iftag.addElement(new Elseif("city == 'Philly'")); iftag.addElement(new Assign("city", "Philadelphia")); iftag.addElement(new Else()); iftag.addElement(new Assign("city", "Unknown")); vxml.addElement(iftag); doc.addElement(vxml); System.out.println(doc.toString()); } public void ScriptTest() { System.out.println("\n" + new org.apache.ecs.html.Comment("Script.vxml")); VXMLDocument doc = new VXMLDocument(); Vxml vxml = new Vxml("1.0"); Script script = new Script(); script.addElement(""); vxml.addElement(script); doc.addElement(vxml); doc.output(System.out); } public static void main(String[] args) { VXMLTestBed tb = new VXMLTestBed(); System.out.println("\n" + new org.apache.ecs.html.Comment("VXML Test Bed")); tb.WeatherTest(); tb.CreditCard(); tb.MenuTest(); tb.RepromptTest(); tb.HelloWorldTest(); tb.DrinkTest(); tb.MetaTest(); tb.LinkTest(); tb.ExitTest(); tb.FilledTest(); tb.ReturnTest(); tb.EmptyElements(); tb.MiscElements(); tb.IfTest(); tb.ScriptTest(); } }