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 digits 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 digit string, returning early if any of the given DTMF digits are
21   * 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: SayDigitsCommand.java,v 1.5 2005/03/11 22:27:49 srt Exp $
27   */
28  public class SayDigitsCommand extends AGICommand
29  {
30      /***
31       * Serial version identifier.
32       */
33      private static final long serialVersionUID = 3907207173934101552L;
34  
35      /***
36       * The digits string to say.
37       */
38      private String digits;
39  
40      /***
41       * When one of these digits is pressed while saying the digits the command
42       * returns.
43       */
44      private String escapeDigits;
45  
46      /***
47       * Creates a new SayDigitsCommand.
48       * 
49       * @param digits the digits to say.
50       */
51      public SayDigitsCommand(String digits)
52      {
53          this.digits = digits;
54          this.escapeDigits = null;
55      }
56  
57      /***
58       * Creates a new SayDigitsCommand.
59       * 
60       * @param digits the digits to say.
61       * @param escapeDigits the digits that allow the user to interrupt this
62       *            command.
63       */
64      public SayDigitsCommand(String digits, String escapeDigits)
65      {
66          this.digits = digits;
67          this.escapeDigits = escapeDigits;
68      }
69  
70      /***
71       * Returns the digits string to say.
72       * 
73       * @return the digits string to say.
74       */
75      public String getDigits()
76      {
77          return digits;
78      }
79  
80      /***
81       * Sets the digits to say.
82       * 
83       * @param digits the digits string to say.
84       */
85      public void setDigits(String digits)
86      {
87          this.digits = digits;
88      }
89  
90      /***
91       * Returns the digits that allow the user to interrupt this command.
92       * 
93       * @return the digits that allow the user to interrupt this command.
94       */
95      public String getEscapeDigits()
96      {
97          return escapeDigits;
98      }
99  
100     /***
101      * Sets the digits that allow the user to interrupt this command.
102      * 
103      * @param escapeDigits the digits that allow the user to interrupt this
104      *            command or <code>null</code> for none.
105      */
106     public void setEscapeDigits(String escapeDigits)
107     {
108         this.escapeDigits = escapeDigits;
109     }
110 
111     public String buildCommand()
112     {
113         return "SAY DIGITS " + escapeAndQuote(digits) + " "
114                 + escapeAndQuote(escapeDigits);
115     }
116 }