diff options
Diffstat (limited to 'src/com/wilko/jaim/responses')
-rw-r--r-- | src/com/wilko/jaim/responses/BuddyUpdateTocResponse.java | 213 | ||||
-rw-r--r-- | src/com/wilko/jaim/responses/ChatInviteTocResponse.java | 113 | ||||
-rw-r--r-- | src/com/wilko/jaim/responses/ConfigTocResponse.java | 211 | ||||
-rw-r--r-- | src/com/wilko/jaim/responses/ConnectionLostTocResponse.java | 52 | ||||
-rw-r--r-- | src/com/wilko/jaim/responses/ErrorTocResponse.java | 146 | ||||
-rw-r--r-- | src/com/wilko/jaim/responses/EvilTocResponse.java | 127 | ||||
-rw-r--r-- | src/com/wilko/jaim/responses/GenericTocResponse.java | 97 | ||||
-rw-r--r-- | src/com/wilko/jaim/responses/GotoTocResponse.java | 115 | ||||
-rw-r--r-- | src/com/wilko/jaim/responses/IMTocResponse.java | 132 | ||||
-rw-r--r-- | src/com/wilko/jaim/responses/LoginCompleteTocResponse.java | 52 | ||||
-rw-r--r-- | src/com/wilko/jaim/responses/NickTocResponse.java | 85 | ||||
-rw-r--r-- | src/com/wilko/jaim/responses/SignOnTocResponse.java | 82 | ||||
-rw-r--r-- | src/com/wilko/jaim/responses/TocResponse.java | 46 | ||||
-rw-r--r-- | src/com/wilko/jaim/responses/TocResponseFactory.java | 75 | ||||
-rw-r--r-- | src/com/wilko/jaim/responses/TocResponseHandler.java | 47 |
15 files changed, 1593 insertions, 0 deletions
diff --git a/src/com/wilko/jaim/responses/BuddyUpdateTocResponse.java b/src/com/wilko/jaim/responses/BuddyUpdateTocResponse.java new file mode 100644 index 0000000..1d79198 --- /dev/null +++ b/src/com/wilko/jaim/responses/BuddyUpdateTocResponse.java @@ -0,0 +1,213 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * BuddyUpdateTocResponse.java + * + * Created on 5 May 2002, 21:19 + */ + +package com.wilko.jaim.responses; + +import com.wilko.jaim.JaimEventListener; + +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 + * + * @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; + private int idleTime; + private boolean onAOL; + private boolean unconfirmed; + private boolean admin; + private boolean confirmed; + private Date signonTime; + private boolean away; + + /** + * Creates new BuddyUpdateTocResponse + */ + public BuddyUpdateTocResponse() { + 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 + * + * @param str The String containing the buddy update + */ + public TocResponse parseString(java.lang.String str) { + BuddyUpdateTocResponse tr = new BuddyUpdateTocResponse(); + tr.doParse(str); + return (tr); + } + + private void doParse(String str) { + cmd = str; + StringTokenizer st = new StringTokenizer(str, ":"); + + 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; + } + } + } + if (userclass.length() > 2) { + if (userclass.charAt(2) == 'U') { + away = true; + } + } + } + + /** + * Get the away status of the buddy specified by this update + * + * @return true if the buddy is "away" + */ + public boolean isAway() { + return (away); + } + + /** + * 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 + * + * @return The buddy name + */ + public String getBuddy() { + return (buddyName); + } + + /** + * Obtain the online status of this buddy update + * + * @return true if the buddy is on line + */ + public boolean isOnline() { + return (online); + } + + /** + * Obtain the idle time of this buddy + * + * @return The idle time in seconds + */ + public int getIdleTime() { + return (idleTime); + } + + /** + * Obtain the "Evil" (Warning) level of this buddy + * + * @return The warning level as a percentage + */ + public int getEvil() { + return (evil); + } + + /** + * Is this buddy an "Administrator" + * + * @return true if an administrator + */ + public boolean isAdmin() { + return (admin); + } + + /** + * IS this buddy a "confirmed" user + * + * @return True if this buddy is confirmed + */ + public boolean isConfirmed() { + return (confirmed); + } + + /** + * Is this user an "Unconfirmed user" + * + * @return True if this user is unconfirmed + */ + public boolean isUnconfirmed() { + return (unconfirmed); + } + + /** + * Get the signon time of this buddy + * + * @return The date/time of signon + */ + public Date getSignonTime() { + return (signonTime); + } + + /** + * 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/responses/ChatInviteTocResponse.java b/src/com/wilko/jaim/responses/ChatInviteTocResponse.java new file mode 100644 index 0000000..6bdba33 --- /dev/null +++ b/src/com/wilko/jaim/responses/ChatInviteTocResponse.java @@ -0,0 +1,113 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * BuddyUpdateTocResponse.java + * + * Created on 5 May 2002, 21:19 + */ + +package com.wilko.jaim.responses; + +import com.wilko.jaim.JaimEventListener; + +import java.util.StringTokenizer; + +/** + * 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; + + /** + * Creates new BuddyUpdateTocResponse + */ + public ChatInviteTocResponse() { + roomName = ""; + roomID = ""; + senderScreenname = ""; + message = ""; + } + + /** + * 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); + } + + private void doParse(String str) { + cmd = str; + StringTokenizer st = new StringTokenizer(str, ":"); + + st.nextToken(); + roomName = st.nextToken(); + roomID = st.nextToken(); + senderScreenname = st.nextToken(); + message = st.nextToken(); + } + + /** + * 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; + } + + public String getRoomName() { + return roomName; + } + + public String getRoomID() { + return roomID; + } + + public String getSenderScreenname() { + return senderScreenname; + } + + public String getMessage() { + return message; + } + + /** + * 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/responses/ConfigTocResponse.java b/src/com/wilko/jaim/responses/ConfigTocResponse.java new file mode 100644 index 0000000..dc72488 --- /dev/null +++ b/src/com/wilko/jaim/responses/ConfigTocResponse.java @@ -0,0 +1,211 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * ConfigTocResponse.java + * Created on 1, October 2002 + */ +package com.wilko.jaim.responses; + +import 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); + 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 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 buddyName 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/responses/ConnectionLostTocResponse.java b/src/com/wilko/jaim/responses/ConnectionLostTocResponse.java new file mode 100644 index 0000000..355c4a9 --- /dev/null +++ b/src/com/wilko/jaim/responses/ConnectionLostTocResponse.java @@ -0,0 +1,52 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * ConnectionLostTocResponse.java + * + * Created on November 2, 2002, 2:52 PM + */ + +package com.wilko.jaim.responses; + +/** + * 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 + * @version: $revision: $ + */ +public class ConnectionLostTocResponse extends TocResponse { + + public static final String RESPONSE_TYPE = "CONNECTIONLOST"; + + /** + * Creates a new instance of LoginCompleteTocResponse + */ + public ConnectionLostTocResponse() { + } + + public String getResponseType() { + return (RESPONSE_TYPE); + } + + public String toString() { + return (RESPONSE_TYPE); + } + +} diff --git a/src/com/wilko/jaim/responses/ErrorTocResponse.java b/src/com/wilko/jaim/responses/ErrorTocResponse.java new file mode 100644 index 0000000..eecdfeb --- /dev/null +++ b/src/com/wilko/jaim/responses/ErrorTocResponse.java @@ -0,0 +1,146 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * ErrorTocResponse.java + * + * Created on 4 May 2002, 14:52 + */ + +package com.wilko.jaim.responses; + +import com.wilko.jaim.JaimEventListener; + +import java.util.MissingResourceException; + +/** + * 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; + + /** + * Creates new ErrorTocResponse + */ + public ErrorTocResponse() { + 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 + * + * @param str The error response string + */ + 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); + } + } + + } + + /** + * Obtain the error code for this response + * + * @return The error code + */ + public int getErrorCode() { + return (errorCode); + } + + /** + * Get the error text (if any) associated with this error response + * + * @return The error text + */ + public String getErrorText() { + return (errorText); + } + + /** + * 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"); + if (argpos != -1) { + desc.replace(argpos, argpos + 1, errorText); + } + return (desc.toString()); + + } catch (MissingResourceException e) { + return ("Unable to locate error description:" + e); + } + } + + public String getResponseType() { + return RESPONSE_TYPE; + } + + /** + * 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/responses/EvilTocResponse.java b/src/com/wilko/jaim/responses/EvilTocResponse.java new file mode 100644 index 0000000..60ee5a9 --- /dev/null +++ b/src/com/wilko/jaim/responses/EvilTocResponse.java @@ -0,0 +1,127 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * EvilTocResponse.java + * + * Created on 6 May 2002, 16:49 + */ + +package com.wilko.jaim.responses; + +import com.wilko.jaim.JaimEventListener; + +import java.util.StringTokenizer; + +/** + * 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; + + /** + * Creates new EvilTocResponse + */ + public EvilTocResponse() { + anonymousEvil = true; + evilBy = ""; + evilAmount = 0; + } + + /** + * Parse the evil message from the TOC server + * + * @param str The evil message + */ + public TocResponse parseString(java.lang.String str) { + EvilTocResponse tr = new EvilTocResponse(); + tr.doParse(str); + return (tr); + } + + 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; + } + } + + /** + * 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); + } + + /** + * 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); + } + + /** + * Obtain the anonymous status of this warning + * + * @return true if this warning was issued anonymously + */ + public boolean isAnonymous() { + return (anonymousEvil); + } + + /** + * Used by the response dispatcher + * + * @return The response type + */ + public String getResponseType() { + return RESPONSE_TYPE; + } + + + /** + * 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/responses/GenericTocResponse.java b/src/com/wilko/jaim/responses/GenericTocResponse.java new file mode 100644 index 0000000..04acd71 --- /dev/null +++ b/src/com/wilko/jaim/responses/GenericTocResponse.java @@ -0,0 +1,97 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * GenericTocCommand.java + * + * Created on 4 May 2002, 12:07 + */ + +package com.wilko.jaim.responses; + +import com.wilko.jaim.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 + */ + public GenericTocResponse() { + this.cmd = ""; + } + + /** + * Parse an incoming string + * + * @param str The response string to be parsed + */ + public TocResponse parseString(String str) { + GenericTocResponse tr = new GenericTocResponse(); + tr.doParse(str); + return tr; + } + + private void doParse(String str) { + cmd = str; + } + + /** + * Get a byte array that contains the response + * + * @return The response as an array of bytes + */ + public byte[] getBytes() { + return (cmd.getBytes()); + } + + /** + * Convert this response to a string + * + * @return The response as a string + */ + public String toString() { + return (cmd); + } + + /** + * Used in the response dispatching process + * + * @return The respnse type + */ + public String getResponseType() { + return ("UNKNOWN"); + } + + /** + * 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); + } + +} diff --git a/src/com/wilko/jaim/responses/GotoTocResponse.java b/src/com/wilko/jaim/responses/GotoTocResponse.java new file mode 100644 index 0000000..f98dfb6 --- /dev/null +++ b/src/com/wilko/jaim/responses/GotoTocResponse.java @@ -0,0 +1,115 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocIMResponse.java + * + * Created on 4 May 2002, 14:38 + */ + +package com.wilko.jaim.responses; + +import com.wilko.jaim.JaimEventListener; + +/** + * 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; + + /** + * Creates new GotoTocResponse + */ + public GotoTocResponse() { + windowName = ""; + URL = ""; + } + + /** + * Obtain the suggested window name for this URL + * + * @return The window name + */ + public String getWindowName() { + return (windowName); + } + + /** + * Obtain the URL + * + * @return The URL + */ + public String getURL() { + return (URL); + } + + + /** + * Parse an incoming response string + * + * @param str The string to be parsed + */ + public TocResponse parseString(java.lang.String str) { + GotoTocResponse tr = new GotoTocResponse(); + 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) { + windowName = str.substring(0, colonPos); + URL = str.substring(colonPos + 1); + + } + } + + } + + /** + * Obtain the response type for response dispatching purposes + * + * @return The response type + */ + public String getResponseType() { + return (RESPONSE_TYPE); + } + + /** + * 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/responses/IMTocResponse.java b/src/com/wilko/jaim/responses/IMTocResponse.java new file mode 100644 index 0000000..93e57af --- /dev/null +++ b/src/com/wilko/jaim/responses/IMTocResponse.java @@ -0,0 +1,132 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocIMResponse.java + * + * Created on 4 May 2002, 14:38 + */ + +package com.wilko.jaim.responses; + +import com.wilko.jaim.JaimEventListener; +import com.wilko.jaim.Utils; + +/** + * 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; + + /** + * Creates new TocIMResponse + */ + public IMTocResponse() { + from = ""; + msg = ""; + autoResponse = false; + } + + /** + * Obtain the name of the buddy who sent this instant message + * + * @return The senders name + */ + public String getFrom() { + return (from); + } + + /** + * Obtain the message + * + * @return The message + * @see Utils#stripHTML + */ + public String getMsg() { + return (msg); + } + + /** + * Is this response an automatically generated response? + * + * @return true if this is an automatically generated response + */ + public boolean getAutoResponse() { + return (autoResponse); + } + + /** + * Parse an incoming IM response string + * + * @param str The string to be parsed + */ + public TocResponse parseString(java.lang.String str) { + IMTocResponse tr = new IMTocResponse(); + 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) { + 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); + } + } + } + + } + + /** + * Obtain the response type for response dispatching purposes + * + * @return The response type + */ + public String getResponseType() { + return (RESPONSE_TYPE); + } + + /** + * 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/responses/LoginCompleteTocResponse.java b/src/com/wilko/jaim/responses/LoginCompleteTocResponse.java new file mode 100644 index 0000000..e9eb463 --- /dev/null +++ b/src/com/wilko/jaim/responses/LoginCompleteTocResponse.java @@ -0,0 +1,52 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * LoginCompleteTocResponse.java + * + * Created on November 2, 2002, 2:52 PM + */ + +package com.wilko.jaim.responses; + +/** + * This is a "pseudo" TOC response - it is delivered to JaimLib clients to indicate that login processing has been completed successfully. + * + * @author wilko + * @version: $revision: $ + */ +public class LoginCompleteTocResponse extends TocResponse { + + public static final String RESPONSE_TYPE = "LOGINCOMPLETE"; + + /** + * Creates a new instance of LoginCompleteTocResponse + */ + public LoginCompleteTocResponse() { + } + + public String getResponseType() { + return (RESPONSE_TYPE); + } + + public String toString() { + return (RESPONSE_TYPE); + } + +} diff --git a/src/com/wilko/jaim/responses/NickTocResponse.java b/src/com/wilko/jaim/responses/NickTocResponse.java new file mode 100644 index 0000000..ec8a537 --- /dev/null +++ b/src/com/wilko/jaim/responses/NickTocResponse.java @@ -0,0 +1,85 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * NickTocResponse.java + * + * Created on 6 May 2002, 17:21 + */ + +package com.wilko.jaim.responses; + +import com.wilko.jaim.JaimConnection; + +/** + * 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; + + + /** + * Creates new NickTocResponse + */ + public NickTocResponse() { + nickName = ""; + } + + + public TocResponse parseString(java.lang.String str) { + NickTocResponse tr = new NickTocResponse(); + tr.doParse(str); + return (tr); + } + + private void doParse(String str) { + int colonPos = str.indexOf(':'); + + if (colonPos != -1) { + nickName = str.substring(colonPos + 1); + } + + + } + + public String getNickName() { + return (nickName); + } + + + public String getResponseType() { + return RESPONSE_TYPE; + } + + /** + * 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/responses/SignOnTocResponse.java b/src/com/wilko/jaim/responses/SignOnTocResponse.java new file mode 100644 index 0000000..f8b6a48 --- /dev/null +++ b/src/com/wilko/jaim/responses/SignOnTocResponse.java @@ -0,0 +1,82 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * SignOnTocResponse.java + * + * Created on 4 May 2002, 13:29 + */ + +package com.wilko.jaim.responses; + +import com.wilko.jaim.JaimConnection; + +/** + * The SignOnTocResponse is used internally to manage the TOC signon process. It is not delivered to clients of {@link JaimConnection} + * + * @author paulw + * @version $Revision: 1.5 $ + */ +public class SignOnTocResponse extends TocResponse implements TocResponseHandler { + + public static final String RESPONSE_TYPE = "SIGN_ON"; + String version; + + + /** + * Creates new SignOnTocResponse + */ + public SignOnTocResponse() { + version = ""; + } + + public String getResponseType() { + return (RESPONSE_TYPE); + } + + protected String getVersion() { + return (version); + } + + + public TocResponse parseString(String str) { + SignOnTocResponse tr = new SignOnTocResponse(); + tr.doParse(str); + return (tr); + } + + 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. + * + * @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/responses/TocResponse.java b/src/com/wilko/jaim/responses/TocResponse.java new file mode 100644 index 0000000..3168378 --- /dev/null +++ b/src/com/wilko/jaim/responses/TocResponse.java @@ -0,0 +1,46 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocCommand.java + * + * Created on 4 May 2002, 11:19 + */ + +package com.wilko.jaim.responses; + +/** + * @author paulw + * @version $Revision: 1.5 $ + */ +public abstract class TocResponse { + + protected String cmd; + + public TocResponse() { + cmd = ""; + } + + public String toString() { + return (cmd); + } + + public abstract String getResponseType(); + +} diff --git a/src/com/wilko/jaim/responses/TocResponseFactory.java b/src/com/wilko/jaim/responses/TocResponseFactory.java new file mode 100644 index 0000000..6c53009 --- /dev/null +++ b/src/com/wilko/jaim/responses/TocResponseFactory.java @@ -0,0 +1,75 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocResponseFactory.java + * + * Created on 4 May 2002, 12:05 + */ + +package com.wilko.jaim.responses; + +/** + * @author paulw + * @version $Revision: 1.5 $ + */ + +import java.util.Vector; + +public abstract class TocResponseFactory { + + static Vector responseHandlers = new Vector(); + + /** + * Creates new TocResponseFactory + */ + public TocResponseFactory() { + } + + public static void addResponseHandler(TocResponseHandler h) { + synchronized (responseHandlers) { + responseHandlers.add(h); + } + } + + public 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); + } + return (tr); + } + +} diff --git a/src/com/wilko/jaim/responses/TocResponseHandler.java b/src/com/wilko/jaim/responses/TocResponseHandler.java new file mode 100644 index 0000000..7934a7e --- /dev/null +++ b/src/com/wilko/jaim/responses/TocResponseHandler.java @@ -0,0 +1,47 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +package com.wilko.jaim.responses; + +/** + * @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 + */ + + 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 + */ + + TocResponse parseString(String Response); + +} + |