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 file 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   * Returns the value of the given channel varible and understands complex
21   * variable names and builtin variables, unlike the GetVariableCommand.<br>
22   * You can also use this command to use custom Asterisk functions. Syntax is
23   * "func(args)".<br>
24   * Returns 0 if the variable is not set or channel does not exist. Returns 1 if
25   * the variable is set and returns the variable in parenthesis.<br>
26   * Available since Asterisk 1.2<br>
27   * Example return code: 200 result=1 (testvariable)
28   * 
29   * @since 0.2
30   * @author srt
31   * @version $Id: GetFullVariableCommand.java,v 1.2 2005/11/27 17:31:04 srt Exp $
32   * @see net.sf.asterisk.fastagi.command.GetVariableCommand
33   */
34  public class GetFullVariableCommand extends AGICommand
35  {
36      /***
37       * Serial version identifier.
38       */
39      private static final long serialVersionUID = 3256719598056387384L;
40  
41      /***
42       * The name of the variable to retrieve.
43       */
44      private String variable;
45  
46      private String channel;
47  
48      /***
49       * Creates a new GetFullVariableCommand.
50       * 
51       * @param variable the name of the variable to retrieve.
52       */
53      public GetFullVariableCommand(String variable)
54      {
55          this.variable = variable;
56      }
57  
58      /***
59       * Creates a new GetFullVariableCommand.
60       * 
61       * @param variable the name of the variable to retrieve.
62       * @param channel the name of the channel.
63       */
64      public GetFullVariableCommand(String variable, String channel)
65      {
66          this.variable = variable;
67          this.channel = channel;
68      }
69  
70      /***
71       * Returns the name of the variable to retrieve.
72       * 
73       * @return the the name of the variable to retrieve.
74       */
75      public String getVariable()
76      {
77          return variable;
78      }
79  
80      /***
81       * Sets the name of the variable to retrieve.<br>
82       * You can also use custom dialplan functions (like "func(args)") as
83       * variable.
84       * 
85       * @param variable the name of the variable to retrieve.
86       */
87      public void setVariable(String variable)
88      {
89          this.variable = variable;
90      }
91  
92      /***
93       * Returns the the name of the channel.
94       * 
95       * @return the name of the channel.
96       */
97      public String getChannel()
98      {
99          return channel;
100     }
101 
102     /***
103      * Sets the name of the channel.
104      * 
105      * @param channel the name of the channel.
106      */
107     public void setChannel(String channel)
108     {
109         this.channel = channel;
110     }
111 
112     public String buildCommand()
113     {
114         StringBuffer sb;
115 
116         sb = new StringBuffer("GET FULL VARIABLE ");
117         sb.append(escapeAndQuote(variable));
118 
119         if (channel != null)
120         {
121             sb.append(" ");
122             sb.append(escapeAndQuote(channel));
123         }
124 
125         return sb.toString();
126     }
127 }