View Javadoc

1   /*
2    * Copyright  2004-2005 Stefan Reuter
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this text except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *
16   */
17  package net.sf.asterisk.fastagi.command;
18  
19  /***
20   * Say a given character string, returning early if any of the
21   * given DTMF digits are received on the channel.<br>
22   * Returns 0 if playback completes without a digit being pressed, or the ASCII
23   * numerical value of the digit if one was pressed or -1 on error/hangup.
24   * 
25   * @author srt
26   * @version $Id: SayAlphaCommand.java,v 1.1 2005/04/06 16:47:27 srt Exp $
27   */
28  public class SayAlphaCommand extends AGICommand
29  {
30      /***
31       * Serial version identifier.
32       */
33      private static final long serialVersionUID = 3256721797012404276L;
34  
35      /***
36       * The text to say.
37       */
38      private String text;
39  
40      /***
41       * When one of these digits is pressed the command returns.
42       */
43      private String escapeDigits;
44  
45      /***
46       * Creates a new SayAlphaCommand.
47       * 
48       * @param text the text to say.
49       */
50      public SayAlphaCommand(String text)
51      {
52          this.text = text;
53          this.escapeDigits = null;
54      }
55  
56      /***
57       * Creates a new SayAlphaCommand.
58       * 
59       * @param text the text to say.
60       * @param escapeDigits contains the digits that allow the user to interrupt
61       *            this command.
62       */
63      public SayAlphaCommand(String text, String escapeDigits)
64      {
65          this.text = text;
66          this.escapeDigits = escapeDigits;
67      }
68  
69      /***
70       * Returns the text to say.
71       * 
72       * @return the text to say.
73       */
74      public String getText()
75      {
76          return text;
77      }
78  
79      /***
80       * Sets the text to say.
81       * 
82       * @param text the text to say.
83       */
84      public void setText(String text)
85      {
86          this.text = text;
87      }
88  
89      /***
90       * Returns the digits that allow the user to interrupt this command.
91       * 
92       * @return the digits that allow the user to interrupt this command.
93       */
94      public String getEscapeDigits()
95      {
96          return escapeDigits;
97      }
98  
99      /***
100      * Sets the digits that allow the user to interrupt this command.
101      * 
102      * @param escapeDigits the text that allow the user to interrupt this
103      *            command or <code>null</code> for none.
104      */
105     public void setEscapeDigits(String escapeDigits)
106     {
107         this.escapeDigits = escapeDigits;
108     }
109 
110     public String buildCommand()
111     {
112         return "SAY ALPHA " + escapeAndQuote(text) + " "
113                 + escapeAndQuote(escapeDigits);
114     }
115 }