Format all code, add editorconfig

This commit is contained in:
floppydiskette 2024-05-10 00:32:34 +01:00
parent a1dff2cb8d
commit 3faced7068
Signed by: fwoppydwisk
SSH key fingerprint: SHA256:Hqn452XQ1ETzUt/FthJu6+OFkS4NBxCv5VQSEvuk7CE
52 changed files with 2011 additions and 1918 deletions

11
.editorconfig Normal file
View file

@ -0,0 +1,11 @@
root = true
[*]
indent_style = space
indent_size = 4
charset = utf-8
end_of_line = lf
insert_final_newline = true
[*.iml]
indent_size = 2

2
.github/README.md vendored
View file

@ -3,9 +3,11 @@
This is a fork of [Jaim](https://jaimlib.sourceforge.net/), a Java library that implements the AOL TOC protocol.
This fork features various improvements on the original Jaim:
- Support for chat invites
## Original README
```
Readme.txt for Jaimlib
----------------------

View file

@ -10,7 +10,7 @@
</target>
<target depends="init" name="compile">
<mkdir dir="build"/>
<mkdir dir="build"/>
<!-- Both srcdir and destdir should be package roots. -->
<!-- They could be different of course; in that case NetBeans can also be set -->
<!-- up to compile to a different filesystem in the same way; see Compiler Types: -->
@ -20,10 +20,10 @@
<target depends="init,compile" name="jar">
<mkdir dir="lib"/>
<copy todir="build">
<fileset dir="src">
<include name="**/*.properties"/>
</fileset>
<copy todir="build">
<fileset dir="src">
<include name="**/*.properties"/>
</fileset>
</copy>
<jar basedir="build" compress="true" jarfile="lib/jaimlib.jar">
<exclude name="**/*.java"/>
@ -34,9 +34,9 @@
<target depends="init,compile" name="jartest">
<mkdir dir="lib"/>
<jar basedir="build" compress="true" jarfile="lib/jaimtest.jar">
<manifest>
<attribute name="Main-Class" value="com.wilko.jaimtest.JaimTest"/>
</manifest>
<manifest>
<attribute name="Main-Class" value="com.wilko.jaimtest.JaimTest"/>
</manifest>
<exclude name="**/*.java"/>
</jar>
</target>
@ -55,29 +55,29 @@
</target>
<target depends="init" description="Clean all build products." name="clean">
<delete dir="doc/apidoc" includeEmptyDirs="true"/>
<delete dir="build" includeEmptyDirs="true"/>
<delete dir="lib" includeEmptyDirs="true"/>
<delete>
<fileset dir="src" includes="**/*.class"/>
</delete>
<delete dir="doc/apidoc" includeEmptyDirs="true"/>
<delete dir="build" includeEmptyDirs="true"/>
<delete dir="lib" includeEmptyDirs="true"/>
<delete>
<fileset dir="src" includes="**/*.class"/>
</delete>
</target>
<target depends="javadoc,compile,jar,jartest" name="dist">
<delete>
<fileset dir="." includes="jaimlib.tar*"/>
<fileset dir="." includes="jaimlib.tar*"/>
</delete>
<mkdir dir="jaimlib"/>
<mkdir dir="jaimlib/lib"/>
<mkdir dir="jaimlib/doc"/>
<copy todir="jaimlib">
<fileset dir="." includes="license.txt"/>
<fileset dir="." includes="build.xml"/>
<fileset dir="." includes="changes.txt"/>
<fileset dir="." includes="readme.txt"/>
<fileset dir="." includes="license.txt"/>
<fileset dir="." includes="build.xml"/>
<fileset dir="." includes="changes.txt"/>
<fileset dir="." includes="readme.txt"/>
</copy>
<copy todir="jaimlib/lib">
<fileset dir="lib"/>
<fileset dir="lib"/>
</copy>
<copy todir="jaimlib/doc">
<fileset dir="doc"/>
@ -89,20 +89,20 @@
</target>
<target depends="javadoc,compile,jar,jartest" name="srcdist">
<delete>
<fileset dir="." includes="jaimlibsrc.tar*"/>
<fileset dir="." includes="jaimlibsrc.tar*"/>
</delete>
<mkdir dir="jaimlib"/>
<mkdir dir="jaimlib/lib"/>
<mkdir dir="jaimlib/doc"/>
<mkdir dir="jaimlib/src"/>
<copy todir="jaimlib">
<fileset dir="." includes="license.txt"/>
<fileset dir="." includes="build.xml"/>
<fileset dir="." includes="changes.txt"/>
<fileset dir="." includes="readme.txt"/>
<fileset dir="." includes="license.txt"/>
<fileset dir="." includes="build.xml"/>
<fileset dir="." includes="changes.txt"/>
<fileset dir="." includes="readme.txt"/>
</copy>
<copy todir="jaimlib/lib">
<fileset dir="lib"/>
<fileset dir="lib"/>
</copy>
<copy todir="jaimlib/doc">
<fileset dir="doc"/>

View file

@ -4,6 +4,9 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/lib" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />

View file

@ -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;
public class Buddy {
/**
* Name of the buddy
*/
private final String buddyName;
/** Permit value */
private boolean permit;
/**
* Permit value
*/
private boolean permit;
/** deny value */
private boolean deny;
/**
* deny value
*/
private boolean deny;
/** Constructor that sets the buddy name
* @param name the name of this buddy.
*/
public Buddy ( String name )
{
buddyName = name;
}
/**
* 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 buddy name
*
* @return buddy name
*/
public String getName() {
return buddyName;
}
/** Gets the permit value
* @return permit value
*/
public boolean getPermit( )
{
return permit;
}
/**
* 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;
}
/**
* 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;
}
}
/**
* 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;
}
}

View file

@ -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;
@ -45,166 +48,164 @@ public class BuddyUpdateTocResponse extends TocResponse implements TocResponseHa
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;
}
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();
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));
}
}

View file

@ -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,19 +51,20 @@ 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();
@ -70,7 +73,9 @@ 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() {
@ -80,6 +85,7 @@ public class ChatInviteTocResponse extends TocResponse implements TocResponseHan
public String getRoomName() {
return roomName;
}
public String getRoomID() {
return roomID;
}
@ -92,12 +98,14 @@ public class ChatInviteTocResponse extends TocResponse implements TocResponseHan
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));
}
}

View file

@ -21,174 +21,189 @@
* ConfigTocResponse.java
* Created on 1, October 2002
*/
package com.wilko.jaim;
package com.wilko.jaim;
import java.util.*;
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 {
/**
* 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";
/**
* 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;
/** The Vector of Group objects */
private Vector buddyList = new Vector();
/**
* 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();
}
/** 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
*/
/**
* 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);
}
/**
* 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;
}
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);
/**
* Parses the config string.
*/
public TocResponse parseString(String message) {
ConfigTocResponse tr = new ConfigTocResponse();
tr.doParse(message);
return (tr);
}
char type = itemType.charAt(0);
switch (type)
{
case 'g':
currentGroup = new Group(itemValue);
buddyList.add(currentGroup);
break;
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);
case 'b':
char type = itemType.charAt(0);
switch (type) {
case 'g':
currentGroup = new Group(itemValue);
buddyList.add(currentGroup);
break;
tmpBuddy = getBuddy(itemValue);
//this shouldn't happen, but:
if(currentGroup==null)
{
currentGroup = new Group("<unknown>");
buddyList.add(currentGroup);
}
currentGroup.addBuddy(tmpBuddy);
case 'b':
tmpBuddy = getBuddy(itemValue);
//this shouldn't happen, but:
if (currentGroup == null) {
currentGroup = new Group("<unknown>");
buddyList.add(currentGroup);
}
currentGroup.addBuddy(tmpBuddy);
break;
break;
case 'p':
tmpBuddy = getBuddy(itemValue);
tmpBuddy.setPermit(true);
break;
case 'p':
tmpBuddy = getBuddy(itemValue);
tmpBuddy.setPermit(true);
break;
case 'm':
setMode(Integer.valueOf(itemValue).intValue());
break;
case 'm':
setMode(Integer.valueOf(itemValue).intValue());
break;
case 'd':
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);
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;
}
/**
* 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
*/
/** Gets the mode for this configuration
* @return mode for the configuration
*/
public int getMode( )
{
return mode;
}
private Buddy getBuddy(String buddyName) {
Buddy retBuddy = (Buddy) buddies.get(buddyName);
if (retBuddy == null) {
retBuddy = new Buddy(buddyName);
buddies.put(buddyName, retBuddy);
}
return (retBuddy);
}
/** 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));
}
/**
* 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));
}
}

View file

@ -27,23 +27,25 @@ 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";
public static final String RESPONSE_TYPE = "CONNECTIONLOST";
/** Creates a new instance of LoginCompleteTocResponse */
public ConnectionLostTocResponse() {
/**
* Creates a new instance of LoginCompleteTocResponse
*/
public ConnectionLostTocResponse() {
}
public String getResponseType() {
return (RESPONSE_TYPE);
}
public String toString()
{
public String toString() {
return (RESPONSE_TYPE);
}

View file

@ -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 = "";
}
/**
* 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
/**
* 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);
}
return (tr);
}
private void doParse(String str)
{
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);
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());
return (desc.toString());
}
catch (MissingResourceException e) {
return("Unable to locate error description:"+e.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));
}
}

View file

@ -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)
{
private void doParse(String str) {
StringTokenizer st=new StringTokenizer(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));
}
}

View file

@ -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);
}
}

View file

@ -25,21 +25,21 @@
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);
}

View file

@ -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 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 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 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();
}

View file

@ -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) {

View file

@ -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);
}
}

View file

@ -26,51 +26,44 @@
package com.wilko.jaim;
/**
*
* @author paulw
* @author paulw
* @version $Revision: 1.3 $
*/
public class FLAPInputFrame extends FLAPFrame {
/** Creates new FLAPInputFrame */
/**
* 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);
}
}

View file

@ -26,27 +26,26 @@
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() {

View file

@ -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);
}
}

View file

@ -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)
{
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;
}
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);
}
}

View file

@ -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);
}
}

View file

@ -25,77 +25,84 @@
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
*/

View file

@ -25,71 +25,89 @@
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();
/**
* Vector of buddies for this group
*/
private final Vector buddies = new Vector();
/** Name of this group */
private String groupName;
/**
* Name of this group
*/
private final String groupName;
/** This constructor sets the name of the group
/**
* 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
/**
* This method returns the buddies in this group
*
* @return a Collection of {@link Buddy} objects
*/
public java.util.Collection getBuddies() {

View file

@ -25,93 +25,100 @@
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
*/

File diff suppressed because it is too large Load diff

View file

@ -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;
private final TocResponse tocResponse;
/** Creates new JaimEvent */
/**
* 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);
}
}

View file

@ -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);
}

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -27,14 +27,17 @@ 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";
public static final String RESPONSE_TYPE = "LOGINCOMPLETE";
/** Creates a new instance of LoginCompleteTocResponse */
/**
* Creates a new instance of LoginCompleteTocResponse
*/
public LoginCompleteTocResponse() {
}
@ -42,8 +45,7 @@ public class LoginCompleteTocResponse extends TocResponse {
return (RESPONSE_TYPE);
}
public String toString()
{
public String toString() {
return (RESPONSE_TYPE);
}

View file

@ -26,44 +26,43 @@
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(':');
private void doParse(String str) {
int colonPos = str.indexOf(':');
if (colonPos != -1)
{
nickName=str.substring(colonPos+1);
}
if (colonPos != -1) {
nickName = str.substring(colonPos + 1);
}
}
public String getNickName()
{
return(nickName);
public String getNickName() {
return (nickName);
}
@ -71,12 +70,14 @@ public class NickTocResponse extends TocResponse implements TocResponseHandler {
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));
}
}

View file

@ -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));
}
}

View file

@ -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());
}
}

View file

@ -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());
}
}

View file

@ -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());
}
}

View file

@ -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());
}
}

View file

@ -26,13 +26,14 @@
package com.wilko.jaim;
/**
*
* @author paulw
* @author paulw
* @version $Revision: 1.3 $
*/
public abstract class TocCommand {
/** Creates new TocCommand */
/**
* Creates new TocCommand
*/
public TocCommand() {
}

View file

@ -26,32 +26,30 @@
package com.wilko.jaim;
/**
*
* @author paulw
* @author paulw
* @version $Revision: 1.3 $
*/
public class TocEvilCommand extends TocCommand {
private String buddy;
private boolean anonymous;
private final String buddy;
private final boolean anonymous;
/** Creates new TocEvilCommand */
/**
* 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";
public String toString() {
String ret = "toc_evil " + buddy;
if (anonymous) {
ret = ret + " anon";
} else
ret = ret + " norm";
return(ret);
return (ret);
}
public byte[] getBytes() {

View file

@ -39,32 +39,31 @@
package com.wilko.jaim;
/**
*
* @author paulw
* @author paulw
* @version $version: $
*/
public class TocGetInfoCommand extends TocCommand {
private String username;
private static final String CMD = "toc_get_info ";
private final String username;
private static String CMD="toc_get_info ";
/** Creates new TocGetInfoCommand
*@param username The screen name for whom information is requested
/**
* 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());
}
}

View file

@ -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;
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);
/**
* 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());
}
}

View file

@ -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";
private static final String CMD = "toc_init_done";
/** Creates new TocInitDoneCommand */
/**
* Creates new TocInitDoneCommand
*/
public TocInitDoneCommand() {
}
public byte[] getBytes() {
return(CMD.getBytes());
return (CMD.getBytes());
}
public String toString()
{
return(CMD);
public String toString() {
return (CMD);
}
}

View file

@ -26,22 +26,19 @@
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();

View file

@ -26,8 +26,7 @@
package com.wilko.jaim;
/**
*
* @author paulw
* @author paulw
* @version $Revision: 1.5 $
*/
@ -37,46 +36,40 @@ 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);
}
}

View file

@ -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);
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
/**
* 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);
}

View file

@ -26,31 +26,31 @@
package com.wilko.jaim;
/**
*
* @author paulw
* @author paulw
* @version $version: $
*/
public class TocSetAwayCommand extends TocCommand {
private String awayMsg;
private static final String CMD = "toc_set_away ";
private final String awayMsg;
private static String CMD="toc_set_away ";
/** Creates new TocSetInfoCommand
/**
* 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());
}
}

View file

@ -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 final String CMD = "toc_set_config ";
private final StringBuffer config;
private static String CMD="toc_set_config ";
/** Creates a new instance of TocSetConfigCommand */
/**
* 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());
}
}

View file

@ -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 ";
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
/**
* 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());
}
}

View file

@ -26,31 +26,31 @@
package com.wilko.jaim;
/**
*
* @author paulw
* @author paulw
* @version $version: $
*/
public class TocSetInfoCommand extends TocCommand {
private String information;
private static final String CMD = "toc_set_info ";
private final 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
/**
* 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());
}
}

View file

@ -26,35 +26,34 @@
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";
private final String server;
private final String username;
private final String password;
private final int port;
private static final String AGENTNAME="jaim01";
/** Creates new TocSignonCommand */
/**
* 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) {

View file

@ -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'};
char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
StringBuffer temppw=new StringBuffer();
StringBuffer temppw = new StringBuffer();
temppw.append("0x");
for (int i=0;i<password.length();i++)
{
int roastedByte=password.charAt(i)^roastKey.charAt(i%roastLen);
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]);
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 ')':
@ -136,7 +128,7 @@ public class Utils {
}
output.append('\"');
return(output.toString());
return (output.toString());
}

View file

@ -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