aboutsummaryrefslogtreecommitdiff
path: root/src/com/wilko
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/wilko')
-rw-r--r--src/com/wilko/jaim/Buddy.java133
-rw-r--r--src/com/wilko/jaim/BuddyUpdateTocResponse.java251
-rw-r--r--src/com/wilko/jaim/ChatInviteTocResponse.java52
-rw-r--r--src/com/wilko/jaim/ConfigTocResponse.java343
-rw-r--r--src/com/wilko/jaim/ConnectionLostTocResponse.java26
-rw-r--r--src/com/wilko/jaim/ErrorTocResponse.java161
-rw-r--r--src/com/wilko/jaim/EvilTocResponse.java118
-rw-r--r--src/com/wilko/jaim/FLAPDataFrame.java59
-rw-r--r--src/com/wilko/jaim/FLAPErrorFrame.java24
-rw-r--r--src/com/wilko/jaim/FLAPFrame.java136
-rw-r--r--src/com/wilko/jaim/FLAPFrameException.java6
-rw-r--r--src/com/wilko/jaim/FLAPFrameFactory.java33
-rw-r--r--src/com/wilko/jaim/FLAPInputFrame.java59
-rw-r--r--src/com/wilko/jaim/FLAPKeepAliveFrame.java25
-rw-r--r--src/com/wilko/jaim/FLAPSignoffFrame.java28
-rw-r--r--src/com/wilko/jaim/FLAPSignonFrame.java84
-rw-r--r--src/com/wilko/jaim/GenericTocResponse.java76
-rw-r--r--src/com/wilko/jaim/GotoTocResponse.java103
-rw-r--r--src/com/wilko/jaim/Group.java80
-rw-r--r--src/com/wilko/jaim/IMTocResponse.java125
-rw-r--r--src/com/wilko/jaim/JaimConnection.java895
-rw-r--r--src/com/wilko/jaim/JaimEvent.java27
-rw-r--r--src/com/wilko/jaim/JaimEventListener.java16
-rw-r--r--src/com/wilko/jaim/JaimException.java6
-rw-r--r--src/com/wilko/jaim/JaimStateException.java6
-rw-r--r--src/com/wilko/jaim/JaimTimeoutException.java6
-rw-r--r--src/com/wilko/jaim/LoginCompleteTocResponse.java24
-rw-r--r--src/com/wilko/jaim/NickTocResponse.java67
-rw-r--r--src/com/wilko/jaim/SignOnTocResponse.java64
-rw-r--r--src/com/wilko/jaim/TocAddBuddyCommand.java42
-rw-r--r--src/com/wilko/jaim/TocAddDenyCommand.java42
-rw-r--r--src/com/wilko/jaim/TocAddPermitCommand.java42
-rw-r--r--src/com/wilko/jaim/TocChatJoinCommand.java28
-rw-r--r--src/com/wilko/jaim/TocCommand.java15
-rw-r--r--src/com/wilko/jaim/TocEvilCommand.java44
-rw-r--r--src/com/wilko/jaim/TocGetInfoCommand.java35
-rw-r--r--src/com/wilko/jaim/TocIMCommand.java38
-rw-r--r--src/com/wilko/jaim/TocInitDoneCommand.java26
-rw-r--r--src/com/wilko/jaim/TocResponse.java25
-rw-r--r--src/com/wilko/jaim/TocResponseFactory.java59
-rw-r--r--src/com/wilko/jaim/TocResponseHandler.java33
-rw-r--r--src/com/wilko/jaim/TocSetAwayCommand.java32
-rw-r--r--src/com/wilko/jaim/TocSetConfigCommand.java57
-rw-r--r--src/com/wilko/jaim/TocSetIdleCommand.java30
-rw-r--r--src/com/wilko/jaim/TocSetInfoCommand.java34
-rw-r--r--src/com/wilko/jaim/TocSignonCommand.java45
-rw-r--r--src/com/wilko/jaim/Utils.java128
-rw-r--r--src/com/wilko/jaimtest/JaimTest.java9
48 files changed, 1937 insertions, 1860 deletions
diff --git a/src/com/wilko/jaim/Buddy.java b/src/com/wilko/jaim/Buddy.java
index 486b7ce..4677e2f 100644
--- a/src/com/wilko/jaim/Buddy.java
+++ b/src/com/wilko/jaim/Buddy.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -25,64 +25,79 @@
package com.wilko.jaim;
-/** This is a buddy object that holds the buddy's name and other
+/**
+ * This is a buddy object that holds the buddy's name and other
* information about a buddy.
+ *
* @author Brett Humphreys
*/
- public class Buddy {
- /** Name of the buddy */
- private String buddyName;
-
- /** Permit value */
- private boolean permit;
-
- /** deny value */
- private boolean deny;
-
- /** Constructor that sets the buddy name
- * @param name the name of this buddy.
- */
- public Buddy ( String name )
- {
- buddyName = name;
- }
-
- /** Gets the buddy name
- * @return buddy name
- */
- public String getName()
- {
- return buddyName;
- }
- /** Sets the permit value
- * @param permitVal what to set permit to
- */
- public void setPermit( boolean permitVal )
- {
- permit = permitVal;
- }
-
- /** Gets the permit value
- * @return permit value
- */
- public boolean getPermit( )
- {
- return permit;
- }
-
- /** Sets the deny value
- * @param denyVal what to set deny to
- */
- public void setDeny( boolean denyVal )
- {
- deny = denyVal;
- }
-
- /** Gets the deny value
- * @return deny value
- */
- public boolean getDeny( )
- {
- return deny;
- }
- }
+public class Buddy {
+ /**
+ * Name of the buddy
+ */
+ private final String buddyName;
+
+ /**
+ * Permit value
+ */
+ private boolean permit;
+
+ /**
+ * deny value
+ */
+ private boolean deny;
+
+ /**
+ * Constructor that sets the buddy name
+ *
+ * @param name the name of this buddy.
+ */
+ public Buddy(String name) {
+ buddyName = name;
+ }
+
+ /**
+ * Gets the buddy name
+ *
+ * @return buddy name
+ */
+ public String getName() {
+ return buddyName;
+ }
+
+ /**
+ * Gets the permit value
+ *
+ * @return permit value
+ */
+ public boolean getPermit() {
+ return permit;
+ }
+
+ /**
+ * Sets the permit value
+ *
+ * @param permitVal what to set permit to
+ */
+ public void setPermit(boolean permitVal) {
+ permit = permitVal;
+ }
+
+ /**
+ * Gets the deny value
+ *
+ * @return deny value
+ */
+ public boolean getDeny() {
+ return deny;
+ }
+
+ /**
+ * Sets the deny value
+ *
+ * @param denyVal what to set deny to
+ */
+ public void setDeny(boolean denyVal) {
+ deny = denyVal;
+ }
+}
diff --git a/src/com/wilko/jaim/BuddyUpdateTocResponse.java b/src/com/wilko/jaim/BuddyUpdateTocResponse.java
index b9de8db..d7cc314 100644
--- a/src/com/wilko/jaim/BuddyUpdateTocResponse.java
+++ b/src/com/wilko/jaim/BuddyUpdateTocResponse.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -28,12 +28,15 @@ package com.wilko.jaim;
import java.util.Date;
import java.util.StringTokenizer;
-/** A BuddyUpdateTocResponse is delivered to a {@link JaimEventListener } when a buddy update is received from the TOC server
+/**
+ * A BuddyUpdateTocResponse is delivered to a {@link JaimEventListener } when a buddy update is received from the TOC server
+ *
* @author paulw
* @version $Revision: 1.7 $
*/
public class BuddyUpdateTocResponse extends TocResponse implements TocResponseHandler {
+ public static String RESPONSE_TYPE = "UPDATE_BUDDY";
private String buddyName;
private boolean online;
private int evil;
@@ -44,167 +47,165 @@ public class BuddyUpdateTocResponse extends TocResponse implements TocResponseHa
private boolean confirmed;
private Date signonTime;
private boolean away;
-
- public static String RESPONSE_TYPE="UPDATE_BUDDY";
-
- /** Creates new BuddyUpdateTocResponse */
+
+ /**
+ * Creates new BuddyUpdateTocResponse
+ */
public BuddyUpdateTocResponse() {
- buddyName="";
- online=false;
- evil=0;
- idleTime=0;
- onAOL=false;
- unconfirmed=false;
- admin=false;
- confirmed=false;
- away=false;
+ buddyName = "";
+ online = false;
+ evil = 0;
+ idleTime = 0;
+ onAOL = false;
+ unconfirmed = false;
+ admin = false;
+ confirmed = false;
+ away = false;
}
- /** The parseString method is used to populate the fields of this class from a Buddy Update string from the TOC server
+ /**
+ * The parseString method is used to populate the fields of this class from a Buddy Update string from the TOC server
+ *
* @param str The String containing the buddy update
- */
+ */
public TocResponse parseString(java.lang.String str) {
- BuddyUpdateTocResponse tr=new BuddyUpdateTocResponse();
+ BuddyUpdateTocResponse tr = new BuddyUpdateTocResponse();
tr.doParse(str);
- return(tr);
+ return (tr);
}
-
- private void doParse(String str)
- {
- cmd=str;
- StringTokenizer st=new StringTokenizer(str,":");
-
+
+ private void doParse(String str) {
+ cmd = str;
+ StringTokenizer st = new StringTokenizer(str, ":");
+
st.nextToken();
- buddyName=st.nextToken();
- String onlineStr=st.nextToken();
- if (onlineStr.equals("T"))
- {
- online=true;
- }
- else
- {
- online=false;
- }
-
- evil=Integer.parseInt(st.nextToken());
- long signon=Long.parseLong(st.nextToken());
- signonTime=new Date(signon*1000);
- idleTime=Integer.parseInt(st.nextToken());
- String userclass=st.nextToken();
+ buddyName = st.nextToken();
+ String onlineStr = st.nextToken();
+ online = onlineStr.equals("T");
+
+ evil = Integer.parseInt(st.nextToken());
+ long signon = Long.parseLong(st.nextToken());
+ signonTime = new Date(signon * 1000);
+ idleTime = Integer.parseInt(st.nextToken());
+ String userclass = st.nextToken();
if (userclass.charAt(0) == 'A')
- onAOL=true;
- if (userclass.charAt(1) == 'A')
- {
- admin=true;
- }
- else
- {
- if (userclass.charAt(1)=='U')
- {
- unconfirmed=true;
- }
- else
- {
- if(userclass.charAt(1)=='O')
- {
- confirmed=true;
+ onAOL = true;
+ if (userclass.charAt(1) == 'A') {
+ admin = true;
+ } else {
+ if (userclass.charAt(1) == 'U') {
+ unconfirmed = true;
+ } else {
+ if (userclass.charAt(1) == 'O') {
+ confirmed = true;
}
}
}
- if (userclass.length()>2)
- {
- if (userclass.charAt(2)=='U')
- {
- away=true;
- }
+ if (userclass.length() > 2) {
+ if (userclass.charAt(2) == 'U') {
+ away = true;
+ }
}
}
-
- /** Get the away status of the buddy specified by this update
+
+ /**
+ * Get the away status of the buddy specified by this update
+ *
* @return true if the buddy is "away"
- */
- public boolean isAway()
- {
- return(away);
+ */
+ public boolean isAway() {
+ return (away);
}
-
- /** Get the response type of this response. This method is used by the response dispatcher within JaimConnection
+
+ /**
+ * Get the response type of this response. This method is used by the response dispatcher within JaimConnection
+ *
* @return The response type
- */
+ */
public String getResponseType() {
return RESPONSE_TYPE;
}
-
- /** Obtain the buddy name from this update
+
+ /**
+ * Obtain the buddy name from this update
+ *
* @return The buddy name
- */
- public String getBuddy()
- {
- return(buddyName);
+ */
+ public String getBuddy() {
+ return (buddyName);
}
-
- /** Obtain the online status of this buddy update
+
+ /**
+ * Obtain the online status of this buddy update
+ *
* @return true if the buddy is on line
- */
- public boolean isOnline()
- {
- return(online);
+ */
+ public boolean isOnline() {
+ return (online);
}
-
- /** Obtain the idle time of this buddy
+
+ /**
+ * Obtain the idle time of this buddy
+ *
* @return The idle time in seconds
- */
- public int getIdleTime()
- {
- return(idleTime);
+ */
+ public int getIdleTime() {
+ return (idleTime);
}
-
- /** Obtain the "Evil" (Warning) level of this buddy
+
+ /**
+ * Obtain the "Evil" (Warning) level of this buddy
+ *
* @return The warning level as a percentage
- */
- public int getEvil()
- {
- return(evil);
+ */
+ public int getEvil() {
+ return (evil);
}
-
- /** Is this buddy an "Administrator"
+
+ /**
+ * Is this buddy an "Administrator"
+ *
* @return true if an administrator
- */
- public boolean isAdmin()
- {
- return(admin);
+ */
+ public boolean isAdmin() {
+ return (admin);
}
-
- /** IS this buddy a "confirmed" user
+
+ /**
+ * IS this buddy a "confirmed" user
+ *
* @return True if this buddy is confirmed
- */
- public boolean isConfirmed()
- {
- return(confirmed);
+ */
+ public boolean isConfirmed() {
+ return (confirmed);
}
-
- /** Is this user an "Unconfirmed user"
+
+ /**
+ * Is this user an "Unconfirmed user"
+ *
* @return True if this user is unconfirmed
- */
- public boolean isUnconfirmed()
- {
- return(unconfirmed);
+ */
+ public boolean isUnconfirmed() {
+ return (unconfirmed);
}
-
- /** Get the signon time of this buddy
+
+ /**
+ * Get the signon time of this buddy
+ *
* @return The date/time of signon
- */
- public Date getSignonTime()
- {
- return(signonTime);
+ */
+ public Date getSignonTime() {
+ return (signonTime);
}
-
- /** Returns true if this response handler can handle the specified response.
+
+ /**
+ * Returns true if this response handler can handle the specified response.
+ *
* @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled
*/
public boolean canHandle(String Response) {
- return(Response.equalsIgnoreCase(RESPONSE_TYPE));
- }
-
+ return (Response.equalsIgnoreCase(RESPONSE_TYPE));
+ }
+
}
diff --git a/src/com/wilko/jaim/ChatInviteTocResponse.java b/src/com/wilko/jaim/ChatInviteTocResponse.java
index 3c4d894..7bd247e 100644
--- a/src/com/wilko/jaim/ChatInviteTocResponse.java
+++ b/src/com/wilko/jaim/ChatInviteTocResponse.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -25,23 +25,25 @@
package com.wilko.jaim;
-import java.util.Date;
import java.util.StringTokenizer;
-/** A BuddyUpdateTocResponse is delivered to a {@link JaimEventListener } when a buddy update is received from the TOC server
+/**
+ * A BuddyUpdateTocResponse is delivered to a {@link JaimEventListener } when a buddy update is received from the TOC server
+ *
* @author paulw
* @version $Revision: 1.7 $
*/
public class ChatInviteTocResponse extends TocResponse implements TocResponseHandler {
+ public static String RESPONSE_TYPE = "CHAT_INVITE";
private String roomName;
private String roomID;
private String senderScreenname;
private String message;
- public static String RESPONSE_TYPE="CHAT_INVITE";
-
- /** Creates new BuddyUpdateTocResponse */
+ /**
+ * Creates new BuddyUpdateTocResponse
+ */
public ChatInviteTocResponse() {
roomName = "";
roomID = "";
@@ -49,20 +51,21 @@ public class ChatInviteTocResponse extends TocResponse implements TocResponseHan
message = "";
}
- /** The parseString method is used to populate the fields of this class from a Buddy Update string from the TOC server
+ /**
+ * The parseString method is used to populate the fields of this class from a Buddy Update string from the TOC server
+ *
* @param str The String containing the buddy update
- */
+ */
public TocResponse parseString(String str) {
ChatInviteTocResponse tr = new ChatInviteTocResponse();
tr.doParse(str);
- return(tr);
+ return (tr);
}
-
- private void doParse(String str)
- {
- cmd=str;
- StringTokenizer st=new StringTokenizer(str,":");
-
+
+ private void doParse(String str) {
+ cmd = str;
+ StringTokenizer st = new StringTokenizer(str, ":");
+
st.nextToken();
roomName = st.nextToken();
roomID = st.nextToken();
@@ -70,9 +73,11 @@ public class ChatInviteTocResponse extends TocResponse implements TocResponseHan
message = st.nextToken();
}
- /** Get the response type of this response. This method is used by the response dispatcher within JaimConnection
+ /**
+ * Get the response type of this response. This method is used by the response dispatcher within JaimConnection
+ *
* @return The response type
- */
+ */
public String getResponseType() {
return RESPONSE_TYPE;
}
@@ -80,6 +85,7 @@ public class ChatInviteTocResponse extends TocResponse implements TocResponseHan
public String getRoomName() {
return roomName;
}
+
public String getRoomID() {
return roomID;
}
@@ -91,13 +97,15 @@ public class ChatInviteTocResponse extends TocResponse implements TocResponseHan
public String getMessage() {
return message;
}
-
- /** Returns true if this response handler can handle the specified response.
+
+ /**
+ * Returns true if this response handler can handle the specified response.
+ *
* @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled
*/
public boolean canHandle(String Response) {
- return(Response.equalsIgnoreCase(RESPONSE_TYPE));
- }
-
+ return (Response.equalsIgnoreCase(RESPONSE_TYPE));
+ }
+
}
diff --git a/src/com/wilko/jaim/ConfigTocResponse.java b/src/com/wilko/jaim/ConfigTocResponse.java
index 49bed69..b9ae399 100644
--- a/src/com/wilko/jaim/ConfigTocResponse.java
+++ b/src/com/wilko/jaim/ConfigTocResponse.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -21,174 +21,189 @@
* ConfigTocResponse.java
* Created on 1, October 2002
*/
- package com.wilko.jaim;
-
- import java.util.*;
-
- /** A ConfigTocResponse contains the config message received from
- * the toc server.
- *This response is handled by the JaimConnection class, but may also be used by client programs.
- *Once this event has been received, information returned from {@link JaimConnection#getGroups} is valid
- * @author Brett Humphreys, Paul Wilkinson
- */
- public class ConfigTocResponse extends TocResponse implements TocResponseHandler {
-
- public static String RESPONSE_TYPE="CONFIG";
-
- /** The Vector of Group objects */
- private Vector buddyList = new Vector();
-
- /** The HashMap of known buddies */
- private HashMap buddies;
-
- /** The mode for this configuration */
- private int mode;
-
- /** Value for mode that indicates PERMIT ALL mode */
- public static final int PERMIT_ALL=1;
-
- /** Value for mode that indicates DENY ALL mode */
- public static final int DENY_ALL=2;
-
- /** Value for mode that indicates PERMIT SOME mode */
- public static final int PERMIT_SOME=3;
-
- /** Value for mode that indicates DENY SOME mode */
- public static final int DENY_SOME=4;
-
- /** Returns an Enumeration of groups. Each Entry is a {@link Group}
- * Each group then has an Enumeration of buddies within that group See {@link Group#enumerateBuddies}.
- * @return list of Group elements or an empty list if none are found.
- */
- public Enumeration enumerateGroups()
- {
- return buddyList.elements();
- }
-
- /** Returns a Collection of groups. Each element is a {@link Group)
- * @return the groups
- */
+package com.wilko.jaim;
+
+import java.util.*;
+
+/**
+ * A ConfigTocResponse contains the config message received from
+ * the toc server.
+ * This response is handled by the JaimConnection class, but may also be used by client programs.
+ * Once this event has been received, information returned from {@link JaimConnection#getGroups} is valid
+ *
+ * @author Brett Humphreys, Paul Wilkinson
+ */
+public class ConfigTocResponse extends TocResponse implements TocResponseHandler {
+
+ /**
+ * Value for mode that indicates PERMIT ALL mode
+ */
+ public static final int PERMIT_ALL = 1;
+ /**
+ * Value for mode that indicates DENY ALL mode
+ */
+ public static final int DENY_ALL = 2;
+ /**
+ * Value for mode that indicates PERMIT SOME mode
+ */
+ public static final int PERMIT_SOME = 3;
+ /**
+ * Value for mode that indicates DENY SOME mode
+ */
+ public static final int DENY_SOME = 4;
+ public static String RESPONSE_TYPE = "CONFIG";
+ /**
+ * The Vector of Group objects
+ */
+ private final Vector buddyList = new Vector();
+ /**
+ * The HashMap of known buddies
+ */
+ private HashMap buddies;
+ /**
+ * The mode for this configuration
+ */
+ private int mode;
+
+ /**
+ * Returns an Enumeration of groups. Each Entry is a {@link Group}
+ * Each group then has an Enumeration of buddies within that group See {@link Group#enumerateBuddies}.
+ *
+ * @return list of Group elements or an empty list if none are found.
+ */
+ public Enumeration enumerateGroups() {
+ return buddyList.elements();
+ }
+
+ /**
+ * Returns a Collection of groups. Each element is a {@link Group)
+ *
+ * @return the groups
+ */
public Collection getGroups() {
java.util.Collection result = new Vector(buddyList);
return result;
}
- /** Get the response type of this response. This method is used by the response dispatcher within JaimConnection
- * @return The response type
- */
- public String getResponseType() {
- return RESPONSE_TYPE;
- }
- /** Parses the config string.
- */
- public TocResponse parseString(String message)
- {
- ConfigTocResponse tr = new ConfigTocResponse();
- tr.doParse(message);
- return(tr);
- }
-
- private void doParse(String message)
- {
- cmd=message;
- int colonIndex = message.indexOf(':');
- //throw away the first word.
- message = message.substring(colonIndex+1, message.length());
- buddies = new HashMap();
- StringTokenizer tok = new StringTokenizer(message,"\n");
- String itemType;
- String itemValue;
- Group currentGroup=null;
- Buddy tmpBuddy;
- while( tok.hasMoreTokens() )
- {
- // Can't tokenize on both \n and space since there could be spaces
- // in the name, so parsing by hand.
- itemType = tok.nextToken();
- int firstSpace = itemType.indexOf(' ');
- itemValue = itemType.substring(firstSpace+1, itemType.length());
- itemType = itemType.substring(0, firstSpace);
-
- char type = itemType.charAt(0);
- switch (type)
- {
- case 'g':
- currentGroup = new Group(itemValue);
- buddyList.add(currentGroup);
- break;
-
- case 'b':
-
- tmpBuddy = getBuddy(itemValue);
- //this shouldn't happen, but:
- if(currentGroup==null)
- {
- currentGroup = new Group("<unknown>");
- buddyList.add(currentGroup);
- }
- currentGroup.addBuddy(tmpBuddy);
-
-
- break;
-
- case 'p':
- tmpBuddy = getBuddy(itemValue);
- tmpBuddy.setPermit(true);
- break;
-
- case 'm':
- setMode(Integer.valueOf(itemValue).intValue());
- break;
-
- case 'd':
-
- tmpBuddy = getBuddy(itemValue);
- tmpBuddy.setDeny(true);
- break;
- }
- }
- }
-
- /** Return an existing Buddy with the specified name or return a new buddy if the name is not known
- * The buddy is added to the buddies hash if it is a new buddy
- * @param The name of the buddy we are looking for
- * @return The buddy object
- */
-
- private Buddy getBuddy(String buddyName)
- {
- Buddy retBuddy = (Buddy)buddies.get(buddyName);
- if (retBuddy== null)
- {
- retBuddy=new Buddy(buddyName);
- buddies.put(buddyName,retBuddy);
+ /**
+ * Get the response type of this response. This method is used by the response dispatcher within JaimConnection
+ *
+ * @return The response type
+ */
+ public String getResponseType() {
+ return RESPONSE_TYPE;
+ }
+
+ /**
+ * Parses the config string.
+ */
+ public TocResponse parseString(String message) {
+ ConfigTocResponse tr = new ConfigTocResponse();
+ tr.doParse(message);
+ return (tr);
+ }
+
+ private void doParse(String message) {
+ cmd = message;
+ int colonIndex = message.indexOf(':');
+ //throw away the first word.
+ message = message.substring(colonIndex + 1);
+ buddies = new HashMap();
+ StringTokenizer tok = new StringTokenizer(message, "\n");
+ String itemType;
+ String itemValue;
+ Group currentGroup = null;
+ Buddy tmpBuddy;
+ while (tok.hasMoreTokens()) {
+ // Can't tokenize on both \n and space since there could be spaces
+ // in the name, so parsing by hand.
+ itemType = tok.nextToken();
+ int firstSpace = itemType.indexOf(' ');
+ itemValue = itemType.substring(firstSpace + 1);
+ itemType = itemType.substring(0, firstSpace);
+
+ char type = itemType.charAt(0);
+ switch (type) {
+ case 'g':
+ currentGroup = new Group(itemValue);
+ buddyList.add(currentGroup);
+ break;
+
+ case 'b':
+
+ tmpBuddy = getBuddy(itemValue);
+ //this shouldn't happen, but:
+ if (currentGroup == null) {
+ currentGroup = new Group("<unknown>");
+ buddyList.add(currentGroup);
+ }
+ currentGroup.addBuddy(tmpBuddy);
+
+
+ break;
+
+ case 'p':
+ tmpBuddy = getBuddy(itemValue);
+ tmpBuddy.setPermit(true);
+ break;
+
+ case 'm':
+ setMode(Integer.valueOf(itemValue).intValue());
+ break;
+
+ case 'd':
+
+ tmpBuddy = getBuddy(itemValue);
+ tmpBuddy.setDeny(true);
+ break;
}
- return(retBuddy);
}
-
- /** Sets the mode for this configuration
- * @param modeVal the string value of the mode (1-4)
- */
- public void setMode( int modeVal )
- {
- mode = modeVal;
- }
-
- /** Gets the mode for this configuration
- * @return mode for the configuration
- */
- public int getMode( )
- {
- return mode;
- }
-
- /** Returns true if this response handler can handle the specified response.
- * @param Response - the response string from TOC. This is the part of the response before the first ':'
- * @return true if the response can be handled
- */
- public boolean canHandle(String Response) {
- return(Response.equalsIgnoreCase(RESPONSE_TYPE));
- }
-
- }
+ }
+
+ /**
+ * Return an existing Buddy with the specified name or return a new buddy if the name is not known
+ * The buddy is added to the buddies hash if it is a new buddy
+ *
+ * @param The name of the buddy we are looking for
+ * @return The buddy object
+ */
+
+ private Buddy getBuddy(String buddyName) {
+ Buddy retBuddy = (Buddy) buddies.get(buddyName);
+ if (retBuddy == null) {
+ retBuddy = new Buddy(buddyName);
+ buddies.put(buddyName, retBuddy);
+ }
+ return (retBuddy);
+ }
+
+ /**
+ * Gets the mode for this configuration
+ *
+ * @return mode for the configuration
+ */
+ public int getMode() {
+ return mode;
+ }
+
+ /**
+ * Sets the mode for this configuration
+ *
+ * @param modeVal the string value of the mode (1-4)
+ */
+ public void setMode(int modeVal) {
+ mode = modeVal;
+ }
+
+ /**
+ * Returns true if this response handler can handle the specified response.
+ *
+ * @param Response - the response string from TOC. This is the part of the response before the first ':'
+ * @return true if the response can be handled
+ */
+ public boolean canHandle(String Response) {
+ return (Response.equalsIgnoreCase(RESPONSE_TYPE));
+ }
+
+}
diff --git a/src/com/wilko/jaim/ConnectionLostTocResponse.java b/src/com/wilko/jaim/ConnectionLostTocResponse.java
index a01b642..4cc1724 100644
--- a/src/com/wilko/jaim/ConnectionLostTocResponse.java
+++ b/src/com/wilko/jaim/ConnectionLostTocResponse.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -27,24 +27,26 @@ package com.wilko.jaim;
/**
* This is a "pseudo" TOC response - it is delivered to JaimLib clients to indicate that the connection to the server has been lost.
- * @author wilko
+ *
+ * @author wilko
* @version: $revision: $
*/
public class ConnectionLostTocResponse extends TocResponse {
-
- public static final String RESPONSE_TYPE="CONNECTIONLOST";
-
- /** Creates a new instance of LoginCompleteTocResponse */
- public ConnectionLostTocResponse() {
+
+ public static final String RESPONSE_TYPE = "CONNECTIONLOST";
+
+ /**
+ * Creates a new instance of LoginCompleteTocResponse
+ */
+ public ConnectionLostTocResponse() {
}
-
+
public String getResponseType() {
return (RESPONSE_TYPE);
}
-
- public String toString()
- {
+
+ public String toString() {
return (RESPONSE_TYPE);
}
-
+
}
diff --git a/src/com/wilko/jaim/ErrorTocResponse.java b/src/com/wilko/jaim/ErrorTocResponse.java
index abf09b6..1ff8188 100644
--- a/src/com/wilko/jaim/ErrorTocResponse.java
+++ b/src/com/wilko/jaim/ErrorTocResponse.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -27,119 +27,118 @@ package com.wilko.jaim;
import java.util.MissingResourceException;
-/** This TOC response is sent to a {@link JaimEventListener } when an error message is received from the TOC server
+/**
+ * This TOC response is sent to a {@link JaimEventListener } when an error message is received from the TOC server
*
* @author paulw
* @version $Revision: 1.7 $
*/
public class ErrorTocResponse extends TocResponse implements TocResponseHandler {
+ public static final String RESPONSE_TYPE = "ERROR";
int errorCode;
String errorText;
-
- public static final String RESPONSE_TYPE="ERROR";
-
- /** Creates new ErrorTocResponse */
+
+ /**
+ * Creates new ErrorTocResponse
+ */
public ErrorTocResponse() {
- errorCode=0;
- errorText="";
+ errorCode = 0;
+ errorText = "";
}
-
- /** Parse the error response string sent by the TOC server
+ /**
+ * Obtain the error message that corresponds to the specified error code
+ *
+ * @param code The error code
+ * @return The error text
+ */
+ static public String getErrorDescription(int code) {
+ try {
+ return (java.util.ResourceBundle.getBundle("com/wilko/jaim/TocErrorDescriptions").getString(Integer.toString(code)));
+ } catch (MissingResourceException e) {
+ return ("Unable to locate error description:" + e);
+ }
+ }
+
+ /**
+ * Parse the error response string sent by the TOC server
+ *
* @param str The error response string
- */
- public TocResponse parseString(String str)
- {
- ErrorTocResponse tr=new ErrorTocResponse();
+ */
+ public TocResponse parseString(String str) {
+ ErrorTocResponse tr = new ErrorTocResponse();
tr.doParse(str);
- return(tr);
- }
-
- private void doParse(String str)
- {
-
- cmd=str;
- int colonPos=str.indexOf(':');
- if (colonPos!=-1)
- {
- str=str.substring(colonPos+1);
- colonPos=str.indexOf(':');
- if (colonPos!=-1)
- {
- errorCode=Integer.parseInt(str.substring(0,colonPos));
- errorText=str.substring(colonPos+1);
- }
- else
- {
- errorCode=Integer.parseInt(str);
+ return (tr);
+ }
+
+ private void doParse(String str) {
+
+ cmd = str;
+ int colonPos = str.indexOf(':');
+ if (colonPos != -1) {
+ str = str.substring(colonPos + 1);
+ colonPos = str.indexOf(':');
+ if (colonPos != -1) {
+ errorCode = Integer.parseInt(str.substring(0, colonPos));
+ errorText = str.substring(colonPos + 1);
+ } else {
+ errorCode = Integer.parseInt(str);
}
}
-
+
}
-
- /** Obtain the error code for this response
+
+ /**
+ * Obtain the error code for this response
+ *
* @return The error code
- */
- public int getErrorCode()
- {
- return(errorCode);
+ */
+ public int getErrorCode() {
+ return (errorCode);
}
-
- /** Get the error text (if any) associated with this error response
+
+ /**
+ * Get the error text (if any) associated with this error response
+ *
* @return The error text
- */
- public String getErrorText()
- {
- return(errorText);
+ */
+ public String getErrorText() {
+ return (errorText);
}
-
-
- /** Obtain the error message that corresponds to this error.
+
+ /**
+ * Obtain the error message that corresponds to this error.
+ *
* @return The error text with any applicable error argument text inserted
*/
public String getErrorDescription() {
try {
- StringBuffer desc=new StringBuffer(java.util.ResourceBundle.getBundle("com/wilko/jaim/TocErrorDescriptions").getString(Integer.toString(errorCode)));
- String sDesc=desc.toString();
- int argpos=sDesc.indexOf("%s");
+ StringBuffer desc = new StringBuffer(java.util.ResourceBundle.getBundle("com/wilko/jaim/TocErrorDescriptions").getString(Integer.toString(errorCode)));
+ String sDesc = desc.toString();
+ int argpos = sDesc.indexOf("%s");
if (argpos != -1) {
- desc.replace(argpos,argpos+1,errorText);
+ desc.replace(argpos, argpos + 1, errorText);
}
- return(desc.toString());
-
- }
- catch (MissingResourceException e) {
- return("Unable to locate error description:"+e.toString());
+ return (desc.toString());
+
+ } catch (MissingResourceException e) {
+ return ("Unable to locate error description:" + e);
}
}
-
- /** Obtain the error message that corresponds to the specified error code
- * @param code The error code
- * @return The error text
- */
- static public String getErrorDescription(int code)
- {
- try
- {
- return(java.util.ResourceBundle.getBundle("com/wilko/jaim/TocErrorDescriptions").getString(Integer.toString(code)));
- }
- catch (MissingResourceException e)
- {
- return("Unable to locate error description:"+e.toString());
- }
- }
-
- public String getResponseType() {
+
+ public String getResponseType() {
return RESPONSE_TYPE;
}
-
- /** Returns true if this response handler can handle the specified response.
+
+ /**
+ * Returns true if this response handler can handle the specified response.
+ *
* @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled
*/
public boolean canHandle(String Response) {
- return(Response.equalsIgnoreCase(RESPONSE_TYPE));
+ return (Response.equalsIgnoreCase(RESPONSE_TYPE));
}
-
+
}
diff --git a/src/com/wilko/jaim/EvilTocResponse.java b/src/com/wilko/jaim/EvilTocResponse.java
index 475523c..caa7e98 100644
--- a/src/com/wilko/jaim/EvilTocResponse.java
+++ b/src/com/wilko/jaim/EvilTocResponse.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -27,91 +27,99 @@ package com.wilko.jaim;
import java.util.StringTokenizer;
-/** An EvilTocResponse is delivered to a {@link JaimEventListener } when the signed on buddy is "eviled" or warned
+/**
+ * An EvilTocResponse is delivered to a {@link JaimEventListener } when the signed on buddy is "eviled" or warned
+ *
* @author paulw
* @version $Revision: 1.6 $
*/
public class EvilTocResponse extends TocResponse implements TocResponseHandler {
+ public static final String RESPONSE_TYPE = "EVILED";
private boolean anonymousEvil;
private int evilAmount;
private String evilBy;
-
- public static final String RESPONSE_TYPE="EVILED";
-
- /** Creates new EvilTocResponse */
+
+ /**
+ * Creates new EvilTocResponse
+ */
public EvilTocResponse() {
- anonymousEvil=true;
- evilBy="";
- evilAmount=0;
+ anonymousEvil = true;
+ evilBy = "";
+ evilAmount = 0;
}
- /** Parse the evil message from the TOC server
+ /**
+ * Parse the evil message from the TOC server
+ *
* @param str The evil message
- */
+ */
public TocResponse parseString(java.lang.String str) {
- EvilTocResponse tr=new EvilTocResponse();
+ EvilTocResponse tr = new EvilTocResponse();
tr.doParse(str);
- return(tr);
+ return (tr);
}
-
- private void doParse(String str)
- {
-
- StringTokenizer st=new StringTokenizer(str,":");
-
+
+ private void doParse(String str) {
+
+ StringTokenizer st = new StringTokenizer(str, ":");
+
st.nextToken(); // skip over "EVILED"
- evilAmount=Integer.parseInt(st.nextToken());
- if (st.hasMoreTokens())
- {
- evilBy=st.nextToken();
- anonymousEvil=false;
- }
- else
- {
- anonymousEvil=true;
+ evilAmount = Integer.parseInt(st.nextToken());
+ if (st.hasMoreTokens()) {
+ evilBy = st.nextToken();
+ anonymousEvil = false;
+ } else {
+ anonymousEvil = true;
}
}
-
- /** 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
+
+ /**
+ * 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
+ *
* @return The cumulative evil or warning level
- */
- public int getEvilAmount()
- {
- return(evilAmount);
+ */
+ public int getEvilAmount() {
+ return (evilAmount);
}
-
- /** Obtain the name of the buddy that issued the warning.
+
+ /**
+ * Obtain the name of the buddy that issued the warning.
+ *
* @return The buddy name that issued the warning
* @see #isAnonymous
- */
- public String getEvilBy()
- {
- return(evilBy);
+ */
+ public String getEvilBy() {
+ return (evilBy);
}
-
- /** Obtain the anonymous status of this warning
+
+ /**
+ * Obtain the anonymous status of this warning
+ *
* @return true if this warning was issued anonymously
- */
- public boolean isAnonymous()
- {
- return(anonymousEvil);
+ */
+ public boolean isAnonymous() {
+ return (anonymousEvil);
}
-
- /** Used by the response dispatcher
+
+ /**
+ * Used by the response dispatcher
+ *
* @return The response type
- */
- public String getResponseType() {
+ */
+ public String getResponseType() {
return RESPONSE_TYPE;
}
-
-
- /** Returns true if this response handler can handle the specified response.
+
+
+ /**
+ * Returns true if this response handler can handle the specified response.
+ *
* @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled
*/
public boolean canHandle(String Response) {
- return(Response.equalsIgnoreCase(RESPONSE_TYPE));
+ return (Response.equalsIgnoreCase(RESPONSE_TYPE));
}
-
+
}
diff --git a/src/com/wilko/jaim/FLAPDataFrame.java b/src/com/wilko/jaim/FLAPDataFrame.java
index 41a538c..a5bd2ae 100644
--- a/src/com/wilko/jaim/FLAPDataFrame.java
+++ b/src/com/wilko/jaim/FLAPDataFrame.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,51 +26,48 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.3 $
*/
public class FLAPDataFrame extends FLAPFrame {
private int frameLen;
-
- /** Creates new FlapDataFrame */
+
+ /**
+ * Creates new FlapDataFrame
+ */
public FLAPDataFrame() {
- frame[1]=FLAP_FRAME_DATA;
- frameLen=1;
- frame[FLAP_DATA_OFFSET]=0;
+ frame[1] = FLAP_FRAME_DATA;
+ frameLen = 1;
+ frame[FLAP_DATA_OFFSET] = 0;
}
-
- public FLAPDataFrame(byte frameData[])
- {
- frame[1]=FLAP_FRAME_DATA;
- frameLen=1;
- frame[FLAP_DATA_OFFSET]=0;
+
+ public FLAPDataFrame(byte[] frameData) {
+ frame[1] = FLAP_FRAME_DATA;
+ frameLen = 1;
+ frame[FLAP_DATA_OFFSET] = 0;
setFrameData(frameData);
}
-
-
+
+
public int getFLAPFrameType() {
- return(FLAPFrame.FLAP_FRAME_DATA);
+ return (FLAPFrame.FLAP_FRAME_DATA);
}
-
- public void addString(String s)
- {
+
+ public void addString(String s) {
frameLen--; // Backspace over '0'
- for (int i=0;i<s.length();i++)
- {
- frame[FLAP_DATA_OFFSET+frameLen++]=(byte)s.charAt(i);
+ for (int i = 0; i < s.length(); i++) {
+ frame[FLAP_DATA_OFFSET + frameLen++] = (byte) s.charAt(i);
}
- frame[FLAP_DATA_OFFSET+frameLen++]=0;
+ frame[FLAP_DATA_OFFSET + frameLen++] = 0;
setLength(frameLen);
}
-
- public byte[] getContent()
- {
+
+ public byte[] getContent() {
byte[] retarray = new byte[getLength()];
-
- System.arraycopy(frame,FLAPFrame.FLAP_DATA_OFFSET,retarray,0,getLength());
- return(retarray);
+
+ System.arraycopy(frame, FLAPFrame.FLAP_DATA_OFFSET, retarray, 0, getLength());
+ return (retarray);
}
-
+
}
diff --git a/src/com/wilko/jaim/FLAPErrorFrame.java b/src/com/wilko/jaim/FLAPErrorFrame.java
index 90af733..1df6e03 100644
--- a/src/com/wilko/jaim/FLAPErrorFrame.java
+++ b/src/com/wilko/jaim/FLAPErrorFrame.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -25,27 +25,27 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.3 $
*/
public class FLAPErrorFrame extends FLAPFrame {
- /** Creates new FLAPErrorFrame */
+ /**
+ * Creates new FLAPErrorFrame
+ */
public FLAPErrorFrame() {
- frame[1]=FLAP_FRAME_ERROR;
+ frame[1] = FLAP_FRAME_ERROR;
}
-
- public FLAPErrorFrame(byte frameData[])
- {
- frame[1]=FLAP_FRAME_ERROR;
+
+ public FLAPErrorFrame(byte[] frameData) {
+ frame[1] = FLAP_FRAME_ERROR;
setFrameData(frameData);
}
-
-
+
+
public int getFLAPFrameType() {
return FLAPFrame.FLAP_FRAME_ERROR;
}
-
+
}
diff --git a/src/com/wilko/jaim/FLAPFrame.java b/src/com/wilko/jaim/FLAPFrame.java
index 3abc3d8..bef422d 100644
--- a/src/com/wilko/jaim/FLAPFrame.java
+++ b/src/com/wilko/jaim/FLAPFrame.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,94 +26,84 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.4 $
*/
public abstract class FLAPFrame {
- public static final int FLAP_FRAME_SIGNON=1;
- public static final int FLAP_FRAME_DATA=2;
- public static final int FLAP_FRAME_ERROR=3;
- public static final int FLAP_FRAME_SIGNOFF=4;
- public static final int FLAP_FRAME_KEEP_ALIVE=5;
- public static final int FLAP_DATA_OFFSET=6;
-
+ public static final int FLAP_FRAME_SIGNON = 1;
+ public static final int FLAP_FRAME_DATA = 2;
+ public static final int FLAP_FRAME_ERROR = 3;
+ public static final int FLAP_FRAME_SIGNOFF = 4;
+ public static final int FLAP_FRAME_KEEP_ALIVE = 5;
+ public static final int FLAP_DATA_OFFSET = 6;
+
protected byte[] frame;
protected int fLen;
-
- /** Creates new FLAPFrame */
+
+ /**
+ * Creates new FLAPFrame
+ */
public FLAPFrame() {
initialise();
}
-
- protected void setFrameData(byte b[])
- {
- frame=new byte[b.length];
- fLen=b.length;
- System.arraycopy(b,0,frame,0,b.length);
- }
-
- protected void initialise()
- {
+
+ protected void initialise() {
frame = new byte[8192];
- frame[0]=(byte)'*';
- frame[1]=0;
- frame[2]=0;
- frame[3]=0;
- frame[4]=0;
- frame[5]=0;
- fLen=6;
-
+ frame[0] = (byte) '*';
+ frame[1] = 0;
+ frame[2] = 0;
+ frame[3] = 0;
+ frame[4] = 0;
+ frame[5] = 0;
+ fLen = 6;
+
+ }
+
+ public int getSequence() {
+ return ((frame[2] & 0xff) * 256 + (frame[3] & 0xff));
}
-
- public void setSequence(int sequence)
- {
- frame[2]=(byte)((sequence/256)&0xff);
- frame[3]=(byte)(sequence&0xff);
+
+ public void setSequence(int sequence) {
+ frame[2] = (byte) ((sequence / 256) & 0xff);
+ frame[3] = (byte) (sequence & 0xff);
}
-
- public int getSequence()
- {
- return((frame[2]&0xff)*256+(frame[3]&0xff));
+
+ public int getLength() {
+ return ((frame[4] & 0xff) * 256 + (frame[5] & 0xff));
}
-
- public int getLength()
- {
- return((frame[4]&0xff)*256+(frame[5]&0xff));
+
+ public void setLength(int length) {
+ frame[4] = (byte) (length / 256);
+ frame[5] = (byte) (length & 0xff);
+ fLen = length + FLAP_DATA_OFFSET;
}
-
- public void setLength(int length)
- {
- frame[4]=(byte)(length/256);
- frame[5]=(byte)(length&0xff);
- fLen=length+FLAP_DATA_OFFSET;
+
+ public byte[] getFrameData() {
+ byte[] b = new byte[fLen];
+ System.arraycopy(frame, 0, b, 0, fLen);
+ return (b);
}
-
- public byte[] getFrameData()
- {
- byte[] b=new byte[fLen];
- System.arraycopy(frame,0,b,0,fLen);
- return(b);
+
+ protected void setFrameData(byte[] b) {
+ frame = new byte[b.length];
+ fLen = b.length;
+ System.arraycopy(b, 0, frame, 0, b.length);
+ }
+
+ public String toString() {
+ StringBuffer temp = new StringBuffer();
+ for (int i = 0; i < fLen; i++) {
+ int k = frame[i] & 0xff;
+ if (k < 16) {
+ temp.append("0" + Integer.toHexString(k) + " ");
+ } else {
+ temp.append(Integer.toHexString(k) + " ");
+ }
+ }
+ return (temp.toString());
}
- public String toString()
- {
- StringBuffer temp=new StringBuffer();
- for (int i=0;i<fLen;i++)
- {
- int k=frame[i]&0xff;
- if (k<16)
- {
- temp.append("0"+Integer.toHexString(k)+" ");
- }
- else
- {
- temp.append(Integer.toHexString(k)+" ");
- }
- }
- return(temp.toString());
-}
public abstract int getFLAPFrameType();
-
+
}
diff --git a/src/com/wilko/jaim/FLAPFrameException.java b/src/com/wilko/jaim/FLAPFrameException.java
index 75ecfc5..c30281b 100644
--- a/src/com/wilko/jaim/FLAPFrameException.java
+++ b/src/com/wilko/jaim/FLAPFrameException.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,8 +26,7 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.3 $
*/
public class FLAPFrameException extends java.lang.Exception {
@@ -41,6 +40,7 @@ public class FLAPFrameException extends java.lang.Exception {
/**
* Constructs an <code>FLAPFrameException</code> with the specified detail message.
+ *
* @param msg the detail message.
*/
public FLAPFrameException(String msg) {
diff --git a/src/com/wilko/jaim/FLAPFrameFactory.java b/src/com/wilko/jaim/FLAPFrameFactory.java
index 475f1d5..4df9fac 100644
--- a/src/com/wilko/jaim/FLAPFrameFactory.java
+++ b/src/com/wilko/jaim/FLAPFrameFactory.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,44 +26,43 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.3 $
*/
public abstract class FLAPFrameFactory {
- /** Creates new FLAPFrameFactory */
+ /**
+ * Creates new FLAPFrameFactory
+ */
public FLAPFrameFactory() {
}
public static FLAPFrame createFLAPFrame(byte[] frameData) throws FLAPFrameException {
- FLAPFrame f=null;
- if (frameData[0]!='*')
- {
+ FLAPFrame f = null;
+ if (frameData[0] != '*') {
throw new FLAPFrameException("Frame does not start with '*'");
}
-
- switch (frameData[1])
- {
+
+ switch (frameData[1]) {
case FLAPFrame.FLAP_FRAME_SIGNON:
- f=new FLAPSignonFrame(frameData);
+ f = new FLAPSignonFrame(frameData);
break;
case FLAPFrame.FLAP_FRAME_DATA:
- f=new FLAPDataFrame(frameData);
+ f = new FLAPDataFrame(frameData);
break;
case FLAPFrame.FLAP_FRAME_ERROR:
- f=new FLAPErrorFrame(frameData);
+ f = new FLAPErrorFrame(frameData);
break;
case FLAPFrame.FLAP_FRAME_SIGNOFF:
- f=new FLAPSignoffFrame(frameData);
+ f = new FLAPSignoffFrame(frameData);
break;
case FLAPFrame.FLAP_FRAME_KEEP_ALIVE:
- f=new FLAPKeepAliveFrame(frameData);
+ f = new FLAPKeepAliveFrame(frameData);
break;
default:
- throw new FLAPFrameException("Illegal FLAP Frame type: "+Integer.toString(frameData[1]));
+ throw new FLAPFrameException("Illegal FLAP Frame type: " + Integer.toString(frameData[1]));
}
- return(f);
+ return (f);
}
}
diff --git a/src/com/wilko/jaim/FLAPInputFrame.java b/src/com/wilko/jaim/FLAPInputFrame.java
index bdceb3c..c432f03 100644
--- a/src/com/wilko/jaim/FLAPInputFrame.java
+++ b/src/com/wilko/jaim/FLAPInputFrame.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,51 +26,44 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.3 $
*/
public class FLAPInputFrame extends FLAPFrame {
- /** Creates new FLAPInputFrame */
- private int frameLen;
-
+ /**
+ * Creates new FLAPInputFrame
+ */
+ private int frameLen;
+
public FLAPInputFrame() {
- frameLen=0;
+ frameLen = 0;
super.initialise();
}
-
- public void addFrameData(byte b)
- {
- frame[frameLen++]=b;
+
+ public void addFrameData(byte b) {
+ frame[frameLen++] = b;
}
- public byte[] getFrameData()
- {
- byte[] b=new byte[frameLen];
- System.arraycopy(frame,0,b,0,frameLen);
- return(b);
+ public byte[] getFrameData() {
+ byte[] b = new byte[frameLen];
+ System.arraycopy(frame, 0, b, 0, frameLen);
+ return (b);
}
-
- public void resetInputFrame()
- {
- frameLen=0;
+
+ public void resetInputFrame() {
+ frameLen = 0;
}
-
- public boolean completeFrameRead()
- {
- if (frameLen > 5)
- {
- if (frameLen-6 == getLength())
- {
- return(true);
- }
+
+ public boolean completeFrameRead() {
+ if (frameLen > 5) {
+ return frameLen - 6 == getLength();
}
- return(false);
+ return (false);
}
-
+
public int getFLAPFrameType() {
- return(-1);
+ return (-1);
}
-
+
}
diff --git a/src/com/wilko/jaim/FLAPKeepAliveFrame.java b/src/com/wilko/jaim/FLAPKeepAliveFrame.java
index 561c53e..b47e96f 100644
--- a/src/com/wilko/jaim/FLAPKeepAliveFrame.java
+++ b/src/com/wilko/jaim/FLAPKeepAliveFrame.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,31 +26,30 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.4 $
*/
public class FLAPKeepAliveFrame extends FLAPFrame {
- /** Creates new FLAPKeepAliveFrame */
+ /**
+ * Creates new FLAPKeepAliveFrame
+ */
public FLAPKeepAliveFrame() {
this.initialise();
}
-
- public FLAPKeepAliveFrame(byte frameData[])
- {
+
+ public FLAPKeepAliveFrame(byte[] frameData) {
initialise();
setFrameData(frameData);
}
-
- protected void initialise()
- {
+
+ protected void initialise() {
super.initialise();
- frame[1]=FLAP_FRAME_KEEP_ALIVE;
+ frame[1] = FLAP_FRAME_KEEP_ALIVE;
}
-
+
public int getFLAPFrameType() {
return (FLAPFrame.FLAP_FRAME_KEEP_ALIVE);
}
-
+
}
diff --git a/src/com/wilko/jaim/FLAPSignoffFrame.java b/src/com/wilko/jaim/FLAPSignoffFrame.java
index 11c93af..1d8653d 100644
--- a/src/com/wilko/jaim/FLAPSignoffFrame.java
+++ b/src/com/wilko/jaim/FLAPSignoffFrame.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,27 +26,27 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.3 $
*/
public class FLAPSignoffFrame extends FLAPFrame {
- /** Creates new FlapSignonFrame */
+ /**
+ * Creates new FlapSignonFrame
+ */
public FLAPSignoffFrame() {
-
- frame[1]=FLAP_FRAME_SIGNOFF;
+
+ frame[1] = FLAP_FRAME_SIGNOFF;
}
-
- public FLAPSignoffFrame(byte frameData[])
- {
- frame[1]=FLAP_FRAME_SIGNOFF;
+
+ public FLAPSignoffFrame(byte[] frameData) {
+ frame[1] = FLAP_FRAME_SIGNOFF;
setFrameData(frameData);
}
-
-
+
+
public int getFLAPFrameType() {
- return(FLAPFrame.FLAP_FRAME_SIGNOFF);
+ return (FLAPFrame.FLAP_FRAME_SIGNOFF);
}
-
+
}
diff --git a/src/com/wilko/jaim/FLAPSignonFrame.java b/src/com/wilko/jaim/FLAPSignonFrame.java
index 93ef5ed..48aa4fe 100644
--- a/src/com/wilko/jaim/FLAPSignonFrame.java
+++ b/src/com/wilko/jaim/FLAPSignonFrame.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,65 +26,57 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.3 $
*/
public class FLAPSignonFrame extends FLAPFrame {
- /** Creates new FlapSignonFrame */
+ /**
+ * Creates new FlapSignonFrame
+ */
public FLAPSignonFrame() {
- frame[1]=FLAP_FRAME_SIGNON;
+ frame[1] = FLAP_FRAME_SIGNON;
}
-
- public FLAPSignonFrame(byte frameData[])
- {
- frame[1]=FLAP_FRAME_SIGNON;
+
+ public FLAPSignonFrame(byte[] frameData) {
+ frame[1] = FLAP_FRAME_SIGNON;
setFrameData(frameData);
}
-
- public int getFLAPVersion()
- {
- return(((frame[6]&0xff)*16777216)+((frame[7]&0xff)*65536)+((frame[8]&0xff)*256)+(frame[9]&0xff));
+
+ public int getFLAPVersion() {
+ return (((frame[6] & 0xff) * 16777216) + ((frame[7] & 0xff) * 65536) + ((frame[8] & 0xff) * 256) + (frame[9] & 0xff));
}
-
- public void setFLAPVersion(int version)
- {
- for (int i=3;i>=0;i--)
- {
- frame[6+i]=(byte)(version&0xff);
- version=version>>8;
+
+ public void setFLAPVersion(int version) {
+ for (int i = 3; i >= 0; i--) {
+ frame[6 + i] = (byte) (version & 0xff);
+ version = version >> 8;
}
}
-
- public void setTLVTag(int tag)
- {
- for (int i=1;i>=0;i--)
- {
- frame[10+i]=(byte)(tag&0xff);
- tag=tag>>8;
+
+ public void setTLVTag(int tag) {
+ for (int i = 1; i >= 0; i--) {
+ frame[10 + i] = (byte) (tag & 0xff);
+ tag = tag >> 8;
}
}
-
- public void setUserName(String name)
- {
-
- int len=0;
- for (int i=0;i<name.length();i++)
- {
- char c = name.charAt(i);
- if (c != ' ')
- {
- frame[FLAP_DATA_OFFSET+8+len++]=(byte)c;
- }
+
+ public void setUserName(String name) {
+
+ int len = 0;
+ for (int i = 0; i < name.length(); i++) {
+ char c = name.charAt(i);
+ if (c != ' ') {
+ frame[FLAP_DATA_OFFSET + 8 + len++] = (byte) c;
+ }
}
- setLength(8+len);
- frame[FLAP_DATA_OFFSET+6]=(byte)(len/256);
- frame[FLAP_DATA_OFFSET+7]=(byte)(len&0xff);
+ setLength(8 + len);
+ frame[FLAP_DATA_OFFSET + 6] = (byte) (len / 256);
+ frame[FLAP_DATA_OFFSET + 7] = (byte) (len & 0xff);
}
-
+
public int getFLAPFrameType() {
- return(FLAPFrame.FLAP_FRAME_SIGNON);
+ return (FLAPFrame.FLAP_FRAME_SIGNON);
}
-
-} \ No newline at end of file
+
+}
diff --git a/src/com/wilko/jaim/GenericTocResponse.java b/src/com/wilko/jaim/GenericTocResponse.java
index c3a6290..79e1389 100644
--- a/src/com/wilko/jaim/GenericTocResponse.java
+++ b/src/com/wilko/jaim/GenericTocResponse.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -25,61 +25,71 @@
package com.wilko.jaim;
-/** A GenericTocResponse is used internally in the Response parsing and processing logic of {@link JaimConnection}
+/**
+ * A GenericTocResponse is used internally in the Response parsing and processing logic of {@link JaimConnection}
+ *
* @author paulw
* @version $Revision: 1.5 $
*/
public class GenericTocResponse extends TocResponse implements TocResponseHandler {
- /** Creates new GenericTocCommand */
+ /**
+ * Creates new GenericTocCommand
+ */
public GenericTocResponse() {
- this.cmd="";
+ this.cmd = "";
}
-
- /** Parse an incoming string
+
+ /**
+ * Parse an incoming string
+ *
* @param str The response string to be parsed
- */
- public TocResponse parseString(String str)
- {
- GenericTocResponse tr=new GenericTocResponse();
+ */
+ public TocResponse parseString(String str) {
+ GenericTocResponse tr = new GenericTocResponse();
tr.doParse(str);
return tr;
}
-
- private void doParse(String str)
- {
- cmd=str;
+
+ private void doParse(String str) {
+ cmd = str;
}
- /** Get a byte array that contains the response
+ /**
+ * Get a byte array that contains the response
+ *
* @return The response as an array of bytes
- */
+ */
public byte[] getBytes() {
- return(cmd.getBytes());
+ return (cmd.getBytes());
}
-
- /** Convert this response to a string
+
+ /**
+ * Convert this response to a string
+ *
* @return The response as a string
- */
- public String toString()
- {
- return(cmd);
+ */
+ public String toString() {
+ return (cmd);
}
-
- /** Used in the response dispatching process
+
+ /**
+ * Used in the response dispatching process
+ *
* @return The respnse type
- */
- public String getResponseType()
- {
- return("UNKNOWN");
+ */
+ public String getResponseType() {
+ return ("UNKNOWN");
}
-
- /** Returns true if this response handler can handle the specified response.
+
+ /**
+ * Returns true if this response handler can handle the specified response.
+ *
* @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled
*/
public boolean canHandle(String Response) {
- return(true);
+ return (true);
}
-
+
}
diff --git a/src/com/wilko/jaim/GotoTocResponse.java b/src/com/wilko/jaim/GotoTocResponse.java
index 4257510..caf9441 100644
--- a/src/com/wilko/jaim/GotoTocResponse.java
+++ b/src/com/wilko/jaim/GotoTocResponse.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -25,82 +25,89 @@
package com.wilko.jaim;
-/** This response is delivered to a {@link JaimEventListener } when a GOTO response is received from TOC
+/**
+ * This response is delivered to a {@link JaimEventListener } when a GOTO response is received from TOC
+ *
* @author paulw
* @version $Revision: 1.3 $
*/
public class GotoTocResponse extends TocResponse implements TocResponseHandler {
+ public static final String RESPONSE_TYPE = "GOTO_URL";
String windowName;
boolean autoResponse;
String URL;
-
- public static final String RESPONSE_TYPE="GOTO_URL";
-
- /** Creates new GotoTocResponse */
+
+ /**
+ * Creates new GotoTocResponse
+ */
public GotoTocResponse() {
- windowName="";
- URL="";
+ windowName = "";
+ URL = "";
}
-
- /** Obtain the suggested window name for this URL
+
+ /**
+ * Obtain the suggested window name for this URL
+ *
* @return The window name
- */
- public String getWindowName()
- {
- return(windowName);
+ */
+ public String getWindowName() {
+ return (windowName);
}
-
- /** Obtain the URL
+
+ /**
+ * Obtain the URL
+ *
* @return The URL
- */
- public String getURL()
- {
- return(URL);
+ */
+ public String getURL() {
+ return (URL);
}
-
-
- /** Parse an incoming response string
+
+ /**
+ * Parse an incoming response string
+ *
* @param str The string to be parsed
- */
+ */
public TocResponse parseString(java.lang.String str) {
- GotoTocResponse tr=new GotoTocResponse();
+ GotoTocResponse tr = new GotoTocResponse();
tr.doParse(str);
- return(tr);
+ return (tr);
}
-
- private void doParse(String str)
- {
- cmd=str;
- int colonPos=str.indexOf(':');
- if (colonPos!=-1)
- {
- str=str.substring(colonPos+1);
- colonPos=str.indexOf(':');
- if (colonPos != -1)
- {
- windowName=str.substring(0,colonPos);
- URL=str.substring(colonPos+1);
-
+
+ private void doParse(String str) {
+ cmd = str;
+ int colonPos = str.indexOf(':');
+ if (colonPos != -1) {
+ str = str.substring(colonPos + 1);
+ colonPos = str.indexOf(':');
+ if (colonPos != -1) {
+ windowName = str.substring(0, colonPos);
+ URL = str.substring(colonPos + 1);
+
}
}
-
+
}
-
- /** Obtain the response type for response dispatching purposes
+
+ /**
+ * Obtain the response type for response dispatching purposes
+ *
* @return The response type
- */
+ */
public String getResponseType() {
- return(RESPONSE_TYPE);
+ return (RESPONSE_TYPE);
}
-
- /** Returns true if this response handler can handle the specified response.
+
+ /**
+ * Returns true if this response handler can handle the specified response.
+ *
* @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled
*/
public boolean canHandle(String Response) {
return (Response.equalsIgnoreCase(RESPONSE_TYPE));
}
-
+
}
diff --git a/src/com/wilko/jaim/Group.java b/src/com/wilko/jaim/Group.java
index 359e224..5adcdbe 100644
--- a/src/com/wilko/jaim/Group.java
+++ b/src/com/wilko/jaim/Group.java
@@ -25,72 +25,90 @@
package com.wilko.jaim;
-import java.util.Vector;
-import java.util.List;
import java.util.Enumeration;
+import java.util.Vector;
-/** This is a logical user group. It holds a set of users.
+/**
+ * This is a logical user group. It holds a set of users.
+ *
* @author Brett Humphreys
*/
public class Group {
-
- /** Vector of buddies for this group */
- private Vector buddies = new Vector();
-
- /** Name of this group */
- private String groupName;
-
- /** This constructor sets the name of the group
+
+ /**
+ * Vector of buddies for this group
+ */
+ private final Vector buddies = new Vector();
+
+ /**
+ * Name of this group
+ */
+ private final String groupName;
+
+ /**
+ * This constructor sets the name of the group
+ *
* @param name the group name
*/
- public Group( String name ) {
+ public Group(String name) {
groupName = name;
}
-
- /** This method adds a buddy to the end of the group
+
+ /**
+ * This method adds a buddy to the end of the group
+ *
* @param buddy The buddy object to associate with this group
*/
public void addBuddy(Buddy buddy) {
buddies.add(buddy);
}
-
- /** This method adds a buddy to the specified location in the group
- * If the specified location is beyond the end of the group, then the buddy is added to the end of the group
+
+ /**
+ * This method adds a buddy to the specified location in the group
+ * If the specified location is beyond the end of the group, then the buddy is added to the end of the group
+ *
* @param buddy The buddy object to associate with this group
- * @param pos the position to add the buddy
+ * @param pos the position to add the buddy
*/
- public void addBuddy(Buddy buddy,int pos) {
+ public void addBuddy(Buddy buddy, int pos) {
if (pos > buddies.size()) {
buddies.add(buddy);
- }
- else {
- buddies.add(pos,buddy);
+ } else {
+ buddies.add(pos, buddy);
}
}
-
- /** This method gets the group name
+
+ /**
+ * This method gets the group name
+ *
* @return the group name
*/
public String getName() {
return groupName;
}
-
- /** This method returns the buddies in this group
+
+ /**
+ * This method returns the buddies in this group
+ *
* @return an Enumeration of {@link Buddy} objects
*/
public Enumeration enumerateBuddies() {
return buddies.elements();
}
-
- /** This method returns the number of buddies in this group
+
+ /**
+ * This method returns the number of buddies in this group
+ *
* @return buddy count
*/
public int getBuddyCount() {
- return(buddies.size());
+ return (buddies.size());
}
- /** This method returns the buddies in this group
- * @return a Collection of {@link Buddy} objects
+ /**
+ * This method returns the buddies in this group
+ *
+ * @return a Collection of {@link Buddy} objects
*/
public java.util.Collection getBuddies() {
java.util.Collection cReturn = new java.util.Vector(buddies);
diff --git a/src/com/wilko/jaim/IMTocResponse.java b/src/com/wilko/jaim/IMTocResponse.java
index ff10804..70a616e 100644
--- a/src/com/wilko/jaim/IMTocResponse.java
+++ b/src/com/wilko/jaim/IMTocResponse.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -25,98 +25,105 @@
package com.wilko.jaim;
-/** This response is delivered to a {@link JaimEventListener } when an instant message is received
+/**
+ * This response is delivered to a {@link JaimEventListener } when an instant message is received
+ *
* @author paulw
* @version $Revision: 1.6 $
*/
public class IMTocResponse extends TocResponse implements TocResponseHandler {
+ public static final String RESPONSE_TYPE = "IM_IN";
String from;
boolean autoResponse;
String msg;
-
- public static final String RESPONSE_TYPE="IM_IN";
-
- /** Creates new TocIMResponse */
+
+ /**
+ * Creates new TocIMResponse
+ */
public IMTocResponse() {
- from="";
- msg="";
- autoResponse=false;
+ from = "";
+ msg = "";
+ autoResponse = false;
}
-
- /** Obtain the name of the buddy who sent this instant message
+
+ /**
+ * Obtain the name of the buddy who sent this instant message
+ *
* @return The senders name
- */
- public String getFrom()
- {
- return(from);
+ */
+ public String getFrom() {
+ return (from);
}
-
- /** Obtain the message
+
+ /**
+ * Obtain the message
+ *
* @return The message
* @see Utils#stripHTML
- */
- public String getMsg()
- {
- return(msg);
+ */
+ public String getMsg() {
+ return (msg);
}
-
- /** Is this response an automatically generated response?
+
+ /**
+ * Is this response an automatically generated response?
+ *
* @return true if this is an automatically generated response
- */
- public boolean getAutoResponse()
- {
- return(autoResponse);
+ */
+ public boolean getAutoResponse() {
+ return (autoResponse);
}
- /** Parse an incoming IM response string
+ /**
+ * Parse an incoming IM response string
+ *
* @param str The string to be parsed
- */
+ */
public TocResponse parseString(java.lang.String str) {
- IMTocResponse tr=new IMTocResponse();
+ IMTocResponse tr = new IMTocResponse();
tr.doParse(str);
- return(tr);
+ return (tr);
}
-
- private void doParse(String str)
- {
- cmd=str;
- int colonPos=str.indexOf(':');
- if (colonPos!=-1)
- {
- str=str.substring(colonPos+1);
- colonPos=str.indexOf(':');
- if (colonPos != -1)
- {
- from=str.substring(0,colonPos);
- str=str.substring(colonPos+1);
- colonPos=str.indexOf(':');
- if (str.charAt(0) == 'T')
- {
- autoResponse=true;
+
+ private void doParse(String str) {
+ cmd = str;
+ int colonPos = str.indexOf(':');
+ if (colonPos != -1) {
+ str = str.substring(colonPos + 1);
+ colonPos = str.indexOf(':');
+ if (colonPos != -1) {
+ from = str.substring(0, colonPos);
+ str = str.substring(colonPos + 1);
+ colonPos = str.indexOf(':');
+ if (str.charAt(0) == 'T') {
+ autoResponse = true;
}
- if (colonPos != -1)
- {
- msg=str.substring(colonPos+1);
+ if (colonPos != -1) {
+ msg = str.substring(colonPos + 1);
}
}
}
-
+
}
-
- /** Obtain the response type for response dispatching purposes
+
+ /**
+ * Obtain the response type for response dispatching purposes
+ *
* @return The response type
- */
+ */
public String getResponseType() {
- return(RESPONSE_TYPE);
+ return (RESPONSE_TYPE);
}
-
- /** Returns true if this response handler can handle the specified response.
+
+ /**
+ * Returns true if this response handler can handle the specified response.
+ *
* @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled
*/
public boolean canHandle(String Response) {
return (Response.equalsIgnoreCase(RESPONSE_TYPE));
}
-
+
}
diff --git a/src/com/wilko/jaim/JaimConnection.java b/src/com/wilko/jaim/JaimConnection.java
index 7fbd133..09a8627 100644
--- a/src/com/wilko/jaim/JaimConnection.java
+++ b/src/com/wilko/jaim/JaimConnection.java
@@ -25,21 +25,31 @@
package com.wilko.jaim;
-import java.net.*;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InterruptedIOException;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.Socket;
+import java.net.URL;
import java.text.DateFormat;
-import java.io.*;
import java.util.*;
-/** The JaimConnection object is the primary interface into the Jaim library.
- * Programs should instantiate a JaimConnection (in most cases the simple constructor should be used).
- * Once JaimConnection has been instantiated, call {@link #connect} followed by {@link #logIn}.
- *
+/**
+ * The JaimConnection object is the primary interface into the Jaim library.
+ * Programs should instantiate a JaimConnection (in most cases the simple constructor should be used).
+ * Once JaimConnection has been instantiated, call {@link #connect} followed by {@link #logIn}.
*
* @author paulw
* @version $Revision: 1.20 $
*/
public class JaimConnection implements java.lang.Runnable {
-
+
+ private static final int MAX_POINTS = 10;
+ private static final int BLOCK_POINTS = 5;
+ private static final int POINT_RECOVERY_TIME = 2200; // Recover one point every 2.2 seconds
+ private static final int THRESHOLD_DELAY = 5000; // Delay when we are threshold of being blocked
+ private static final int WAIT_TIME = 61000; // Wait 61 secs for a keep alive
private Socket s;
private InputStream sin;
private OutputStream sout;
@@ -47,8 +57,8 @@ public class JaimConnection implements java.lang.Runnable {
private boolean loggedIn;
private boolean loginComplete;
private boolean configValid;
- private String host;
- private int port;
+ private final String host;
+ private final int port;
private int clientSequence;
private int serverSequence;
private ReceiverThread rt;
@@ -64,56 +74,51 @@ public class JaimConnection implements java.lang.Runnable {
private Vector messageQueue;
private boolean exit;
private long lastKeepAlive;
-
// Number of send "points" - used to control send rate
- private int sendPoints=10;
-
-
- private static final int MAX_POINTS=10;
- private static final int BLOCK_POINTS=5;
- private static final int POINT_RECOVERY_TIME=2200; // Recover one point every 2.2 seconds
- private static final int THRESHOLD_DELAY=5000; // Delay when we are threshold of being blocked
-
- private static final int WAIT_TIME=61000; // Wait 61 secs for a keep alive
-
- /** Creates new JaimConnection that connects to the default host and port.
- * In most cases this constructor should be used.
+ private int sendPoints = 10;
+
+ /**
+ * Creates new JaimConnection that connects to the default host and port.
+ * In most cases this constructor should be used.
*/
public JaimConnection() {
- host="toc.oscar.aol.com";
- port=9898;
+ host = "toc.oscar.aol.com";
+ port = 9898;
startMe();
-
+
}
-
- /** Creates a new Jaim Connection to the specified host/port.
+
+ /**
+ * Creates a new Jaim Connection to the specified host/port.
* There are currently no reasons to call this constructor, however AOL may change the TOC host and port in the future
+ *
* @param host The hostname or IP address of the TOC server
* @param port The port number to connect to on the host
*/
- public JaimConnection(String host,int port) {
- this.host=host;
- this.port=port;
+ public JaimConnection(String host, int port) {
+ this.host = host;
+ this.port = port;
startMe();
}
-
- /** start the message dispatcher thread
+
+ /**
+ * start the message dispatcher thread
*/
-
+
private void startMe() {
- connected=false;
- loggedIn=false;
- eventListeners=new Vector();
- loginComplete=false;
- lastMessageSendTime=0;
- watchedBuddies=new HashMap();
- buddies=new HashMap();
- groups=new HashMap();
- debug=false;
- exit=false;
- rt=null;
- configValid=false;
- lastKeepAlive=System.currentTimeMillis();
+ connected = false;
+ loggedIn = false;
+ eventListeners = new Vector();
+ loginComplete = false;
+ lastMessageSendTime = 0;
+ watchedBuddies = new HashMap();
+ buddies = new HashMap();
+ groups = new HashMap();
+ debug = false;
+ exit = false;
+ rt = null;
+ configValid = false;
+ lastKeepAlive = System.currentTimeMillis();
TocResponseFactory.addResponseHandler(new BuddyUpdateTocResponse());
TocResponseFactory.addResponseHandler(new ErrorTocResponse());
TocResponseFactory.addResponseHandler(new EvilTocResponse());
@@ -123,488 +128,498 @@ public class JaimConnection implements java.lang.Runnable {
TocResponseFactory.addResponseHandler(new GotoTocResponse());
TocResponseFactory.addResponseHandler(new ConfigTocResponse());
TocResponseFactory.addResponseHandler(new ChatInviteTocResponse());
- messageQueue=new Vector();
+ messageQueue = new Vector();
myThread = new Thread(this);
myThread.setDaemon(true);
myThread.start();
- dt=new DeliveryThread();
+ dt = new DeliveryThread();
dt.setDaemon(true);
dt.start();
}
-
-
-
- /** Enable/Disable debugging messages to stdout
+
+
+ /**
+ * Enable/Disable debugging messages to stdout
+ *
* @param debug true if debugging messages should be output
*/
-
+
public void setDebug(boolean debug) {
- this.debug=debug;
+ this.debug = debug;
}
-
-
- /** Specify the intermessage delay time. <br>
+
+ /**
+ * Get the intermessage delay time
+ *
+ * @return The intermessage delay time in milliseconds
+ * @deprecated This function is no longer used
+ */
+ public long getInterMessageDelay() {
+ return (0);
+ }
+
+ /**
+ * Specify the intermessage delay time. <br>
* The {@link #sendIM } method will ensure that at least this amount of time has elapsed between messages
+ *
* @param msec The delay period in milliseconds
* @deprecated This function is no longer used - send throttling is automatic
*/
public void setInterMessageDelay(long msec) {
-
- }
-
- /** Get the intermessage delay time
- * @return The intermessage delay time in milliseconds
- * @deprecated This function is no longer used
- */
- public long getInterMessageDelay() {
- return(0);
+
}
-
- /** Set the EventListener object. This object will be notified of incoming TOC events
+
+ /**
+ * Set the EventListener object. This object will be notified of incoming TOC events
+ *
* @param l The listener class to be notified
* @deprecated replaced by {@link #addEventListener}
*/
public void setEventListener(JaimEventListener l) throws TooManyListenersException {
eventListeners.add(l);
}
-
- /** Add an EventListener object. This object will be notified of incoming TOC events
+
+ /**
+ * Add an EventListener object. This object will be notified of incoming TOC events
+ *
* @param l The listener class to be notified
*/
-
+
public void addEventListener(JaimEventListener l) {
eventListeners.add(l);
}
-
- /** Remove an EventListener object. This object will no longer be notified of incoming TOC events
- * @param l The listener class to be removed
+
+ /**
+ * Remove an EventListener object. This object will no longer be notified of incoming TOC events
+ *
+ * @param l The listener class to be removed
*/
-
+
public void removeEventListener(JaimEventListener l) {
eventListeners.remove(l);
}
-
-
- /** Initiate a connection to the TOC server
+
+
+ /**
+ * Initiate a connection to the TOC server
+ *
* @throws IOException If an underlying network communication fails
*/
public void connect() throws IOException {
- s=new Socket(host,port);
+ s = new Socket(host, port);
s.setSoTimeout(500);
- sin=s.getInputStream();
- sout=s.getOutputStream();
-
+ sin = s.getInputStream();
+ sout = s.getOutputStream();
+
sout.write("FLAPON\r\n\r\n".getBytes());
-
+
FLAPInputFrame inFrame = new FLAPInputFrame();
-
- int i=-1;
-
-
+
+ int i = -1;
+
+
while (!inFrame.completeFrameRead()) {
- i=sin.read();
- inFrame.addFrameData((byte)i);
+ i = sin.read();
+ inFrame.addFrameData((byte) i);
}
-
+
try {
FLAPFrame f = FLAPFrameFactory.createFLAPFrame(inFrame.getFrameData());
- FLAPSignonFrame sf = (FLAPSignonFrame)f;
+ FLAPSignonFrame sf = (FLAPSignonFrame) f;
if (debug) {
- System.out.println("Starting sequence="+sf.getSequence());
- System.out.println("FLAP version = "+sf.getFLAPVersion());
+ System.out.println("Starting sequence=" + sf.getSequence());
+ System.out.println("FLAP version = " + sf.getFLAPVersion());
}
- clientSequence=sf.getSequence();
- serverSequence=sf.getSequence();
- }
- catch (FLAPFrameException e) {
- throw new IOException("FLAPFrameException:"+e.toString());
+ clientSequence = sf.getSequence();
+ serverSequence = sf.getSequence();
+ } catch (FLAPFrameException e) {
+ throw new IOException("FLAPFrameException:" + e);
}
- if (rt!=null) {
+ if (rt != null) {
rt.pleaseExit();
}
- rt=new ReceiverThread(this);
+ rt = new ReceiverThread(this);
rt.setInputStream(sin);
rt.setDaemon(true);
rt.start();
- connected=true;
+ connected = true;
}
-
- /** Disconnect from the TOC server
+
+ /**
+ * Disconnect from the TOC server
+ *
* @throws IOException if a network transport error occurs
*/
public void disconnect() throws IOException {
- exit=true;
+ exit = true;
rt.pleaseExit();
try {
rt.join(700);
myThread.join(700);
+ } catch (InterruptedException e) {
}
- catch (InterruptedException e) {
- }
-
+
if (connected) {
if (loggedIn) {
logOut();
}
s.close();
- connected=false;
+ connected = false;
}
}
-
-
- /** Check if the TOC login process has completed
+
+
+ /**
+ * Check if the TOC login process has completed
+ *
* @return true if the login process is complete
*/
public boolean isLoginComplete() {
- return(loginComplete);
+ return (loginComplete);
}
-
- /** Log out from the TOC server
+
+ /**
+ * Log out from the TOC server
*/
public void logOut() {
- loggedIn=false;
- loginComplete=false;
- configValid=false;
-
+ loggedIn = false;
+ loginComplete = false;
+ configValid = false;
+
}
-
- /** Get the formatted Nick Name for this connection. If no formatted nick name has been registered with the TOC server, then the username provided to the logIn call is returned
+
+ /**
+ * Get the formatted Nick Name for this connection. If no formatted nick name has been registered with the TOC server, then the username provided to the logIn call is returned
+ *
* @return The Nick Name associated with this connection
*/
public String getNickName() {
- return(nickName);
+ return (nickName);
}
-
- /** login to the TOC server. {@link #connect() } method should be called first
+
+ /**
+ * login to the TOC server. {@link #connect() } method should be called first
+ *
* @param username The username to log in with
* @param password the password for the specified username
* @param waitTime time in milliseconds for successful login before declaring an error
- * @throws IOException If a network error occurs
+ * @throws IOException If a network error occurs
* @throws JaimException If a login failure occurs or login fails to complete before waittime expires
*/
- public void logIn(String username,String password,int waitTime) throws JaimException, IOException {
+ public void logIn(String username, String password, int waitTime) throws JaimException, IOException {
if (connected) {
-
- nickName=username;
- String nuser=Utils.normalise(username);
+
+ nickName = username;
+ String nuser = Utils.normalise(username);
FLAPSignonFrame sof = new FLAPSignonFrame();
sof.setSequence(clientSequence++);
sof.setFLAPVersion(1);
sof.setTLVTag(1);
sof.setUserName(nuser);
sout.write(sof.getFrameData());
- TocSignonCommand soc=new TocSignonCommand(host,port,username,password);
+ TocSignonCommand soc = new TocSignonCommand(host, port, username, password);
sendTocCommand(soc);
- for (int i=0;i<waitTime/100;i++) // Wait a max of waitTime * 100ms
+ for (int i = 0; i < waitTime / 100; i++) // Wait a max of waitTime * 100ms
{
- if (loginComplete||!connected) // Have we logged in successfully
+ if (loginComplete || !connected) // Have we logged in successfully
{
break; // If so then return
- }
- else {
+ } else {
try {
Thread.sleep(100); //Sleep for a tenth of a second
- }
- catch (InterruptedException e) {
+ } catch (InterruptedException e) {
}
}
}
if (loginComplete) {
- loggedIn=true;
- }
- else {
+ loggedIn = true;
+ } else {
throw new JaimTimeoutException("login failed-timeout waiting for valid response");
}
-
- }
-
- else
+
+ } else
throw new JaimStateException("Not connected.");
}
-
+
private void sendTocCommand(TocCommand cmd) throws IOException {
- FLAPDataFrame fr=new FLAPDataFrame();
+ FLAPDataFrame fr = new FLAPDataFrame();
fr.setSequence(nextSequence());
if (debug) {
- System.out.println("Sending "+cmd.toString());
+ System.out.println("Sending " + cmd.toString());
}
fr.addString(cmd.toString());
sout.write(fr.getFrameData());
}
- private int nextSequence()
- {
- int seq=clientSequence++;
- if (clientSequence>65535)
- clientSequence=0;
- return(seq);
+ private int nextSequence() {
+ int seq = clientSequence++;
+ if (clientSequence > 65535)
+ clientSequence = 0;
+ return (seq);
}
private void sendKeepAlive() throws IOException {
- FLAPKeepAliveFrame fr=new FLAPKeepAliveFrame();
- fr.setSequence(nextSequence());
- if (debug) {
- System.out.println("Sending keepalive");
- }
- sout.write(fr.getFrameData());
- }
- /** The run method for the dispatcher thread
- */
-
+ FLAPKeepAliveFrame fr = new FLAPKeepAliveFrame();
+ fr.setSequence(nextSequence());
+ if (debug) {
+ System.out.println("Sending keepalive");
+ }
+ sout.write(fr.getFrameData());
+ }
+
+ /**
+ * The run method for the dispatcher thread
+ */
+
public void run() {
while (true) {
-
- if (messageQueue.size()>0) {
- realDispatch((FLAPFrame)messageQueue.remove(0));
- }
- else {
- if (System.currentTimeMillis()-lastKeepAlive>WAIT_TIME)
- {
- if (debug)
- {
- System.out.println("No keepalive received - sending");
- }
- try
- {
- sendKeepAlive();
- lastKeepAlive=System.currentTimeMillis();
- }
- catch (IOException ioe)
- {
- connectionLost();
- }
+
+ if (messageQueue.size() > 0) {
+ realDispatch((FLAPFrame) messageQueue.remove(0));
+ } else {
+ if (System.currentTimeMillis() - lastKeepAlive > WAIT_TIME) {
+ if (debug) {
+ System.out.println("No keepalive received - sending");
+ }
+ try {
+ sendKeepAlive();
+ lastKeepAlive = System.currentTimeMillis();
+ } catch (IOException ioe) {
+ connectionLost();
+ }
}
-
+
try {
- synchronized(this) {
+ synchronized (this) {
this.wait(WAIT_TIME);
}
- }
- catch (InterruptedException e) {
+ } catch (InterruptedException e) {
}
}
}
}
-
+
protected void Dispatch(FLAPFrame fr) {
messageQueue.addElement(fr);
- synchronized(this) {
+ synchronized (this) {
this.notify();
}
}
-
+
private void realDispatch(FLAPFrame fr) {
switch (fr.getFLAPFrameType()) {
case FLAPFrame.FLAP_FRAME_ERROR:
-
+
try {
disconnect();
- }
- catch (IOException e) {
+ } catch (IOException e) {
}
break;
case FLAPFrame.FLAP_FRAME_DATA:
-
- FLAPDataFrame df=(FLAPDataFrame)fr;
+
+ FLAPDataFrame df = (FLAPDataFrame) fr;
TocResponse tr = TocResponseFactory.createResponse(df.getContent());
HandleTocResponse(tr);
break;
case FLAPFrame.FLAP_FRAME_KEEP_ALIVE:
if (debug) {
- System.out.println("Received keep alive frame "+DateFormat.getTimeInstance().format(new Date()));
+ System.out.println("Received keep alive frame " + DateFormat.getTimeInstance().format(new Date()));
+ }
+ lastKeepAlive = System.currentTimeMillis();
+ try {
+ sendKeepAlive();
+ } catch (IOException e) {
+ connectionLost();
}
- lastKeepAlive=System.currentTimeMillis();
- try
- {
- sendKeepAlive();
- }
- catch (IOException e)
- {
- connectionLost();
- }
break;
case FLAPFrame.FLAP_FRAME_SIGNOFF:
- connected=false;
- loggedIn=false;
+ connected = false;
+ loggedIn = false;
try {
s.close();
- }
- catch (IOException e) {
+ } catch (IOException e) {
}
break;
default:
if (debug) {
- System.out.println("Unknown type received: "+fr.getFLAPFrameType());
+ System.out.println("Unknown type received: " + fr.getFLAPFrameType());
}
break;
}
}
-
-
+
+
protected void HandleTocResponse(TocResponse tr) {
if (debug) {
- System.out.println("Toc Response received:"+tr.toString());
+ System.out.println("Toc Response received:" + tr.toString());
}
if (tr instanceof SignOnTocResponse) {
TocInitDoneCommand tid = new TocInitDoneCommand();
TocAddBuddyCommand tab = new TocAddBuddyCommand();
- Iterator it=watchedBuddies.keySet().iterator();
+ Iterator it = watchedBuddies.keySet().iterator();
while (it.hasNext()) {
- tab.addBuddy((String)it.next());
+ tab.addBuddy((String) it.next());
}
try {
sendTocCommand(tab);
sendTocCommand(tid);
deliverEvent(new LoginCompleteTocResponse()); // nform clients that login processing is now complete
- loginComplete=true;
+ loginComplete = true;
+ } catch (IOException e) {
}
- catch (IOException e) {
- }
- }
- else if (tr instanceof ConfigTocResponse) {
+ } else if (tr instanceof ConfigTocResponse ctr) {
if (debug) {
System.out.println("Received ConfigTocResponse");
}
-
- ConfigTocResponse ctr=(ConfigTocResponse)tr;
- Enumeration e=ctr.enumerateGroups();
+
+ Enumeration e = ctr.enumerateGroups();
while (e.hasMoreElements()) {
- Group g=(Group)e.nextElement();
- groups.put(g.getName(),g);
- Enumeration be=g.enumerateBuddies();
+ Group g = (Group) e.nextElement();
+ groups.put(g.getName(), g);
+ Enumeration be = g.enumerateBuddies();
while (be.hasMoreElements()) {
- Buddy b=(Buddy)be.nextElement();
+ Buddy b = (Buddy) be.nextElement();
if (!buddies.containsKey(b.getName())) {
- buddies.put(b.getName(),b);
+ buddies.put(b.getName(), b);
}
}
}
- configValid=true;
+ configValid = true;
}
-
+
deliverEvent(tr);
-
-
-
+
+
}
-
- /** Deliver a TocResponse event to registered listeners
- *@param tr The TocResponse to be delivered
+
+ /**
+ * Deliver a TocResponse event to registered listeners
+ *
+ * @param tr The TocResponse to be delivered
*/
-
+
private void deliverEvent(TocResponse tr) {
dt.deliverMessage(tr);
-
+
}
public void joinChat(int exchange, String roomName) {
try {
TocChatJoinCommand joinCommand = new TocChatJoinCommand(exchange, roomName);
sendTocCommand(joinCommand);
- } catch (IOException ignore) {}
+ } catch (IOException ignore) {
+ }
}
public void joinChat(String roomName) {
joinChat(4, roomName);
}
-
- /** Send an instant message
+
+ /**
+ * Send an instant message
+ *
* @param recipient The nickname of the message recipient
- * @param msg The message to send
+ * @param msg The message to send
* @throws IOException if a network error occurs
*/
- public void sendIM(String recipient,String msg) throws IOException {
- sendIM(recipient,msg,false);
+ public void sendIM(String recipient, String msg) throws IOException {
+ sendIM(recipient, msg, false);
}
-
- /** Send an instant message
+
+ /**
+ * Send an instant message
+ *
* @param recipient The nickname of the message recipient
- * @param msg The message to send
- * @param auto true if this is an automatic response (eg. away message)
+ * @param msg The message to send
+ * @param auto true if this is an automatic response (eg. away message)
* @throws IOException if a network error occurs
*/
- public void sendIM(String recipient,String msg,boolean auto) throws IOException {
-
- synchronized(this) {
-
+ public void sendIM(String recipient, String msg, boolean auto) throws IOException {
+
+ synchronized (this) {
+
if (sendPoints < MAX_POINTS) // If we have less than full points
{
- long now=System.currentTimeMillis();
- long difference=now-lastMessageSendTime;
- sendPoints+=(int)(difference/POINT_RECOVERY_TIME); // 1 point is regained every 2 seconds
- if (sendPoints >MAX_POINTS)
- sendPoints=MAX_POINTS;
-
- if (sendPoints <BLOCK_POINTS) // If we are in danger of being limited
+ long now = System.currentTimeMillis();
+ long difference = now - lastMessageSendTime;
+ sendPoints += (int) (difference / POINT_RECOVERY_TIME); // 1 point is regained every 2 seconds
+ if (sendPoints > MAX_POINTS)
+ sendPoints = MAX_POINTS;
+
+ if (sendPoints < BLOCK_POINTS) // If we are in danger of being limited
{
try {
Thread.sleep(THRESHOLD_DELAY); // Wait until we get one point back
sendPoints++;
- }
- catch (InterruptedException ie) {
+ } catch (InterruptedException ie) {
}
}
}
}
- TocIMCommand im=new TocIMCommand(recipient,msg,auto);
-
+ TocIMCommand im = new TocIMCommand(recipient, msg, auto);
+
sendTocCommand(im);
sendPoints--;
if (debug) {
- System.out.println("Points="+sendPoints);
+ System.out.println("Points=" + sendPoints);
}
-
- lastMessageSendTime=System.currentTimeMillis();
+
+ lastMessageSendTime = System.currentTimeMillis();
}
-
-
- /** Add a buddy to a group. This information can be saved on the server by calling {@link #saveConfig}
- * @param buddyName The normalised buddy name to add
- * @param groupName The name of the group to add this buddy to
- * @param pos the position in the group at which to add the buddy.
- * @return The {@link Buddy} object that represents the specified buddy name.
+
+
+ /**
+ * Add a buddy to a group. This information can be saved on the server by calling {@link #saveConfig}
+ *
+ * @param buddyName The normalised buddy name to add
+ * @param groupName The name of the group to add this buddy to
+ * @param pos the position in the group at which to add the buddy.
+ * @return The {@link Buddy} object that represents the specified buddy name.
*/
-
+
public Buddy addBuddy(String buddyName, String groupName, int pos) {
-
+
if (debug) {
- System.out.println("Adding "+buddyName+" to group "+groupName+" at position "+pos);
+ System.out.println("Adding " + buddyName + " to group " + groupName + " at position " + pos);
}
-
+
Buddy buddy;
- buddy=(Buddy)buddies.get(buddyName);
- if (buddy==null) {
- buddy=new Buddy(buddyName);
+ buddy = (Buddy) buddies.get(buddyName);
+ if (buddy == null) {
+ buddy = new Buddy(buddyName);
}
- Group group=(Group)groups.get(groupName);
- if (group==null) {
- group=new Group(groupName);
- groups.put(groupName,group);
+ Group group = (Group) groups.get(groupName);
+ if (group == null) {
+ group = new Group(groupName);
+ groups.put(groupName, group);
}
- if (pos>group.getBuddyCount()||pos==-1) {
+ if (pos > group.getBuddyCount() || pos == -1) {
group.addBuddy(buddy);
+ } else {
+ group.addBuddy(buddy, pos);
}
- else {
- group.addBuddy(buddy,pos);
- }
- return(buddy);
+ return (buddy);
}
-
- /** Add a buddy to a group. This information can be saved on the server by calling {@link #saveConfig}
- * The buddy is added to the end of the group
- * @param buddyName The normalised buddy name to add
- * @param groupName The name of the group to add this buddy to
- * @return The {@link Buddy} object that represents the specified buddy name.
+
+ /**
+ * Add a buddy to a group. This information can be saved on the server by calling {@link #saveConfig}
+ * The buddy is added to the end of the group
+ *
+ * @param buddyName The normalised buddy name to add
+ * @param groupName The name of the group to add this buddy to
+ * @return The {@link Buddy} object that represents the specified buddy name.
*/
-
+
public Buddy addBuddy(String buddyName, String groupName) {
- return(addBuddy(buddyName,groupName,-1));
+ return (addBuddy(buddyName, groupName, -1));
}
-
- /** Add a buddy to the watch list for this connection.
+
+ /**
+ * Add a buddy to the watch list for this connection.
* This method must be called after {@link #connect()}
* It also appears that the login process will not complete unless at least one buddy is added to the watch list
+ *
* @param buddy The nickname to add to the watch list
* @throws JaimException if the method is called at the wrong time
* @see JaimEventListener
@@ -612,12 +627,14 @@ public class JaimConnection implements java.lang.Runnable {
*/
public void addBuddy(String buddy) throws JaimException {
watchBuddy(buddy);
-
+
}
-
- /** Add a buddy to the watch list for this connection.
+
+ /**
+ * Add a buddy to the watch list for this connection.
* This method must be called after {@link #connect()}
* It also appears that the login process will not complete unless at least one buddy is added to the watch list
+ *
* @param buddy The nickname to add to the watch list
* @throws JaimException if the method is called at the wrong time
* @see JaimEventListener
@@ -628,118 +645,135 @@ public class JaimConnection implements java.lang.Runnable {
TocAddBuddyCommand tab = new TocAddBuddyCommand();
tab.addBuddy(buddy);
sendTocCommand(tab);
- }
- catch (IOException e) {
+ } catch (IOException e) {
throw new JaimException(e.toString());
}
}
-
- watchedBuddies.put(buddy,buddy);
-
+
+ watchedBuddies.put(buddy, buddy);
+
}
-
- /** Save group/buddy list configuration to the TOC server
+
+ /**
+ * Save group/buddy list configuration to the TOC server
+ *
* @throws IOException if a network error occurs
*/
-
+
public void saveConfig() throws IOException {
- TocSetConfigCommand tsc=new TocSetConfigCommand();
- Iterator it =groups.keySet().iterator();
+ TocSetConfigCommand tsc = new TocSetConfigCommand();
+ Iterator it = groups.keySet().iterator();
while (it.hasNext()) {
- Group g = (Group)groups.get(it.next());
+ Group g = (Group) groups.get(it.next());
tsc.addGroup(g);
}
sendTocCommand(tsc);
-
+
}
-
- /** Return the set of groups that have been stored in the TOC server
- * The information returned from this method is only valid if {@link #isConfigValid} returns true
- * @return A Collection of {@link Group} Objects
+
+ /**
+ * Return the set of groups that have been stored in the TOC server
+ * The information returned from this method is only valid if {@link #isConfigValid} returns true
+ *
+ * @return A Collection of {@link Group} Objects
*/
-
+
public Collection getGroups() {
- return(groups.values());
+ return (groups.values());
}
- /**
- * Return a group, given its name
- * @return A {@link Group} Object corresponding to the string name
+ /**
+ * Return a group, given its name
+ *
+ * @return A {@link Group} Object corresponding to the string name
*/
-
+
public Group getGroupBy(String name) {
Group result = (Group) groups.get(name);
return result;
}
-
- /** Indicate whether configuration information has been received from the TOC server.
- * If this method returns true then the information returned by {@link #getGroups} is valid
- * @return true if configuration information has been received from the TOC server.
+
+ /**
+ * Indicate whether configuration information has been received from the TOC server.
+ * If this method returns true then the information returned by {@link #getGroups} is valid
+ *
+ * @return true if configuration information has been received from the TOC server.
*/
-
+
public boolean isConfigValid() {
- return(configValid);
+ return (configValid);
}
-
- /** Send a warning or "Evil" to another user. You must be involved in a communication with a user before you can warn them
- * @param buddy The nickname of the buddy to warn
+
+ /**
+ * Send a warning or "Evil" to another user. You must be involved in a communication with a user before you can warn them
+ *
+ * @param buddy The nickname of the buddy to warn
* @param anonymous true if the warning should be sent anonymously
* @throws IOException if a network error occurs
*/
- public void sendEvil(String buddy,boolean anonymous) throws IOException {
- TocEvilCommand ec=new TocEvilCommand(buddy,anonymous);
+ public void sendEvil(String buddy, boolean anonymous) throws IOException {
+ TocEvilCommand ec = new TocEvilCommand(buddy, anonymous);
sendTocCommand(ec);
}
-
-
- /** Set the information for the logged in user
+
+
+ /**
+ * Set the information for the logged in user
+ *
* @param information The information for this user (May contain HTML)
* @throws IOException if a network error occurs
*/
public void setInfo(String information) throws IOException {
- TocSetInfoCommand sic=new TocSetInfoCommand(information);
+ TocSetInfoCommand sic = new TocSetInfoCommand(information);
sendTocCommand(sic);
}
-
- /** Get the information for the specified user
+
+ /**
+ * Get the information for the specified user
+ *
* @param username The screenname for whom info is requested (May contain HTML)
* @throws IOException if a network error occurs
*/
public void getInfo(String username) throws IOException {
- TocGetInfoCommand gic=new TocGetInfoCommand(username);
+ TocGetInfoCommand gic = new TocGetInfoCommand(username);
sendTocCommand(gic);
}
-
- /** Get an Input stream associated with a URL returned by the "GOTO_URL" toc response
- *@param file The "file" returned by calling GotoTocResponse#getURL
- *@return An InputStream connected to the specified URL
- *@throws IOException if an IO error occurs
- *@throws MalformedURLException if there is an error building the URL
+
+ /**
+ * Get an Input stream associated with a URL returned by the "GOTO_URL" toc response
+ *
+ * @param file The "file" returned by calling GotoTocResponse#getURL
+ * @return An InputStream connected to the specified URL
+ * @throws IOException if an IO error occurs
+ * @throws MalformedURLException if there is an error building the URL
*/
-
-
+
+
public InputStream getURL(String file) throws IOException, MalformedURLException {
URL URL;
-
- URL=new URL("http",host,port,file);
-
- return(URL.openStream());
- }
-
-
-
- /** Set the information for the logged in user
+
+ URL = new URL("http", host, port, file);
+
+ return (URL.openStream());
+ }
+
+
+ /**
+ * Set the information for the logged in user
+ *
* @param awayMsg The away message for this user. May contain HTML. To cancel "away" status set the awayMsg to ""
* @throws IOException if a network error occurs
*/
public void setAway(String awayMsg) throws IOException {
- TocSetAwayCommand sic=new TocSetAwayCommand(awayMsg);
+ TocSetAwayCommand sic = new TocSetAwayCommand(awayMsg);
sendTocCommand(sic);
}
-
-
- /** Adds the specified buddy to your permit list.
+
+
+ /**
+ * Adds the specified buddy to your permit list.
+ *
* @param buddy The buddy to add to your block list. If this is an empty string, mode is changed to "permit none"
* @throws JaimException if a network error occurs
*/
@@ -749,14 +783,15 @@ public class JaimConnection implements java.lang.Runnable {
TocAddPermitCommand tap = new TocAddPermitCommand();
tap.addPermit(buddy);
sendTocCommand(tap);
- }
- catch (IOException e) {
+ } catch (IOException e) {
throw new JaimException(e.toString());
}
}
}
-
- /** Adds the specified buddy to your block list.
+
+ /**
+ * Adds the specified buddy to your block list.
+ *
* @param buddy The buddy to add to your block list. If this is an empty string, mode is changed to "deny none"
* @throws JaimException if a network error occurs
*/
@@ -766,83 +801,87 @@ public class JaimConnection implements java.lang.Runnable {
TocAddDenyCommand tad = new TocAddDenyCommand();
tad.addDeny(buddy);
sendTocCommand(tad);
- }
- catch (IOException e) {
+ } catch (IOException e) {
throw new JaimException(e.toString());
}
}
}
-
- /** Called by receiver thread to indicate that the connection has been terminated by an IOException
+
+ /**
+ * Called by receiver thread to indicate that the connection has been terminated by an IOException
*/
-
+
private void connectionLost() {
deliverEvent(new ConnectionLostTocResponse());
logOut();
- connected=false;
+ connected = false;
}
-
-
-
- /** Set the idle time for this user
+
+
+ /**
+ * Set the idle time for this user
+ *
* @param idleSecs The number of seconds the user has been idle for. Set to 0 to indicate current activity. The server will increment the idle time if non-zero
* @throws IOException if a network error occurs
*/
public void setIdle(int idleSecs) throws IOException {
- TocSetIdleCommand sic=new TocSetIdleCommand(idleSecs);
+ TocSetIdleCommand sic = new TocSetIdleCommand(idleSecs);
sendTocCommand(sic);
}
-
-
- /** Delete a buddy from the buddy watch list. The buddy should have been added with {@link #addBuddy } first.
+
+
+ /**
+ * Delete a buddy from the buddy watch list. The buddy should have been added with {@link #addBuddy } first.
* The buddy list can only be modified after {@link #connect } is called.
+ *
* @param buddy The buddy name to be deleted\
* @deprecated use {@link #unwatchBuddy } instead
*/
public void deleteBuddy(String buddy) {
unwatchBuddy(buddy);
}
-
- /** Delete a buddy from the buddy watch list. The buddy should have been added with {@link #addBuddy } first.
+
+ /**
+ * Delete a buddy from the buddy watch list. The buddy should have been added with {@link #addBuddy } first.
* The buddy list can only be modified after {@link #connect } is called.
+ *
* @param buddy The buddy name to be deleted
*/
public void unwatchBuddy(String buddy) {
watchedBuddies.remove(buddy);
}
-
+
private class ReceiverThread extends Thread {
private InputStream sin;
private boolean exit;
- private JaimConnection parent;
-
+ private final JaimConnection parent;
+
private ReceiverThread(JaimConnection parent) {
- this.parent=parent;
- exit=false;
+ this.parent = parent;
+ exit = false;
}
-
+
private void setInputStream(InputStream in) {
- sin=in;
+ sin = in;
}
-
+
public void run() {
if (debug) {
System.out.println("Receiver starting");
}
- FLAPInputFrame inframe=new FLAPInputFrame();
+ FLAPInputFrame inframe = new FLAPInputFrame();
try {
while (!exit) {
try {
int i;
- while ( !inframe.completeFrameRead()) {
- i=sin.read();
- inframe.addFrameData((byte)i);
+ while (!inframe.completeFrameRead()) {
+ i = sin.read();
+ inframe.addFrameData((byte) i);
}
try {
- FLAPFrame fr=FLAPFrameFactory.createFLAPFrame(inframe.getFrameData());
+ FLAPFrame fr = FLAPFrameFactory.createFLAPFrame(inframe.getFrameData());
parent.Dispatch(fr);
- }
- catch (FLAPFrameException ffe) {
+ } catch (FLAPFrameException ffe) {
if (debug) {
ffe.printStackTrace();
}
@@ -850,77 +889,73 @@ public class JaimConnection implements java.lang.Runnable {
if (inframe.completeFrameRead()) {
inframe.resetInputFrame();
}
- }
- catch (InterruptedIOException iie) {
+ } catch (InterruptedIOException iie) {
// We expect these because we are performing reads with a timeout
}
}
- }
- catch (IOException e) {
+ } catch (IOException e) {
connectionLost(); // Indicate that we have lost our connection
if (debug) {
e.printStackTrace();
}
}
}
-
+
private void pleaseExit() {
- exit=true;
+ exit = true;
}
-
+
}
+
private class DeliveryThread extends Thread {
- private Vector messages;
+ private final Vector messages;
private boolean exit;
+
private DeliveryThread() {
- messages=new Vector();
- exit=false;
+ messages = new Vector();
+ exit = false;
}
-
+
private void deliverMessage(TocResponse tr) {
- synchronized(this) {
+ synchronized (this) {
messages.add(tr);
this.notify();
}
}
-
+
public void run() {
if (debug) {
System.out.println("Delivery Thread starting");
}
while (!exit) {
- if (messages.size()>0) {
- TocResponse tr=(TocResponse)messages.remove(0);
+ if (messages.size() > 0) {
+ TocResponse tr = (TocResponse) messages.remove(0);
doDelivery(tr);
- }
- else {
- synchronized(this) {
- try
- {
+ } else {
+ synchronized (this) {
+ try {
this.wait();
- }
- catch (InterruptedException e)
- {
+ } catch (InterruptedException e) {
}
}
}
-
+
}
}
-
+
private void doDelivery(TocResponse tr) {
- for (int i=0;i<eventListeners.size();i++) {
- JaimEventListener el=(JaimEventListener)eventListeners.elementAt(i);
- el.receiveEvent(new JaimEvent(this,tr));
+ for (int i = 0; i < eventListeners.size(); i++) {
+ JaimEventListener el = (JaimEventListener) eventListeners.elementAt(i);
+ el.receiveEvent(new JaimEvent(this, tr));
}
}
-
+
private void pleaseExit() {
- exit=true;
+ exit = true;
}
-
-
+
+
}
-
-
+
+
}
diff --git a/src/com/wilko/jaim/JaimEvent.java b/src/com/wilko/jaim/JaimEvent.java
index 50c66ae..739c4ec 100644
--- a/src/com/wilko/jaim/JaimEvent.java
+++ b/src/com/wilko/jaim/JaimEvent.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -19,24 +19,27 @@
package com.wilko.jaim;
-/** The JaimEvent object is delivered to all registered {@link JaimEventListener}
- * @see JaimConnection#addEventListener
- * @author paulw
+/**
+ * The JaimEvent object is delivered to all registered {@link JaimEventListener}
+ *
+ * @author paulw
* @version $revision: $
+ * @see JaimConnection#addEventListener
*/
public class JaimEvent extends java.util.EventObject {
- private TocResponse tocResponse;
-
- /** Creates new JaimEvent */
+ private final TocResponse tocResponse;
+
+ /**
+ * Creates new JaimEvent
+ */
public JaimEvent(Object source, TocResponse tocResponse) {
super(source);
- this.tocResponse=tocResponse;
+ this.tocResponse = tocResponse;
}
-
- public TocResponse getTocResponse()
- {
- return(tocResponse);
+
+ public TocResponse getTocResponse() {
+ return (tocResponse);
}
}
diff --git a/src/com/wilko/jaim/JaimEventListener.java b/src/com/wilko/jaim/JaimEventListener.java
index e0861bc..54c01d2 100644
--- a/src/com/wilko/jaim/JaimEventListener.java
+++ b/src/com/wilko/jaim/JaimEventListener.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -25,16 +25,20 @@
package com.wilko.jaim;
-/** A JaimEventListener receives JaimEvents from the JaimConnection class.
+/**
+ * A JaimEventListener receives JaimEvents from the JaimConnection class.
* A {@link JaimEvent} contains a {@link TocResponse} object.
- * @author paulw
+ *
+ * @author paulw
* @version $Revision: 1.3 $
*/
public interface JaimEventListener {
- /** Receive an incoming {@link JaimEvent}
- *@param ev - The incoming event
+ /**
+ * Receive an incoming {@link JaimEvent}
+ *
+ * @param ev - The incoming event
*/
- public void receiveEvent(JaimEvent ev);
+ void receiveEvent(JaimEvent ev);
}
diff --git a/src/com/wilko/jaim/JaimException.java b/src/com/wilko/jaim/JaimException.java
index 3b36954..23c3d1c 100644
--- a/src/com/wilko/jaim/JaimException.java
+++ b/src/com/wilko/jaim/JaimException.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,8 +26,7 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.3 $
*/
public class JaimException extends java.lang.Exception {
@@ -41,6 +40,7 @@ public class JaimException extends java.lang.Exception {
/**
* Constructs an <code>JaimException</code> with the specified detail message.
+ *
* @param msg the detail message.
*/
public JaimException(String msg) {
diff --git a/src/com/wilko/jaim/JaimStateException.java b/src/com/wilko/jaim/JaimStateException.java
index 621350b..ad848c8 100644
--- a/src/com/wilko/jaim/JaimStateException.java
+++ b/src/com/wilko/jaim/JaimStateException.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -19,8 +19,7 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $version: $
*/
public class JaimStateException extends JaimException {
@@ -34,6 +33,7 @@ public class JaimStateException extends JaimException {
/**
* Constructs an <code>JaimStateException</code> with the specified detail message.
+ *
* @param msg the detail message.
*/
public JaimStateException(String msg) {
diff --git a/src/com/wilko/jaim/JaimTimeoutException.java b/src/com/wilko/jaim/JaimTimeoutException.java
index 4dfb271..b26d4b9 100644
--- a/src/com/wilko/jaim/JaimTimeoutException.java
+++ b/src/com/wilko/jaim/JaimTimeoutException.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -20,8 +20,7 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $version: $
*/
public class JaimTimeoutException extends JaimException {
@@ -35,6 +34,7 @@ public class JaimTimeoutException extends JaimException {
/**
* Constructs an <code>JaimTimeoutException</code> with the specified detail message.
+ *
* @param msg the detail message.
*/
public JaimTimeoutException(String msg) {
diff --git a/src/com/wilko/jaim/LoginCompleteTocResponse.java b/src/com/wilko/jaim/LoginCompleteTocResponse.java
index c00fc07..23ca39b 100644
--- a/src/com/wilko/jaim/LoginCompleteTocResponse.java
+++ b/src/com/wilko/jaim/LoginCompleteTocResponse.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -27,24 +27,26 @@ package com.wilko.jaim;
/**
* This is a "pseudo" TOC response - it is delivered to JaimLib clients to indicate that login processing has been completed successfully.
- * @author wilko
+ *
+ * @author wilko
* @version: $revision: $
*/
public class LoginCompleteTocResponse extends TocResponse {
-
- public static final String RESPONSE_TYPE="LOGINCOMPLETE";
-
- /** Creates a new instance of LoginCompleteTocResponse */
+
+ public static final String RESPONSE_TYPE = "LOGINCOMPLETE";
+
+ /**
+ * Creates a new instance of LoginCompleteTocResponse
+ */
public LoginCompleteTocResponse() {
}
-
+
public String getResponseType() {
return (RESPONSE_TYPE);
}
-
- public String toString()
- {
+
+ public String toString() {
return (RESPONSE_TYPE);
}
-
+
}
diff --git a/src/com/wilko/jaim/NickTocResponse.java b/src/com/wilko/jaim/NickTocResponse.java
index e288bfd..acca3d7 100644
--- a/src/com/wilko/jaim/NickTocResponse.java
+++ b/src/com/wilko/jaim/NickTocResponse.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,57 +26,58 @@
package com.wilko.jaim;
/**
-* The NicTocResponse is used internally to manage the TOC signon process. It is not delivered to clients of {@link JaimConnection}
- * @author paulw
+ * The NicTocResponse is used internally to manage the TOC signon process. It is not delivered to clients of {@link JaimConnection}
+ *
+ * @author paulw
* @version $Revision: 1.6 $
*/
public class NickTocResponse extends TocResponse implements TocResponseHandler {
+ public static final String RESPONSE_TYPE = "NICK";
private String nickName;
-
- public static final String RESPONSE_TYPE="NICK";
-
-
- /** Creates new NickTocResponse */
+
+
+ /**
+ * Creates new NickTocResponse
+ */
public NickTocResponse() {
- nickName="";
+ nickName = "";
}
-
+
public TocResponse parseString(java.lang.String str) {
- NickTocResponse tr=new NickTocResponse();
+ NickTocResponse tr = new NickTocResponse();
tr.doParse(str);
- return(tr);
+ return (tr);
}
-
- private void doParse(String str)
- {
- int colonPos=str.indexOf(':');
-
- if (colonPos != -1)
- {
- nickName=str.substring(colonPos+1);
- }
-
-
+
+ private void doParse(String str) {
+ int colonPos = str.indexOf(':');
+
+ if (colonPos != -1) {
+ nickName = str.substring(colonPos + 1);
+ }
+
+
}
-
- public String getNickName()
- {
- return(nickName);
+
+ public String getNickName() {
+ return (nickName);
}
-
-
+
+
public String getResponseType() {
return RESPONSE_TYPE;
}
-
- /** Returns true if this response handler can handle the specified response.
+
+ /**
+ * Returns true if this response handler can handle the specified response.
+ *
* @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled
*/
public boolean canHandle(String Response) {
- return(Response.equalsIgnoreCase(RESPONSE_TYPE));
+ return (Response.equalsIgnoreCase(RESPONSE_TYPE));
}
-
+
}
diff --git a/src/com/wilko/jaim/SignOnTocResponse.java b/src/com/wilko/jaim/SignOnTocResponse.java
index f4fd5d6..adc9f04 100644
--- a/src/com/wilko/jaim/SignOnTocResponse.java
+++ b/src/com/wilko/jaim/SignOnTocResponse.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -27,54 +27,54 @@ package com.wilko.jaim;
/**
* The SignOnTocResponse is used internally to manage the TOC signon process. It is not delivered to clients of {@link JaimConnection}
- * @author paulw
+ *
+ * @author paulw
* @version $Revision: 1.5 $
*/
public class SignOnTocResponse extends TocResponse implements TocResponseHandler {
+ public static final String RESPONSE_TYPE = "SIGN_ON";
String version;
-
- public static final String RESPONSE_TYPE="SIGN_ON";
-
-
- /** Creates new SignOnTocResponse */
+
+
+ /**
+ * Creates new SignOnTocResponse
+ */
public SignOnTocResponse() {
- version="";
+ version = "";
}
-
+
public String getResponseType() {
- return(RESPONSE_TYPE);
+ return (RESPONSE_TYPE);
}
-
- protected String getVersion()
- {
- return(version);
+
+ protected String getVersion() {
+ return (version);
}
-
-
- public TocResponse parseString(String str)
- {
- SignOnTocResponse tr=new SignOnTocResponse();
+
+
+ public TocResponse parseString(String str) {
+ SignOnTocResponse tr = new SignOnTocResponse();
tr.doParse(str);
- return(tr);
+ return (tr);
}
-
- private void doParse(String str)
- {
- cmd=str;
- int colonpos=str.indexOf(':');
- if (colonpos != -1)
- {
- version=str.substring(colonpos+1);
+
+ private void doParse(String str) {
+ cmd = str;
+ int colonpos = str.indexOf(':');
+ if (colonpos != -1) {
+ version = str.substring(colonpos + 1);
}
}
-
- /** Returns true if this response handler can handle the specified response.
+
+ /**
+ * Returns true if this response handler can handle the specified response.
+ *
* @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled
*/
public boolean canHandle(String Response) {
- return(Response.equalsIgnoreCase(RESPONSE_TYPE));
+ return (Response.equalsIgnoreCase(RESPONSE_TYPE));
}
-
+
}
diff --git a/src/com/wilko/jaim/TocAddBuddyCommand.java b/src/com/wilko/jaim/TocAddBuddyCommand.java
index d4a6566..fb1a3d5 100644
--- a/src/com/wilko/jaim/TocAddBuddyCommand.java
+++ b/src/com/wilko/jaim/TocAddBuddyCommand.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -28,40 +28,38 @@ package com.wilko.jaim;
import java.util.Vector;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.3 $
*/
public class TocAddBuddyCommand extends TocCommand {
- private static String CMD="toc_add_buddy";
-
+ private static final String CMD = "toc_add_buddy";
+
Vector buddyList;
-
- /** Creates new TocAddBuddyCommand */
+
+ /**
+ * Creates new TocAddBuddyCommand
+ */
public TocAddBuddyCommand() {
- buddyList=new Vector();
+ buddyList = new Vector();
}
- public void addBuddy(String buddy)
- {
+ public void addBuddy(String buddy) {
buddyList.add(Utils.normalise(buddy));
}
-
- public String toString()
- {
- StringBuffer output=new StringBuffer(CMD);
- for (int i=0;i<buddyList.size();i++)
- {
+
+ public String toString() {
+ StringBuffer output = new StringBuffer(CMD);
+ for (int i = 0; i < buddyList.size(); i++) {
output.append(' ');
- output.append((String)buddyList.elementAt(i));
+ output.append((String) buddyList.elementAt(i));
}
- return(output.toString());
+ return (output.toString());
}
-
-
+
+
public byte[] getBytes() {
- return(toString().getBytes());
+ return (toString().getBytes());
}
-
+
}
diff --git a/src/com/wilko/jaim/TocAddDenyCommand.java b/src/com/wilko/jaim/TocAddDenyCommand.java
index 46bc523..1bb4957 100644
--- a/src/com/wilko/jaim/TocAddDenyCommand.java
+++ b/src/com/wilko/jaim/TocAddDenyCommand.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -28,40 +28,38 @@ package com.wilko.jaim;
import java.util.Vector;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.3 $
*/
public class TocAddDenyCommand extends TocCommand {
- private static String CMD="toc_add_deny";
-
+ private static final String CMD = "toc_add_deny";
+
Vector buddyList;
-
- /** Creates new TocAddBuddyCommand */
+
+ /**
+ * Creates new TocAddBuddyCommand
+ */
public TocAddDenyCommand() {
- buddyList=new Vector();
+ buddyList = new Vector();
}
- public void addDeny(String buddy)
- {
+ public void addDeny(String buddy) {
buddyList.add(Utils.normalise(buddy));
}
-
- public String toString()
- {
- StringBuffer output=new StringBuffer(CMD);
- for (int i=0;i<buddyList.size();i++)
- {
+
+ public String toString() {
+ StringBuffer output = new StringBuffer(CMD);
+ for (int i = 0; i < buddyList.size(); i++) {
output.append(' ');
- output.append((String)buddyList.elementAt(i));
+ output.append((String) buddyList.elementAt(i));
}
- return(output.toString());
+ return (output.toString());
}
-
-
+
+
public byte[] getBytes() {
- return(toString().getBytes());
+ return (toString().getBytes());
}
-
+
}
diff --git a/src/com/wilko/jaim/TocAddPermitCommand.java b/src/com/wilko/jaim/TocAddPermitCommand.java
index 82ec8c7..05c1830 100644
--- a/src/com/wilko/jaim/TocAddPermitCommand.java
+++ b/src/com/wilko/jaim/TocAddPermitCommand.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -28,40 +28,38 @@ package com.wilko.jaim;
import java.util.Vector;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.1 $
*/
public class TocAddPermitCommand extends TocCommand {
- private static String CMD="toc_add_permit";
-
+ private static final String CMD = "toc_add_permit";
+
Vector buddyList;
-
- /** Creates new TocAddBuddyCommand */
+
+ /**
+ * Creates new TocAddBuddyCommand
+ */
public TocAddPermitCommand() {
- buddyList=new Vector();
+ buddyList = new Vector();
}
- public void addPermit(String buddy)
- {
+ public void addPermit(String buddy) {
buddyList.add(Utils.normalise(buddy));
}
-
- public String toString()
- {
- StringBuffer output=new StringBuffer(CMD);
- for (int i=0;i<buddyList.size();i++)
- {
+
+ public String toString() {
+ StringBuffer output = new StringBuffer(CMD);
+ for (int i = 0; i < buddyList.size(); i++) {
output.append(' ');
- output.append((String)buddyList.elementAt(i));
+ output.append((String) buddyList.elementAt(i));
}
- return(output.toString());
+ return (output.toString());
}
-
-
+
+
public byte[] getBytes() {
- return(toString().getBytes());
+ return (toString().getBytes());
}
-
+
}
diff --git a/src/com/wilko/jaim/TocChatJoinCommand.java b/src/com/wilko/jaim/TocChatJoinCommand.java
index 314fea9..d0fb1dc 100644
--- a/src/com/wilko/jaim/TocChatJoinCommand.java
+++ b/src/com/wilko/jaim/TocChatJoinCommand.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,28 +26,28 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.4 $
*/
public class TocChatJoinCommand extends TocCommand {
- private int exchange;
- private String roomName;
+ private final int exchange;
+ private final String roomName;
- /** Creates new TocIMCommand */
+ /**
+ * Creates new TocIMCommand
+ */
public TocChatJoinCommand(int exchange, String roomName) {
- this.exchange=exchange;
- this.roomName=roomName;
+ this.exchange = exchange;
+ this.roomName = roomName;
}
- public String toString()
- {
- return ("toc_chat_join "+exchange+" "+roomName);
+ public String toString() {
+ return ("toc_chat_join " + exchange + " " + roomName);
}
-
+
public byte[] getBytes() {
- return(this.toString().getBytes());
+ return (this.toString().getBytes());
}
-
+
}
diff --git a/src/com/wilko/jaim/TocCommand.java b/src/com/wilko/jaim/TocCommand.java
index 14998cf..7de992c 100644
--- a/src/com/wilko/jaim/TocCommand.java
+++ b/src/com/wilko/jaim/TocCommand.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,18 +26,19 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.3 $
*/
public abstract class TocCommand {
- /** Creates new TocCommand */
+ /**
+ * Creates new TocCommand
+ */
public TocCommand() {
}
-
+
abstract public byte[] getBytes();
-
+
abstract public String toString();
-
+
}
diff --git a/src/com/wilko/jaim/TocEvilCommand.java b/src/com/wilko/jaim/TocEvilCommand.java
index b76f409..7ef1caa 100644
--- a/src/com/wilko/jaim/TocEvilCommand.java
+++ b/src/com/wilko/jaim/TocEvilCommand.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,36 +26,34 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.3 $
*/
public class TocEvilCommand extends TocCommand {
- private String buddy;
- private boolean anonymous;
-
- /** Creates new TocEvilCommand */
+ private final String buddy;
+ private final boolean anonymous;
+
+ /**
+ * Creates new TocEvilCommand
+ */
public TocEvilCommand(String buddy, boolean anonymous) {
- this.buddy=Utils.normalise(buddy);
- this.anonymous=anonymous;
+ this.buddy = Utils.normalise(buddy);
+ this.anonymous = anonymous;
}
-
- public String toString()
- {
- String ret="toc_evil "+buddy;
- if (anonymous)
- {
- ret=ret+" anon";
- }
- else
- ret=ret+" norm";
-
- return(ret);
+
+ public String toString() {
+ String ret = "toc_evil " + buddy;
+ if (anonymous) {
+ ret = ret + " anon";
+ } else
+ ret = ret + " norm";
+
+ return (ret);
}
-
+
public byte[] getBytes() {
return toString().getBytes();
}
-
+
}
diff --git a/src/com/wilko/jaim/TocGetInfoCommand.java b/src/com/wilko/jaim/TocGetInfoCommand.java
index f333f67..0ed49ce 100644
--- a/src/com/wilko/jaim/TocGetInfoCommand.java
+++ b/src/com/wilko/jaim/TocGetInfoCommand.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -17,7 +17,7 @@
*
*/
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -39,32 +39,31 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $version: $
*/
public class TocGetInfoCommand extends TocCommand {
- private String username;
-
- private static String CMD="toc_get_info ";
- /** Creates new TocGetInfoCommand
- *@param username The screen name for whom information is requested
+ private static final String CMD = "toc_get_info ";
+ private final String username;
+
+ /**
+ * Creates new TocGetInfoCommand
*
+ * @param username The screen name for whom information is requested
*/
-
+
public TocGetInfoCommand(String username) {
- this.username=Utils.normalise(username);
+ this.username = Utils.normalise(username);
}
-
-
- public String toString()
- {
- return(CMD+username);
+
+
+ public String toString() {
+ return (CMD + username);
}
public byte[] getBytes() {
- return(toString().getBytes());
+ return (toString().getBytes());
}
-
+
}
diff --git a/src/com/wilko/jaim/TocIMCommand.java b/src/com/wilko/jaim/TocIMCommand.java
index eec6dc0..7a43319 100644
--- a/src/com/wilko/jaim/TocIMCommand.java
+++ b/src/com/wilko/jaim/TocIMCommand.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,33 +26,33 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.4 $
*/
public class TocIMCommand extends TocCommand {
- private String recipient;
- private String msg;
- private String auto;
-
- /** Creates new TocIMCommand */
- public TocIMCommand(String recipient, String msg,boolean autoMessage) {
- this.recipient=Utils.normalise(recipient);
- this.msg=Utils.encodeText(msg);
+ private final String recipient;
+ private final String msg;
+ private final String auto;
+
+ /**
+ * Creates new TocIMCommand
+ */
+ public TocIMCommand(String recipient, String msg, boolean autoMessage) {
+ this.recipient = Utils.normalise(recipient);
+ this.msg = Utils.encodeText(msg);
if (autoMessage)
- auto=" auto";
+ auto = " auto";
else
- auto="";
+ auto = "";
}
- public String toString()
- {
- return ("toc_send_im "+recipient+" "+msg+auto);
+ public String toString() {
+ return ("toc_send_im " + recipient + " " + msg + auto);
}
-
+
public byte[] getBytes() {
- return(this.toString().getBytes());
+ return (this.toString().getBytes());
}
-
+
}
diff --git a/src/com/wilko/jaim/TocInitDoneCommand.java b/src/com/wilko/jaim/TocInitDoneCommand.java
index a847569..5cb8c55 100644
--- a/src/com/wilko/jaim/TocInitDoneCommand.java
+++ b/src/com/wilko/jaim/TocInitDoneCommand.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,25 +26,25 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.4 $
*/
public class TocInitDoneCommand extends TocCommand {
- private static final String CMD="toc_init_done";
-
- /** Creates new TocInitDoneCommand */
+ private static final String CMD = "toc_init_done";
+
+ /**
+ * Creates new TocInitDoneCommand
+ */
public TocInitDoneCommand() {
}
-
+
public byte[] getBytes() {
- return(CMD.getBytes());
+ return (CMD.getBytes());
}
-
- public String toString()
- {
- return(CMD);
+
+ public String toString() {
+ return (CMD);
}
-
+
}
diff --git a/src/com/wilko/jaim/TocResponse.java b/src/com/wilko/jaim/TocResponse.java
index adbdb02..0635a6a 100644
--- a/src/com/wilko/jaim/TocResponse.java
+++ b/src/com/wilko/jaim/TocResponse.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,24 +26,21 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.5 $
*/
public abstract class TocResponse {
-
+
protected String cmd;
-
- public TocResponse()
- {
- cmd="";
+
+ public TocResponse() {
+ cmd = "";
}
-
- public String toString()
- {
- return(cmd);
+
+ public String toString() {
+ return (cmd);
}
-
+
public abstract String getResponseType();
-
+
}
diff --git a/src/com/wilko/jaim/TocResponseFactory.java b/src/com/wilko/jaim/TocResponseFactory.java
index d7728b9..45b9444 100644
--- a/src/com/wilko/jaim/TocResponseFactory.java
+++ b/src/com/wilko/jaim/TocResponseFactory.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,8 +26,7 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.5 $
*/
@@ -36,47 +35,41 @@ import java.util.Vector;
public abstract class TocResponseFactory {
static Vector responseHandlers = new Vector();
-
- /** Creates new TocResponseFactory */
+
+ /**
+ * Creates new TocResponseFactory
+ */
public TocResponseFactory() {
}
- public static void addResponseHandler(TocResponseHandler h)
- {
- synchronized (responseHandlers)
- {
+ public static void addResponseHandler(TocResponseHandler h) {
+ synchronized (responseHandlers) {
responseHandlers.add(h);
}
}
-
- static TocResponse createResponse(byte[] b)
- {
- TocResponse tr=null;
- String strversion=new String(b);
- int colonpos=strversion.indexOf(':');
- if (colonpos != -1)
- {
- String firstWord=strversion.substring(0,colonpos);
- int i=0;
- synchronized (responseHandlers)
- {
- while ((i<responseHandlers.size())&&(tr==null))
- {
- TocResponseHandler h=(TocResponseHandler)responseHandlers.elementAt(i);
- if (h.canHandle(firstWord))
- {
- tr=h.parseString(strversion);
+
+ static TocResponse createResponse(byte[] b) {
+ TocResponse tr = null;
+ String strversion = new String(b);
+ int colonpos = strversion.indexOf(':');
+ if (colonpos != -1) {
+ String firstWord = strversion.substring(0, colonpos);
+ int i = 0;
+ synchronized (responseHandlers) {
+ while ((i < responseHandlers.size()) && (tr == null)) {
+ TocResponseHandler h = (TocResponseHandler) responseHandlers.elementAt(i);
+ if (h.canHandle(firstWord)) {
+ tr = h.parseString(strversion);
}
i++;
}
}
}
- if (tr==null)
- {
- GenericTocResponse gtr=new GenericTocResponse();
- tr=gtr.parseString(strversion);
+ if (tr == null) {
+ GenericTocResponse gtr = new GenericTocResponse();
+ tr = gtr.parseString(strversion);
}
- return(tr);
+ return (tr);
}
-
+
}
diff --git a/src/com/wilko/jaim/TocResponseHandler.java b/src/com/wilko/jaim/TocResponseHandler.java
index c6cf920..aa7be37 100644
--- a/src/com/wilko/jaim/TocResponseHandler.java
+++ b/src/com/wilko/jaim/TocResponseHandler.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -20,25 +20,28 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $revision: $
*/
public interface TocResponseHandler {
- /** Returns true if this response handler can handle the specified response.
- *@param Response - the response string from TOC. This is the part of the response before the first ':'
- *@return true if the response can be handled
+ /**
+ * Returns true if this response handler can handle the specified response.
+ *
+ * @param Response - the response string from TOC. This is the part of the response before the first ':'
+ * @return true if the response can be handled
*/
-
- public boolean canHandle(String Response);
-
- /** Parse the provided response
- *@param Response - the response from the TOC server. This is the full TOC response string
- *@return - A TocResponse object that represents this response
+
+ boolean canHandle(String Response);
+
+ /**
+ * Parse the provided response
+ *
+ * @param Response - the response from the TOC server. This is the full TOC response string
+ * @return - A TocResponse object that represents this response
*/
-
- public TocResponse parseString(String Response);
-
+
+ TocResponse parseString(String Response);
+
}
diff --git a/src/com/wilko/jaim/TocSetAwayCommand.java b/src/com/wilko/jaim/TocSetAwayCommand.java
index a8f4448..382310f 100644
--- a/src/com/wilko/jaim/TocSetAwayCommand.java
+++ b/src/com/wilko/jaim/TocSetAwayCommand.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,31 +26,31 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $version: $
*/
public class TocSetAwayCommand extends TocCommand {
- private String awayMsg;
-
- private static String CMD="toc_set_away ";
- /** Creates new TocSetInfoCommand
+ private static final String CMD = "toc_set_away ";
+ private final String awayMsg;
+
+ /**
+ * Creates new TocSetInfoCommand
+ *
* @param awayMsg The away message for this user. May contain HTML. To cancel "away" status set the awayMsg to ""
*/
-
+
public TocSetAwayCommand(String awayMsg) {
- this.awayMsg=Utils.encodeText(awayMsg);
+ this.awayMsg = Utils.encodeText(awayMsg);
}
-
-
- public String toString()
- {
- return(CMD+awayMsg);
+
+
+ public String toString() {
+ return (CMD + awayMsg);
}
public byte[] getBytes() {
- return(toString().getBytes());
+ return (toString().getBytes());
}
-
+
}
diff --git a/src/com/wilko/jaim/TocSetConfigCommand.java b/src/com/wilko/jaim/TocSetConfigCommand.java
index 4984a21..aea6d91 100644
--- a/src/com/wilko/jaim/TocSetConfigCommand.java
+++ b/src/com/wilko/jaim/TocSetConfigCommand.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -28,47 +28,42 @@ package com.wilko.jaim;
import java.util.Enumeration;
/**
- *
- * @author paulw
+ * @author paulw
*/
public class TocSetConfigCommand extends TocCommand {
-
- private StringBuffer config;
-
- private static String CMD="toc_set_config ";
- /** Creates a new instance of TocSetConfigCommand */
+ private static final String CMD = "toc_set_config ";
+ private final StringBuffer config;
+
+ /**
+ * Creates a new instance of TocSetConfigCommand
+ */
public TocSetConfigCommand() {
- config=new StringBuffer();
+ config = new StringBuffer();
}
-
- public void addGroup(Group g)
- {
- config.append("g "+g.getName()+"\n");
- Enumeration buddies=g.enumerateBuddies();
- while (buddies.hasMoreElements())
- {
- Buddy b = (Buddy)buddies.nextElement();
- config.append("b "+b.getName()+"\n");
- if (b.getPermit())
- {
- config.append("p "+b.getName()+"\n");
+
+ public void addGroup(Group g) {
+ config.append("g " + g.getName() + "\n");
+ Enumeration buddies = g.enumerateBuddies();
+ while (buddies.hasMoreElements()) {
+ Buddy b = (Buddy) buddies.nextElement();
+ config.append("b " + b.getName() + "\n");
+ if (b.getPermit()) {
+ config.append("p " + b.getName() + "\n");
}
- if (b.getDeny())
- {
- config.append("d "+b.getName()+"\n");
+ if (b.getDeny()) {
+ config.append("d " + b.getName() + "\n");
}
}
}
-
-
- public String toString()
- {
- return(CMD+'"'+config.toString()+'"');
+
+
+ public String toString() {
+ return (CMD + '"' + config.toString() + '"');
}
public byte[] getBytes() {
- return(toString().getBytes());
+ return (toString().getBytes());
}
-
+
}
diff --git a/src/com/wilko/jaim/TocSetIdleCommand.java b/src/com/wilko/jaim/TocSetIdleCommand.java
index 2d192ba..95e93c9 100644
--- a/src/com/wilko/jaim/TocSetIdleCommand.java
+++ b/src/com/wilko/jaim/TocSetIdleCommand.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -25,29 +25,29 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $version: $
*/
public class TocSetIdleCommand extends TocCommand {
- private int idle;
- private static final String CMD="toc_set_idle ";
-
- /** Creates new TocSetIdleCommand
- *@param idleSecs - the period for which the user has been idle
+ private static final String CMD = "toc_set_idle ";
+ private final int idle;
+
+ /**
+ * Creates new TocSetIdleCommand
+ *
+ * @param idleSecs - the period for which the user has been idle
*/
public TocSetIdleCommand(int idleSecs) {
- idle=idleSecs;
+ idle = idleSecs;
}
-
- public String toString()
- {
- return(CMD+idle);
+
+ public String toString() {
+ return (CMD + idle);
}
public byte[] getBytes() {
- return(toString().getBytes());
+ return (toString().getBytes());
}
-
+
}
diff --git a/src/com/wilko/jaim/TocSetInfoCommand.java b/src/com/wilko/jaim/TocSetInfoCommand.java
index 334346b..24d4183 100644
--- a/src/com/wilko/jaim/TocSetInfoCommand.java
+++ b/src/com/wilko/jaim/TocSetInfoCommand.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,31 +26,31 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $version: $
*/
public class TocSetInfoCommand extends TocCommand {
- private String information;
-
- private static String CMD="toc_set_info ";
- /** Creates new TocSetInfoCommand
- *@param information The information about this user can be located. May contain HTML
+ private static final String CMD = "toc_set_info ";
+ private final String information;
+
+ /**
+ * Creates new TocSetInfoCommand
+ *
+ * @param information The information about this user can be located. May contain HTML
*/
-
+
public TocSetInfoCommand(String information) {
- this.information=Utils.encodeText(information);
+ this.information = Utils.encodeText(information);
}
-
-
- public String toString()
- {
- return(CMD+information);
+
+
+ public String toString() {
+ return (CMD + information);
}
public byte[] getBytes() {
- return(toString().getBytes());
+ return (toString().getBytes());
}
-
+
}
diff --git a/src/com/wilko/jaim/TocSignonCommand.java b/src/com/wilko/jaim/TocSignonCommand.java
index de34420..0f73475 100644
--- a/src/com/wilko/jaim/TocSignonCommand.java
+++ b/src/com/wilko/jaim/TocSignonCommand.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,38 +26,37 @@
package com.wilko.jaim;
/**
- *
- * @author paulw
+ * @author paulw
* @version $Revision: 1.3 $
*/
public class TocSignonCommand extends TocCommand {
-
- private String server;
- private String username;
- private String password;
- private int port;
-
- private static final String AGENTNAME="jaim01";
-
- /** Creates new TocSignonCommand */
+
+ private static final String AGENTNAME = "jaim01";
+ private final String server;
+ private final String username;
+ private final String password;
+ private final int port;
+
+ /**
+ * Creates new TocSignonCommand
+ */
public TocSignonCommand(String server, int port, String username, String password) {
- this.server=server;
- this.port=port;
- this.username=Utils.normalise(username);
- this.password=Utils.roast(password);
+ this.server = server;
+ this.port = port;
+ this.username = Utils.normalise(username);
+ this.password = Utils.roast(password);
}
public byte[] getBytes() {
return toString().getBytes();
}
-
- public String toString()
- {
- String temp="toc_signon login.oscar.aol.com 5159 "+username+" "+password+" english "+AGENTNAME;
- return(temp);
+
+ public String toString() {
+ String temp = "toc_signon login.oscar.aol.com 5159 " + username + " " + password + " english " + AGENTNAME;
+ return (temp);
}
-
+
public void parseString(java.lang.String str) {
}
-
+
}
diff --git a/src/com/wilko/jaim/Utils.java b/src/com/wilko/jaim/Utils.java
index a226966..8ddac39 100644
--- a/src/com/wilko/jaim/Utils.java
+++ b/src/com/wilko/jaim/Utils.java
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
@@ -26,100 +26,92 @@
package com.wilko.jaim;
/**
- *
* @author paulw
* @version $Revision: 1.4 $
*/
public class Utils {
- private static final String roastKey="Tic/Toc";
- private static final int roastLen=7;
+ private static final String roastKey = "Tic/Toc";
+ private static final int roastLen = 7;
- /** convert a buddy name to normalised format - remove spaces and convert to lower case
+ /**
+ * convert a buddy name to normalised format - remove spaces and convert to lower case
+ *
* @param input The un-normalised buddy name
* @return the normalised buddy name
- */
+ */
public static String normalise(java.lang.String input) {
- StringBuffer output=new StringBuffer();
- String temp=input.toLowerCase();
- for (int i=0;i<input.length();i++)
- {
- char c=temp.charAt(i);
- if ((c>= '0' && c<='9')||(c>='a' && c<='z'))
- {
+ StringBuffer output = new StringBuffer();
+ String temp = input.toLowerCase();
+ for (int i = 0; i < input.length(); i++) {
+ char c = temp.charAt(i);
+ if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z')) {
output.append(c);
}
}
-
- return(output.toString());
+
+ return (output.toString());
}
-
- /** Roast a password using the AOL roasting protocol
+
+ /**
+ * Roast a password using the AOL roasting protocol
+ *
* @param password The password to be roasted
* @return The roasted password
- */
+ */
public static String roast(java.lang.String password) {
- char[] hexChars={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
-
- StringBuffer temppw=new StringBuffer();
+ char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+
+ StringBuffer temppw = new StringBuffer();
temppw.append("0x");
- for (int i=0;i<password.length();i++)
- {
- int roastedByte=password.charAt(i)^roastKey.charAt(i%roastLen);
-
- temppw.append(hexChars[(roastedByte>>4)&0x0f]);
- temppw.append(hexChars[roastedByte&0x0f]);
+ for (int i = 0; i < password.length(); i++) {
+ int roastedByte = password.charAt(i) ^ roastKey.charAt(i % roastLen);
+
+ temppw.append(hexChars[(roastedByte >> 4) & 0x0f]);
+ temppw.append(hexChars[roastedByte & 0x0f]);
}
- return(temppw.toString());
+ return (temppw.toString());
}
-
- /** This method performs a simple HTML strip on text. It looks for < characters and then skips input until a matching > is found.
+
+ /**
+ * This method performs a simple HTML strip on text. It looks for < characters and then skips input until a matching > is found.
* This may fail if the HTML tag contains an embedded '>'
+ *
* @param input The text to have HTML stripped
* @return The text stripped of html
- */
- public static String stripHTML(java.lang.String input)
- {
- StringBuffer output=new StringBuffer();
- boolean inHTML=false;
- for (int i=0;i<input.length();i++)
- {
- char c=input.charAt(i);
- if (c=='<')
- {
- inHTML=true;
- }
- else
- {
- if (c=='>') {
- inHTML=false;
- }
- else
- {
- if (!inHTML)
- {
+ */
+ public static String stripHTML(java.lang.String input) {
+ StringBuffer output = new StringBuffer();
+ boolean inHTML = false;
+ for (int i = 0; i < input.length(); i++) {
+ char c = input.charAt(i);
+ if (c == '<') {
+ inHTML = true;
+ } else {
+ if (c == '>') {
+ inHTML = false;
+ } else {
+ if (!inHTML) {
output.append(c);
}
}
}
}
- return(output.toString());
+ return (output.toString());
}
-
-
- /** Encode a text message so that it is suitable for transmission using toc_send_im
+
+
+ /**
+ * Encode a text message so that it is suitable for transmission using toc_send_im
*
* @param input The text to be encoded
* @return The encoded text
- */
- public static String encodeText(String input)
- {
- StringBuffer output=new StringBuffer("\"");
- for (int i=0;i<input.length();i++)
- {
- char c=input.charAt(i);
- switch (c)
- {
+ */
+ public static String encodeText(String input) {
+ StringBuffer output = new StringBuffer("\"");
+ for (int i = 0; i < input.length(); i++) {
+ char c = input.charAt(i);
+ switch (c) {
case '\"':
case '(':
case ')':
@@ -134,10 +126,10 @@ public class Utils {
}
output.append(c);
}
-
+
output.append('\"');
- return(output.toString());
+ return (output.toString());
}
-
-
+
+
}
diff --git a/src/com/wilko/jaimtest/JaimTest.java b/src/com/wilko/jaimtest/JaimTest.java
index 428949a..032af65 100644
--- a/src/com/wilko/jaimtest/JaimTest.java
+++ b/src/com/wilko/jaimtest/JaimTest.java
@@ -25,12 +25,13 @@
package com.wilko.jaimtest;
-import java.net.*;
-import java.io.*;
-
import com.wilko.jaim.*;
-import java.util.*;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Enumeration;
+import java.util.Iterator;
/**
* @author paulw