1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.asterisk.fastagi.command;
18
19 import java.io.Serializable;
20
21 /***
22 * Abstract base class for all commands supported by asterisk's FastAGI.
23 *
24 * @author srt
25 * @version $Id: AGICommand.java,v 1.4 2005/03/13 11:26:48 srt Exp $
26 */
27 public abstract class AGICommand implements Serializable
28 {
29 /***
30 * Serial version identifier.
31 */
32 private static final long serialVersionUID = 3257849874518456633L;
33
34 /***
35 * Returns a string suitable to be sent to asterisk.<br>
36 *
37 * @return a string suitable to be sent to asterisk.
38 */
39 public abstract String buildCommand();
40
41 protected String escapeAndQuote(String s)
42 {
43 String tmp;
44
45 if (s == null)
46 {
47 return "\"\"";
48 }
49
50 tmp = s;
51 tmp = tmp.replaceAll("//\"", "////\"");
52 tmp = tmp.replaceAll("//\n", "");
53 return "\"" + tmp + "\"";
54 }
55
56 public String toString()
57 {
58 StringBuffer sb;
59
60 sb = new StringBuffer(getClass().getName() + ": ");
61 sb.append("command='" + buildCommand() + "'; ");
62 sb.append("systemHashcode=" + System.identityHashCode(this));
63
64 return sb.toString();
65 }
66 }