nan.nntp
Class NNTPClientImpl

java.lang.Object
  extended bynan.nntp.NNTPClientImpl
All Implemented Interfaces:
NNTPClient

public class NNTPClientImpl
extends java.lang.Object
implements NNTPClient

An implementation of the NNTP Client interface.

Version:
1.34, 1/6/04
Author:
John David Ratliff

Field Summary
static int NNTP_BODY_OK
          The status response for a successful BODY command.
static int NNTP_CONNECT_NO_POSTING
          The status response for NNTP connections that forbid posting.
static int NNTP_CONNECT_OK
          The status response for NNTP connections that allow posting.
static int NNTP_DISCONNECT_OK
          The status response for disconnecting from the NNTP server.
static int NNTP_GROUP_OK
          The status response for a successful GROUP command.
static int NNTP_HEAD_OK
          The status response for a successful HEAD command.
static int NNTP_LIST_OK
          The status response for successful LIST command.
static int NNTP_NEWGROUPS_OK
          The status response for a successful NEWGROUPS command.
static int NNTP_NEWNEWS_OK
          The status response for a successful NEWNEWS command.
static int NNTP_POST_CONTINUE
          The status response for POST command.
static int NNTP_POST_OK
          The status response for a successful POST command.
protected  java.io.BufferedReader reader
           
protected  java.io.PrintWriter writer
           
 
Constructor Summary
NNTPClientImpl()
          Creates a new NNTPClientImpl object.
 
Method Summary
 void connect(java.lang.String hostname, int port)
          Connects to the NNTP server.
 void disconnect()
          Disconnects from the server.
 MessageHeader getHeader(int article)
          Gets the MessageHeader of a newsgroup article.
 MessageHeader getHeader(java.lang.String messageId)
          Gets the MessageHeader of a newsgroup article.
 Message getMessage(int article)
          Gets a message from the news server.
 Message getMessage(int article, MessageHeader header)
          Gets a message from the news server.
 Message getMessage(java.lang.String messageId)
          Gets a message from the news server.
 Message getMessage(java.lang.String messageId, MessageHeader header)
          Gets a message from the news server.
 java.util.Iterator getMessagesSince(Newsgroup newsgroup, java.util.Date when)
          Gets the message IDs in an iterator of all messages added to a Newsgroup since a Date.
 NewsgroupList getNewsgroupList()
          Gets the list of available Newsgroups from the NNTP server.
 NewsgroupList getNewsgroupsSince(java.util.Date when)
          Gets the list of Newsgroups added to the server since a Date.
 boolean isConnected()
          Checks if this client is connected.
 boolean isPostingAllowed()
          Checks if posting is allowed on this server.
 boolean post(Message message)
          Posts a message to the NNTP server.
 boolean selectNewsgroup(Newsgroup newsgroup)
          Selects the current Newsgroup.
 void setWaitDialog(WaitDialog dialog)
          Sets the wait dialog that is waiting on a task to finish.
static void test()
          A method to test this class for correctness.
 java.lang.String toString()
          Returns a String representation of this NNTPClient.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

reader

protected java.io.BufferedReader reader

writer

protected java.io.PrintWriter writer

NNTP_CONNECT_OK

public static final int NNTP_CONNECT_OK
The status response for NNTP connections that allow posting.

See Also:
Constant Field Values

NNTP_CONNECT_NO_POSTING

public static final int NNTP_CONNECT_NO_POSTING
The status response for NNTP connections that forbid posting.

See Also:
Constant Field Values

NNTP_DISCONNECT_OK

public static final int NNTP_DISCONNECT_OK
The status response for disconnecting from the NNTP server.

See Also:
Constant Field Values

NNTP_LIST_OK

public static final int NNTP_LIST_OK
The status response for successful LIST command.

See Also:
Constant Field Values

NNTP_POST_CONTINUE

public static final int NNTP_POST_CONTINUE
The status response for POST command.

See Also:
Constant Field Values

NNTP_POST_OK

public static final int NNTP_POST_OK
The status response for a successful POST command.

See Also:
Constant Field Values

NNTP_GROUP_OK

public static final int NNTP_GROUP_OK
The status response for a successful GROUP command.

See Also:
Constant Field Values

NNTP_HEAD_OK

public static final int NNTP_HEAD_OK
The status response for a successful HEAD command.

See Also:
Constant Field Values

NNTP_BODY_OK

public static final int NNTP_BODY_OK
The status response for a successful BODY command.

See Also:
Constant Field Values

NNTP_NEWNEWS_OK

public static final int NNTP_NEWNEWS_OK
The status response for a successful NEWNEWS command.

See Also:
Constant Field Values

NNTP_NEWGROUPS_OK

public static final int NNTP_NEWGROUPS_OK
The status response for a successful NEWGROUPS command.

See Also:
Constant Field Values
Constructor Detail

NNTPClientImpl

public NNTPClientImpl()
Creates a new NNTPClientImpl object.

Method Detail

connect

public void connect(java.lang.String hostname,
                    int port)
             throws NNTPConnectException
Connects to the NNTP server.

Specified by:
connect in interface NNTPClient
Parameters:
hostname - The NNTP server's hostname.
port - The NNTP server's port.
Throws:
NNTPConnectException - if the connection failed.

isConnected

public boolean isConnected()
Checks if this client is connected.

Specified by:
isConnected in interface NNTPClient
Returns:
true if this client is connected; false otherwise.

disconnect

