Source code: com/wilko/jaim/IMTocResponse.java
1 /*
2 * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 */
19
20 /*
21 * TocIMResponse.java
22 *
23 * Created on 4 May 2002, 14:38
24 */
25
26 package com.wilko.jaim;
27
28 /** This response is delivered to a {@link JaimEventListener } when an instant message is received
29 * @author paulw
30 * @version $Revision: 1.6 $
31 */
32 public class IMTocResponse extends TocResponse implements TocResponseHandler {
33
34 String from;
35 boolean autoResponse;
36 String msg;
37
38 public static final String RESPONSE_TYPE="IM_IN";
39
40 /** Creates new TocIMResponse */
41 public IMTocResponse() {
42 from="";
43 msg="";
44 autoResponse=false;
45 }
46
47 /** Obtain the name of the buddy who sent this instant message
48 * @return The senders name
49 */
50 public String getFrom()
51 {
52 return(from);
53 }
54
55 /** Obtain the message
56 * @return The message
57 * @see Utils#stripHTML
58 */
59 public String getMsg()
60 {
61 return(msg);
62 }
63
64 /** Is this response an automatically generated response?
65 * @return true if this is an automatically generated response
66 */
67 public boolean getAutoResponse()
68 {
69 return(autoResponse);
70 }
71
72 /** Parse an incoming IM response string
73 * @param str The string to be parsed
74 */
75 public TocResponse parseString(java.lang.String str) {
76 IMTocResponse tr=new IMTocResponse();
77 tr.doParse(str);
78 return(tr);
79 }
80
81 private void doParse(String str)
82 {
83 cmd=str;
84 int colonPos=str.indexOf(':');
85 if (colonPos!=-1)
86 {
87 str=str.substring(colonPos+1);
88 colonPos=str.indexOf(':');
89 if (colonPos != -1)
90 {
91 from=str.substring(0,colonPos);
92 str=str.substring(colonPos+1);
93 colonPos=str.indexOf(':');
94 if (str.charAt(0) == 'T')
95 {
96 autoResponse=true;
97 }
98 if (colonPos != -1)
99 {
100 msg=str.substring(colonPos+1);
101 }
102 }
103 }
104
105 }
106
107 /** Obtain the response type for response dispatching purposes
108 * @return The response type
109 */
110 public String getResponseType() {
111 return(RESPONSE_TYPE);
112 }
113
114 /** Returns true if this response handler can handle the specified response.
115 * @param Response - the response string from TOC. This is the part of the response before the first ':'
116 * @return true if the response can be handled
117 */
118 public boolean canHandle(String Response) {
119 return (Response.equalsIgnoreCase(RESPONSE_TYPE));
120 }
121
122 }