wtanaka.praya.dict
Class DictClient

java.lang.Object
  |
  +--wtanaka.praya.Protocol
        |
        +--wtanaka.praya.dict.DictClient
All Implemented Interfaces:
java.lang.Runnable, java.io.Serializable

public class DictClient
extends Protocol
implements java.lang.Runnable

Main entry point for this package.

Version:
$Name: $ $Date: 2002/07/14 19:36:25 $
Author:
$Author: wtanaka $
See Also:
Serialized Form

Field Summary
private static java.lang.String[] defaultStratDesc
           
private static java.lang.String[] defaultStrategies
           
private  java.net.Socket dictSocket
           
private  java.lang.String m_database
           
private  Recipient m_dictRecipient
           
private  java.lang.String m_server
           
private  java.lang.Thread myThread
           
static int port
           
private  java.io.BufferedReader sockIn
           
private  java.io.PrintWriter sockOut
           
private  java.lang.String[] strategies
           
private  int strategy
           
private  java.lang.String[] strategyDesc
           
 
Fields inherited from class wtanaka.praya.Protocol
descriptionListeners, iAmGarbage, m_buddyList, m_configPanel, m_currentDescription, m_messageListeners, recipientListeners
 
Constructor Summary
DictClient()
           
DictClient(java.lang.String server)
           
 
Method Summary
 void checkForNewMessages(boolean isAutomatic)
          Checks for new messages on the protocol.
 void connect()
          Connects to the network, if that makes any sense.
 CommandInterface[] consoleCommands()
          Command-based input to the DictClient.
 void disconnect()
          Disconnects from the network, if that makes any sense.
 Recipient getDefaultRecipient()
           
static java.awt.Image getIcon()
           
static java.lang.String getProtocolDescription()
          Used to describe the class of this protocol, before any instances have been created.
 java.lang.String getServer()
          The name of the DICT server to which this DictClient instance will next connect.
 java.lang.String[] getStrategies()
           
 boolean isConnected()
          Returns if the protocol is connected right now.
private  Definition parse151()
           
private  java.lang.String parseAtom()
           
private  java.lang.String parseSqDqOrPair()
           
private  java.lang.String parseString()
           
private  java.lang.String parseWord()
           
private  Message process(java.lang.String response)
          processes the given message, returning a Message if the user should get a message.
 void run()
           
 void sendCommand(java.lang.String command)
          Sends the verbatim command passed in as a parameter to the dict server
private  void setServer(java.lang.String server)
          Sets the server to which this DictClient will next connect
 void setStatus(Status status)
          Nobody else is ever able to see our status, so this method call does nothing.
private  void updateDescription(java.lang.String server)
           
private  java.lang.String wordAt(java.lang.String line, int offset)
           
 
Methods inherited from class wtanaka.praya.Protocol
addDescriptionListener, addListener, addRecipient, addRecipientListener, changeRecipientStatus, clearBuddyList, console, fireDescriptionChanged, fireRecipientAppeared, fireRecipientChanged, fireRecipientDisappeared, getBuddies, getConfigPanelInstance, getConfiguration, getCurrentDescription, getObjInstance, getStatusForBuddy, initialize, isGarbage, markAsGarbage, pushMessage, readObject, removeDescriptionListener, removeListener, removeRecipient, removeRecipientListener, setCurrentDescription, writeObject
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

port

public static final int port

m_server

private java.lang.String m_server

dictSocket

private java.net.Socket dictSocket

sockOut

private java.io.PrintWriter sockOut

sockIn

private java.io.BufferedReader sockIn

myThread

private java.lang.Thread myThread

m_database

private java.lang.String m_database

defaultStrategies

private static final java.lang.String[] defaultStrategies

defaultStratDesc

private static final java.lang.String[] defaultStratDesc

strategies

private java.lang.String[] strategies

strategyDesc

private java.lang.String[] strategyDesc

strategy

private int strategy

m_dictRecipient

private final Recipient m_dictRecipient
Constructor Detail

DictClient

public DictClient()

DictClient

public DictClient(java.lang.String server)
Method Detail

checkForNewMessages

public void checkForNewMessages(boolean isAutomatic)
Description copied from class: Protocol
Checks for new messages on the protocol. This might make sense for nntp/usenet, email, etc. but not for irc, gale, zephyr, icq. If any new messages are found, push them.
Overrides:
checkForNewMessages in class Protocol
Following copied from class: wtanaka.praya.Protocol
Parameters:
isAutomatic - true if the check is generated automatically with a timer. false if the check is generated manually by the user.

getStrategies

public java.lang.String[] getStrategies()

connect

public void connect()
             throws java.io.IOException
Description copied from class: Protocol
Connects to the network, if that makes any sense. skip if it does not.
Overrides:
connect in class Protocol
Following copied from class: wtanaka.praya.Protocol
Throws:
java.io.IOException - if the connection fails due to an I/O error.
java.lang.InterruptedException - todo, why does it throw this?

disconnect

public void disconnect()
Description copied from class: Protocol
Disconnects from the network, if that makes any sense. skip if it does not.
Overrides:
disconnect in class Protocol

setStatus

public void setStatus(Status status)
Nobody else is ever able to see our status, so this method call does nothing.
Overrides:
setStatus in class Protocol

isConnected

public boolean isConnected()
Description copied from class: Protocol
Returns if the protocol is connected right now. Good for telling if you need to call connect() again after the connection dies.
Overrides:
isConnected in class Protocol

updateDescription

private final void updateDescription(java.lang.String server)

getDefaultRecipient

public Recipient getDefaultRecipient()
Overrides:
getDefaultRecipient in class Protocol

sendCommand

public void sendCommand(java.lang.String command)
Sends the verbatim command passed in as a parameter to the dict server
Parameters:
the - command to send

consoleCommands

public CommandInterface[] consoleCommands()
Command-based input to the DictClient.
 /HELP             : this message
 /SERVER <hostname>: switch DICT server (does not reconnect)
 /CONNECT          : connect to server
 /DISCONNECT       : disconnect from server
 /SERVERHELP       : get help from server
 /STRATEGY foo     : change strategy to foo
 /DATABASE foo     : change database to foo (! first match, * for all)
 /DEFINE foo       : define a word
 /MATCH foo        : search for a word
 
Overrides:
consoleCommands in class Protocol

parseSqDqOrPair

private java.lang.String parseSqDqOrPair()
                                  throws ParseException,
                                         java.io.IOException

parseString

private java.lang.String parseString()
                              throws ParseException,
                                     java.io.IOException

parseAtom

private java.lang.String parseAtom()
                            throws java.io.IOException

parseWord

private java.lang.String parseWord()
                            throws ParseException,
                                   java.io.IOException

parse151

private Definition parse151()
                     throws java.io.IOException

wordAt

private java.lang.String wordAt(java.lang.String line,
                                int offset)

process

private Message process(java.lang.String response)
                 throws java.io.InterruptedIOException,
                        java.io.IOException
processes the given message, returning a Message if the user should get a message.
Returns:
the Message to give to the user if any, null if none.

getIcon

public static java.awt.Image getIcon()

getProtocolDescription

public static java.lang.String getProtocolDescription()
Used to describe the class of this protocol, before any instances have been created.

run

public void run()
Specified by:
run in interface java.lang.Runnable

getServer

public java.lang.String getServer()
The name of the DICT server to which this DictClient instance will next connect.
Returns:
the name of the DICT server to which this DictClient instance will next connect.

setServer

private void setServer(java.lang.String server)
Sets the server to which this DictClient will next connect
Parameters:
server - the name of the server e.g. "dict.org"