public void disconnect()
Disconnects from the server.

Specified by:
disconnect in interface NNTPClient

isPostingAllowed

public boolean isPostingAllowed()
Checks if posting is allowed on this server.

Specified by:
isPostingAllowed in interface NNTPClient
Returns:
true if posting is allowed; false otherwise.

getNewsgroupList

public NewsgroupList getNewsgroupList()
                               throws UnconnectedException
Gets the list of available Newsgroups from the NNTP server.

Specified by:
getNewsgroupList in interface NNTPClient
Returns:
The NewsgroupList of available Newsgroups.
Throws:
UnconnectedException - if this client is not connected.
NNTPException - if an unknown NNTP problem occurs.

selectNewsgroup

public boolean selectNewsgroup(Newsgroup newsgroup)
                        throws UnconnectedException
Selects the current Newsgroup.

Specified by:
selectNewsgroup in interface NNTPClient
Parameters:
newsgroup - The Newsgroup to select.
Returns:
true if the Newsgroup was selected; false otherwise.
Throws:
UnconnectedException - if this client is not connected.

getNewsgroupsSince

public NewsgroupList getNewsgroupsSince(java.util.Date when)
                                 throws UnconnectedException
Gets the list of Newsgroups added to the server since a Date.

Specified by:
getNewsgroupsSince in interface NNTPClient
Parameters:
when - The Date after which the newsgroups were added.
Returns:
The NewsgroupList of recent newsgroups, which may be empty.
Throws:
UnconnectedException - if this client is not connected.
NNTPException - if an unknown NNTP problem occurs.

getMessagesSince

public java.util.Iterator getMessagesSince(Newsgroup newsgroup,
                                           java.util.Date when)
                                    throws UnconnectedException
Gets the message IDs in an iterator of all messages added to a Newsgroup since a Date.

Specified by:
getMessagesSince in interface NNTPClient
Parameters:
newsgroup - The Newsgroup to check for new messages in.
when - The Date after which the messages were added.
Returns:
An Iterator of the message IDs of the new messages.
Throws:
UnconnectedException - if this client is not connected.
NNTPException - if an unknown NNTP problem occurs.

getHeader

public MessageHeader getHeader(int article)
                        throws UnconnectedException,
                               InvalidArticleException
Gets the MessageHeader of a newsgroup article.

Specified by:
getHeader in interface NNTPClient
Parameters:
article - The article ID in the current group.
Returns:
The MessageHeader.
Throws:
UnconnectedException - if this client is not connected.
InvalidArticleException - if the article does not exist on this server.

getHeader

public MessageHeader getHeader(java.lang.String messageId)
                        throws UnconnectedException,
                               InvalidArticleException
Gets the MessageHeader of a newsgroup article.

Specified by:
getHeader in interface NNTPClient
Parameters:
messageId - The message ID of the article.
Returns:
The MessageHeader.
Throws:
UnconnectedException - if this client is not connected.
InvalidArticleException - if the article does not exist on this server.

getMessage

public Message getMessage(int article,
                          MessageHeader header)
                   throws UnconnectedException,
                          InvalidArticleException
Gets a message from the news server. If the MessageHeader argument is null, the MessageHeader will be retrieved as well. If the MessageHeader is not null, it will be added as the MessageHeader of the Message.

Specified by:
getMessage in interface NNTPClient
Parameters:
article - The article ID in the current group.
header - The MessageHeader of this article.
Returns:
The Message.
Throws:
UnconnectedException - if this client is not connected.
InvalidArticleException - if the article does not exist on this server.

getMessage

public Message getMessage(int article)
                   throws UnconnectedException,
                          InvalidArticleException
Gets a message from the news server.

Specified by:
getMessage in interface NNTPClient
Parameters:
article - The article ID in the current group.
Returns:
The Message.
Throws:
UnconnectedException - if this client is not connected.
InvalidArticleException - if the article does not exist on this server.

getMessage

public Message getMessage(java.lang.String messageId,
                          MessageHeader header)
                   throws UnconnectedException,
                          InvalidArticleException
Gets a message from the news server. If the MessageHeader argument is null, the MessageHeader will be retrieved as well. If the MessageHeader is not null, it will be added as the MessageHeader of the Message.

Specified by:
getMessage in interface NNTPClient
Parameters:
messageId - The message ID of the article.
header - The MessageHeader of this article.
Returns:
The Message.
Throws:
UnconnectedException - if this client is not connected.
InvalidArticleException - if the article does not exist on this server.

getMessage

public Message getMessage(java.lang.String messageId)
                   throws UnconnectedException,
                          InvalidArticleException
Gets a message from the news server.

Specified by:
getMessage in interface NNTPClient
Parameters:
messageId - The message ID of the article.
Returns:
The Message.
Throws:
UnconnectedException - if this client is not connected.
InvalidArticleException - if the article does not exist on this server.

post

public boolean post(Message message)
             throws UnconnectedException
Posts a message to the NNTP server.

Specified by:
post in interface NNTPClient
Parameters:
message - The Message to post.
Returns:
true if the message was posted; false otherwise.
Throws:
UnconnectedException - if this client is not connected.

setWaitDialog

public void setWaitDialog(WaitDialog dialog)
Sets the wait dialog that is waiting on a task to finish.

Parameters:
dialog - The WaitDialog.

toString

public java.lang.String toString()
Returns a String representation of this NNTPClient.

Returns:
A String representation.

test

public static void test()
A method to test this class for correctness.