Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/wilko/jaim/BuddyUpdateTocResponse.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   * BuddyUpdateTocResponse.java
22   *
23   * Created on 5 May 2002, 21:19
24   */
25  
26  package com.wilko.jaim;
27  
28  import java.util.Date;
29  import java.util.StringTokenizer;
30  
31  /** A BuddyUpdateTocResponse is delivered to a {@link JaimEventListener } when a buddy update is received from the TOC server
32   * @author paulw
33   * @version $Revision: 1.7 $
34   */
35  public class BuddyUpdateTocResponse extends TocResponse implements TocResponseHandler {
36  
37      private String buddyName;
38      private boolean online;
39      private int evil;
40      private int idleTime;
41      private boolean onAOL;
42      private boolean unconfirmed;
43      private boolean admin;
44      private boolean confirmed;
45      private Date signonTime;
46      private boolean away;
47      
48      public static String RESPONSE_TYPE="UPDATE_BUDDY";
49      
50      /** Creates new BuddyUpdateTocResponse */
51      public BuddyUpdateTocResponse() {
52          buddyName="";
53          online=false;
54          evil=0;
55          idleTime=0;
56          onAOL=false;
57          unconfirmed=false;
58          admin=false;
59          confirmed=false;
60          away=false;
61      }
62  
63      /** The parseString method is used to populate the fields of this class from a Buddy Update string from the TOC server
64       * @param str The String containing the buddy update
65       */    
66      public TocResponse parseString(java.lang.String str) {
67          BuddyUpdateTocResponse tr=new BuddyUpdateTocResponse();
68          tr.doParse(str);
69          return(tr);
70      }
71      
72      private void doParse(String str)
73      {
74          cmd=str;
75          StringTokenizer st=new StringTokenizer(str,":");
76          
77          st.nextToken();
78          buddyName=st.nextToken();
79          String onlineStr=st.nextToken();
80          if (onlineStr.equals("T"))
81          {
82              online=true;
83          }
84          else
85          {
86              online=false;
87          }
88          
89          evil=Integer.parseInt(st.nextToken());
90          long signon=Long.parseLong(st.nextToken());
91          signonTime=new Date(signon*1000);
92          idleTime=Integer.parseInt(st.nextToken());
93          String userclass=st.nextToken();
94          if (userclass.charAt(0) == 'A')
95              onAOL=true;
96          if (userclass.charAt(1) == 'A')
97          {
98              admin=true;
99          }
100         else
101         {
102             if (userclass.charAt(1)=='U')
103             {
104                 unconfirmed=true;
105             }
106             else
107             {
108                 if(userclass.charAt(1)=='O')
109                 {
110                     confirmed=true;
111                 }
112             }
113         }
114         if (userclass.length()>2)
115         {
116         if (userclass.charAt(2)=='U')
117         {
118             away=true;
119         }
120         }
121     }
122     
123     /** Get the away status of the buddy specified by this update
124      * @return true if the buddy is "away"
125      */    
126     public boolean isAway()
127     {
128         return(away);
129     }
130     
131     /** Get the response type of  this response.  This method is used by the response dispatcher within JaimConnection
132      * @return The response type
133      */    
134     public String getResponseType() {
135         return RESPONSE_TYPE;
136     }
137     
138     /** Obtain the buddy name from this update
139      * @return The buddy name
140      */    
141     public String getBuddy()
142     {
143         return(buddyName);
144     }
145     
146     /** Obtain the online status of this buddy update
147      * @return true if the buddy is on line
148      */    
149     public boolean isOnline()
150     {
151         return(online);
152     }
153     
154     /** Obtain the idle time of this buddy
155      * @return The idle time in seconds
156      */    
157     public int getIdleTime()
158     {
159         return(idleTime);
160     }
161     
162     /** Obtain the "Evil" (Warning) level of this buddy
163      * @return The warning level as a percentage
164      */    
165     public int getEvil()
166     {
167         return(evil);
168     }
169     
170     /** Is this buddy an "Administrator"
171      * @return true if an administrator
172      */    
173     public boolean isAdmin()
174     {
175         return(admin);
176     }
177     
178     /** IS this buddy a "confirmed" user
179      * @return True if this buddy is confirmed
180      */    
181     public boolean isConfirmed()
182     {
183         return(confirmed);
184     }
185     
186     /** Is this user an "Unconfirmed user"
187      * @return True if this user is unconfirmed
188      */    
189     public boolean isUnconfirmed()
190     {
191         return(unconfirmed);
192     }
193     
194     /** Get the signon time of this buddy
195      * @return The date/time of signon
196      */    
197     public Date getSignonTime()
198     {
199         return(signonTime);
200     }
201     
202     /** Returns true if this response handler can handle the specified response.
203      * @param Response - the response string from TOC.  This is the part of the response before the first ':'
204      * @return true if the response can be handled
205      */
206     public boolean canHandle(String Response) {
207         return(Response.equalsIgnoreCase(RESPONSE_TYPE));
208     }    
209     
210 }