Source code: com/wilko/jaim/EvilTocResponse.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 * EvilTocResponse.java
22 *
23 * Created on 6 May 2002, 16:49
24 */
25
26 package com.wilko.jaim;
27
28 import java.util.StringTokenizer;
29
30 /** An EvilTocResponse is delivered to a {@link JaimEventListener } when the signed on buddy is "eviled" or warned
31 * @author paulw
32 * @version $Revision: 1.6 $
33 */
34 public class EvilTocResponse extends TocResponse implements TocResponseHandler {
35
36 private boolean anonymousEvil;
37 private int evilAmount;
38 private String evilBy;
39
40 public static final String RESPONSE_TYPE="EVILED";
41
42 /** Creates new EvilTocResponse */
43 public EvilTocResponse() {
44 anonymousEvil=true;
45 evilBy="";
46 evilAmount=0;
47 }
48
49 /** Parse the evil message from the TOC server
50 * @param str The evil message
51 */
52 public TocResponse parseString(java.lang.String str) {
53 EvilTocResponse tr=new EvilTocResponse();
54 tr.doParse(str);
55 return(tr);
56 }
57
58 private void doParse(String str)
59 {
60
61 StringTokenizer st=new StringTokenizer(str,":");
62
63 st.nextToken(); // skip over "EVILED"
64 evilAmount=Integer.parseInt(st.nextToken());
65 if (st.hasMoreTokens())
66 {
67 evilBy=st.nextToken();
68 anonymousEvil=false;
69 }
70 else
71 {
72 anonymousEvil=true;
73 }
74 }
75
76 /** Get the evil amount from this response. This is the current evil or warning level for the authenticated buddy, not the increment specified by the last warning
77 * @return The cumulative evil or warning level
78 */
79 public int getEvilAmount()
80 {
81 return(evilAmount);
82 }
83
84 /** Obtain the name of the buddy that issued the warning.
85 * @return The buddy name that issued the warning
86 * @see #isAnonymous
87 */
88 public String getEvilBy()
89 {
90 return(evilBy);
91 }
92
93 /** Obtain the anonymous status of this warning
94 * @return true if this warning was issued anonymously
95 */
96 public boolean isAnonymous()
97 {
98 return(anonymousEvil);
99 }
100
101 /** Used by the response dispatcher
102 * @return The response type
103 */
104 public String getResponseType() {
105 return RESPONSE_TYPE;
106 }
107
108
109 /** Returns true if this response handler can handle the specified response.
110 * @param Response - the response string from TOC. This is the part of the response before the first ':'
111 * @return true if the response can be handled
112 */
113 public boolean canHandle(String Response) {
114 return(Response.equalsIgnoreCase(RESPONSE_TYPE));
115 }
116
117 }