Methods Summary |
---|
private void | __parseArticlePointer(java.lang.String reply, ArticlePointer pointer)
StringTokenizer tokenizer;
// Do loop is a kluge to simulate goto
do
{
tokenizer = new StringTokenizer(reply);
if (tokenizer.countTokens() < 3)
break;
// Skip numeric response value
tokenizer.nextToken();
// Get article number
try
{
pointer.articleNumber = Integer.parseInt(tokenizer.nextToken());
}
catch (NumberFormatException e)
{
break;
}
// Get article id
pointer.articleId = tokenizer.nextToken();
return ;
}
while (false);
throw new MalformedServerReplyException(
"Could not parse article pointer.\nServer reply: " + reply);
|
private void | __parseGroupReply(java.lang.String reply, NewsgroupInfo info)
String count, first, last;
StringTokenizer tokenizer;
// Do loop is a kluge to simulate goto
do
{
tokenizer = new StringTokenizer(reply);
if (tokenizer.countTokens() < 5)
break;
// Skip numeric response value
tokenizer.nextToken();
// Get estimated article count
count = tokenizer.nextToken();
// Get first article number
first = tokenizer.nextToken();
// Get last article number
last = tokenizer.nextToken();
// Get newsgroup name
info._setNewsgroup(tokenizer.nextToken());
try
{
info._setArticleCount(Integer.parseInt(count));
info._setFirstArticle(Integer.parseInt(first));
info._setLastArticle(Integer.parseInt(last));
}
catch (NumberFormatException e)
{
break;
}
info._setPostingPermission(NewsgroupInfo.UNKNOWN_POSTING_PERMISSION);
return ;
}
while (false);
throw new MalformedServerReplyException(
"Could not parse newsgroup info.\nServer reply: " + reply);
|
private NewsgroupInfo | __parseNewsgroupListEntry(java.lang.String entry)
NewsgroupInfo result;
StringTokenizer tokenizer;
int lastNum, firstNum;
String last, first, permission;
result = new NewsgroupInfo();
tokenizer = new StringTokenizer(entry);
if (tokenizer.countTokens() < 4)
return null;
result._setNewsgroup(tokenizer.nextToken());
last = tokenizer.nextToken();
first = tokenizer.nextToken();
permission = tokenizer.nextToken();
try
{
lastNum = Integer.parseInt(last);
firstNum = Integer.parseInt(first);
result._setFirstArticle(firstNum);
result._setLastArticle(lastNum);
if((firstNum == 0) && (lastNum == 0))
result._setArticleCount(0);
else
result._setArticleCount(lastNum - firstNum + 1);
}
catch (NumberFormatException e)
{
return null;
}
switch (permission.charAt(0))
{
case 'y":
case 'Y":
result._setPostingPermission(
NewsgroupInfo.PERMITTED_POSTING_PERMISSION);
break;
case 'n":
case 'N":
result._setPostingPermission(
NewsgroupInfo.PROHIBITED_POSTING_PERMISSION);
break;
case 'm":
case 'M":
result._setPostingPermission(
NewsgroupInfo.MODERATED_POSTING_PERMISSION);
break;
default:
result._setPostingPermission(
NewsgroupInfo.UNKNOWN_POSTING_PERMISSION);
break;
}
return result;
|
private NewsgroupInfo[] | __readNewsgroupListing()
int size;
String line;
Vector list;
BufferedReader reader;
NewsgroupInfo tmp, info[];
reader = new BufferedReader(new DotTerminatedMessageReader(_reader_));
// Start of with a big vector because we may be reading a very large
// amount of groups.
list = new Vector(2048);
while ((line = reader.readLine()) != null)
{
tmp = __parseNewsgroupListEntry(line);
if (tmp != null)
list.addElement(tmp);
else
throw new MalformedServerReplyException(line);
}
if ((size = list.size()) < 1)
return new NewsgroupInfo[0];
info = new NewsgroupInfo[size];
list.copyInto(info);
return info;
|
private java.io.Reader | __retrieve(int command, java.lang.String articleId, ArticlePointer pointer)
Reader reader;
if (articleId != null)
{
if (!NNTPReply.isPositiveCompletion(sendCommand(command, articleId)))
return null;
}
else
{
if (!NNTPReply.isPositiveCompletion(sendCommand(command)))
return null;
}
if (pointer != null)
__parseArticlePointer(getReplyString(), pointer);
reader = new DotTerminatedMessageReader(_reader_);
return reader;
|
private java.io.Reader | __retrieve(int command, int articleNumber, ArticlePointer pointer)
Reader reader;
if (!NNTPReply.isPositiveCompletion(sendCommand(command,
Integer.toString(articleNumber))))
return null;
if (pointer != null)
__parseArticlePointer(getReplyString(), pointer);
reader = new DotTerminatedMessageReader(_reader_);
return reader;
|
private java.io.Reader | __retrieveArticleInfo(java.lang.String articleRange)Private implementation of XOVER functionality.
See {@link NNTP#xover}
for legal agument formats. Alternatively, read RFC 2980 :-)
if (!NNTPReply.isPositiveCompletion(xover(articleRange)))
return null;
return new DotTerminatedMessageReader(_reader_);
|
private java.io.Reader | __retrieveHeader(java.lang.String header, java.lang.String articleRange)Private implementation of XHDR functionality.
See {@link NNTP#xhdr}
for legal agument formats. Alternatively, read RFC 1036.
if (!NNTPReply.isPositiveCompletion(xhdr(header, articleRange)))
return null;
return new DotTerminatedMessageReader(_reader_);
|
public boolean | authenticate(java.lang.String username, java.lang.String password)Log into a news server by sending the AUTHINFO USER/AUTHINFO
PASS command sequence. This is usually sent in response to a
480 reply code from the NNTP server.
int replyCode = authinfoUser(username);
if (replyCode == NNTPReply.MORE_AUTH_INFO_REQUIRED)
{
replyCode = authinfoPass(password);
if (replyCode == NNTPReply.AUTHENTICATION_ACCEPTED)
{
_isAllowedToPost = true;
return true;
}
}
return false;
|
public boolean | completePendingCommand()There are a few NNTPClient methods that do not complete the
entire sequence of NNTP commands to complete a transaction. These
commands require some action by the programmer after the reception
of a positive preliminary command. After the programmer's code
completes its actions, it must call this method to receive
the completion reply from the server and verify the success of the
entire transaction.
For example
writer = client.postArticle();
if(writer == null) // failure
return false;
header = new SimpleNNTPHeader("foobar@foo.com", "Just testing");
header.addNewsgroup("alt.test");
writer.write(header.toString());
writer.write("This is just a test");
writer.close();
if(!client.completePendingCommand()) // failure
return false;
return NNTPReply.isPositiveCompletion(getReply());
|
public java.io.Writer | forwardArticle(java.lang.String articleId)
if (!NNTPReply.isPositiveIntermediate(ihave(articleId)))
return null;
return new DotTerminatedMessageWriter(_writer_);
|
public java.lang.String | listHelp()List the command help from the server.
StringWriter help;
Reader reader;
if (!NNTPReply.isInformational(help()))
return null;
help = new StringWriter();
reader = new DotTerminatedMessageReader(_reader_);
Util.copyReader(reader, help);
reader.close();
help.close();
return help.toString();
|
public java.lang.String[] | listNewNews(NewGroupsOrNewsQuery query)List all new articles added to the NNTP server since a particular
date subject to the conditions of the specified query. If no new
new news is found, a zero length array will be returned. If the
command fails, null will be returned. You must add at least one
newsgroup to the query, else the command will fail. Each String
in the returned array is a unique message identifier including the
enclosing < and >.
int size;
String line;
Vector list;
String[] result;
BufferedReader reader;
if (!NNTPReply.isPositiveCompletion(newnews(
query.getNewsgroups(), query.getDate(), query.getTime(),
query.isGMT(), query.getDistributions())))
return null;
list = new Vector();
reader = new BufferedReader(new DotTerminatedMessageReader(_reader_));
while ((line = reader.readLine()) != null)
list.addElement(line);
size = list.size();
if (size < 1)
return new String[0];
result = new String[size];
list.copyInto(result);
return result;
|
public NewsgroupInfo[] | listNewNewsgroups(NewGroupsOrNewsQuery query)List all new newsgroups added to the NNTP server since a particular
date subject to the conditions of the specified query. If no new
newsgroups were added, a zero length array will be returned. If the
command fails, null will be returned.
if (!NNTPReply.isPositiveCompletion(newgroups(
query.getDate(), query.getTime(),
query.isGMT(), query.getDistributions())))
return null;
return __readNewsgroupListing();
|
public NewsgroupInfo[] | listNewsgroups()List all newsgroups served by the NNTP server. If no newsgroups
are served, a zero length array will be returned. If the command
fails, null will be returned.
if (!NNTPReply.isPositiveCompletion(list()))
return null;
return __readNewsgroupListing();
|
public NewsgroupInfo[] | listNewsgroups(java.lang.String wildmat)An overloaded listNewsgroups() command that allows us to
specify with a pattern what groups we want to list. Wraps the
LIST ACTIVE command.
if(!NNTPReply.isPositiveCompletion(listActive(wildmat)))
return null;
return __readNewsgroupListing();
|
public boolean | logout()Logs out of the news server gracefully by sending the QUIT command.
However, you must still disconnect from the server before you can open
a new connection.
return NNTPReply.isPositiveCompletion(quit());
|
public java.io.Writer | postArticle()Post an article to the NNTP server. This method returns a
DotTerminatedMessageWriter instance to which the article can be
written. Null is returned if the posting attempt fails. You
should check {@link NNTP#isAllowedToPost isAllowedToPost() }
before trying to post. However, a posting
attempt can fail due to malformed headers.
You must not issue any commands to the NNTP server (i.e., call any
(other methods) until you finish writing to the returned Writer
instance and close it. The NNTP protocol uses the same stream for
issuing commands as it does for returning results. Therefore the
returned Writer actually writes directly to the NNTP connection.
After you close the writer, you can execute new commands. If you
do not follow these requirements your program will not work properly.
Different NNTP servers will require different header formats, but
you can use the provided
{@link org.apache.commons.net.nntp.SimpleNNTPHeader}
class to construct the bare minimum acceptable header for most
news readers. To construct more complicated headers you should
refer to RFC 822. When the Java Mail API is finalized, you will be
able to use it to compose fully compliant Internet text messages.
The DotTerminatedMessageWriter takes care of doubling line-leading
dots and ending the message with a single dot upon closing, so all
you have to worry about is writing the header and the message.
Upon closing the returned Writer, you need to call
{@link #completePendingCommand completePendingCommand() }
to finalize the posting and verify its success or failure from
the server reply.
if (!NNTPReply.isPositiveIntermediate(post()))
return null;
return new DotTerminatedMessageWriter(_writer_);
|
public java.io.Reader | retrieveArticle(int articleNumber, ArticlePointer pointer)Retrieves an article from the currently selected newsgroup. The
article is referenced by its article number.
The article number and identifier contained in the server reply
are returned through an ArticlePointer. The articleId
field of the ArticlePointer cannot always be trusted because some
NNTP servers do not correctly follow the RFC 977 reply format.
A DotTerminatedMessageReader is returned from which the article can
be read. If the article does not exist, null is returned.
You must not issue any commands to the NNTP server (i.e., call any
other methods) until you finish reading the message from the returned
Reader instance.
The NNTP protocol uses the same stream for issuing commands as it does
for returning results. Therefore the returned Reader actually reads
directly from the NNTP connection. After the end of message has been
reached, new commands can be executed and their replies read. If
you do not follow these requirements, your program will not work
properly.
return __retrieve(NNTPCommand.ARTICLE, articleNumber, pointer);
|
public java.io.Reader | retrieveArticle(int articleNumber)Same as retrieveArticle(articleNumber, null)
return retrieveArticle(articleNumber, null);
|
public java.io.Reader | retrieveArticle(java.lang.String articleId, ArticlePointer pointer)Retrieves an article from the NNTP server. The article is referenced
by its unique article identifier (including the enclosing < and >).
The article number and identifier contained in the server reply
are returned through an ArticlePointer. The articleId
field of the ArticlePointer cannot always be trusted because some
NNTP servers do not correctly follow the RFC 977 reply format.
A DotTerminatedMessageReader is returned from which the article can
be read. If the article does not exist, null is returned.
You must not issue any commands to the NNTP server (i.e., call any
other methods) until you finish reading the message from the returned
Reader instance.
The NNTP protocol uses the same stream for issuing commands as it does
for returning results. Therefore the returned Reader actually reads
directly from the NNTP connection. After the end of message has been
reached, new commands can be executed and their replies read. If
you do not follow these requirements, your program will not work
properly.
return __retrieve(NNTPCommand.ARTICLE, articleId, pointer);
|
public java.io.Reader | retrieveArticle(java.lang.String articleId)Same as retrieveArticle(articleId, null)
return retrieveArticle(articleId, null);
|
public java.io.Reader | retrieveArticle()Same as retrieveArticle(null)
return retrieveArticle(null);
|
public java.io.Reader | retrieveArticleBody(java.lang.String articleId, ArticlePointer pointer)Retrieves an article body from the NNTP server. The article is
referenced
by its unique article identifier (including the enclosing < and >).
The article number and identifier contained in the server reply
are returned through an ArticlePointer. The articleId
field of the ArticlePointer cannot always be trusted because some
NNTP servers do not correctly follow the RFC 977 reply format.
A DotTerminatedMessageReader is returned from which the article can
be read. If the article does not exist, null is returned.
You must not issue any commands to the NNTP server (i.e., call any
other methods) until you finish reading the message from the returned
Reader instance.
The NNTP protocol uses the same stream for issuing commands as it does
for returning results. Therefore the returned Reader actually reads
directly from the NNTP connection. After the end of message has been
reached, new commands can be executed and their replies read. If
you do not follow these requirements, your program will not work
properly.
return __retrieve(NNTPCommand.BODY, articleId, pointer);
|
public java.io.Reader | retrieveArticleBody(java.lang.String articleId)Same as retrieveArticleBody(articleId, null)
return retrieveArticleBody(articleId, null);
|
public java.io.Reader | retrieveArticleBody()Same as retrieveArticleBody(null)
return retrieveArticleBody(null);
|
public java.io.Reader | retrieveArticleBody(int articleNumber, ArticlePointer pointer)Retrieves an article body from the currently selected newsgroup. The
article is referenced by its article number.
The article number and identifier contained in the server reply
are returned through an ArticlePointer. The articleId
field of the ArticlePointer cannot always be trusted because some
NNTP servers do not correctly follow the RFC 977 reply format.
A DotTerminatedMessageReader is returned from which the article can
be read. If the article does not exist, null is returned.
You must not issue any commands to the NNTP server (i.e., call any
other methods) until you finish reading the message from the returned
Reader instance.
The NNTP protocol uses the same stream for issuing commands as it does
for returning results. Therefore the returned Reader actually reads
directly from the NNTP connection. After the end of message has been
reached, new commands can be executed and their replies read. If
you do not follow these requirements, your program will not work
properly.
return __retrieve(NNTPCommand.BODY, articleNumber, pointer);
|
public java.io.Reader | retrieveArticleBody(int articleNumber)Same as retrieveArticleBody(articleNumber, null)
return retrieveArticleBody(articleNumber, null);
|
public java.io.Reader | retrieveArticleHeader(java.lang.String articleId, ArticlePointer pointer)Retrieves an article header from the NNTP server. The article is
referenced
by its unique article identifier (including the enclosing < and >).
The article number and identifier contained in the server reply
are returned through an ArticlePointer. The articleId
field of the ArticlePointer cannot always be trusted because some
NNTP servers do not correctly follow the RFC 977 reply format.
A DotTerminatedMessageReader is returned from which the article can
be read. If the article does not exist, null is returned.
You must not issue any commands to the NNTP server (i.e., call any
other methods) until you finish reading the message from the returned
Reader instance.
The NNTP protocol uses the same stream for issuing commands as it does
for returning results. Therefore the returned Reader actually reads
directly from the NNTP connection. After the end of message has been
reached, new commands can be executed and their replies read. If
you do not follow these requirements, your program will not work
properly.
return __retrieve(NNTPCommand.HEAD, articleId, pointer);
|
public java.io.Reader | retrieveArticleHeader(java.lang.String articleId)Same as retrieveArticleHeader(articleId, null)
return retrieveArticleHeader(articleId, null);
|
public java.io.Reader | retrieveArticleHeader()Same as retrieveArticleHeader(null)
return retrieveArticleHeader(null);
|
public java.io.Reader | retrieveArticleHeader(int articleNumber, ArticlePointer pointer)Retrieves an article header from the currently selected newsgroup. The
article is referenced by its article number.
The article number and identifier contained in the server reply
are returned through an ArticlePointer. The articleId
field of the ArticlePointer cannot always be trusted because some
NNTP servers do not correctly follow the RFC 977 reply format.
A DotTerminatedMessageReader is returned from which the article can
be read. If the article does not exist, null is returned.
You must not issue any commands to the NNTP server (i.e., call any
other methods) until you finish reading the message from the returned
Reader instance.
The NNTP protocol uses the same stream for issuing commands as it does
for returning results. Therefore the returned Reader actually reads
directly from the NNTP connection. After the end of message has been
reached, new commands can be executed and their replies read. If
you do not follow these requirements, your program will not work
properly.
return __retrieve(NNTPCommand.HEAD, articleNumber, pointer);
|
public java.io.Reader | retrieveArticleHeader(int articleNumber)Same as retrieveArticleHeader(articleNumber, null)
return retrieveArticleHeader(articleNumber, null);
|
public java.io.Reader | retrieveArticleInfo(int articleNumber)Return article headers for a specified post.
return __retrieveArticleInfo(Integer.toString(articleNumber));
|
public java.io.Reader | retrieveArticleInfo(int lowArticleNumber, int highArticleNumber)Return article headers for all articles between lowArticleNumber
and highArticleNumber, inclusively.
return
__retrieveArticleInfo(new String(lowArticleNumber + "-" +
highArticleNumber));
|
public java.io.Reader | retrieveHeader(java.lang.String header, int articleNumber)Return an article header for a specified post.
return __retrieveHeader(header, Integer.toString(articleNumber));
|
public java.io.Reader | retrieveHeader(java.lang.String header, int lowArticleNumber, int highArticleNumber)Return an article header for all articles between lowArticleNumber
and highArticleNumber, inclusively.
return
__retrieveHeader(header,
new String(lowArticleNumber + "-" +
highArticleNumber));
|
public boolean | selectArticle(java.lang.String articleId, ArticlePointer pointer)Select an article by its unique identifier (including enclosing
< and >) and return its article number and id through the
pointer parameter. This is achieved through the STAT command.
According to RFC 977, this will NOT set the current article pointer
on the server. To do that, you must reference the article by its
number.
if (articleId != null)
{
if (!NNTPReply.isPositiveCompletion(stat(articleId)))
return false;
}
else
{
if (!NNTPReply.isPositiveCompletion(stat()))
return false;
}
if (pointer != null)
__parseArticlePointer(getReplyString(), pointer);
return true;
|
public boolean | selectArticle(java.lang.String articleId)Same as selectArticle(articleId, null)
return selectArticle(articleId, null);
|
public boolean | selectArticle(ArticlePointer pointer)Same as selectArticle(null, articleId) . Useful
for retrieving the current article number.
return selectArticle(null, pointer);
|
public boolean | selectArticle(int articleNumber, ArticlePointer pointer)Select an article in the currently selected newsgroup by its number.
and return its article number and id through the
pointer parameter. This is achieved through the STAT command.
According to RFC 977, this WILL set the current article pointer
on the server. Use this command to select an article before retrieving
it, or to obtain an article's unique identifier given its number.
if (!NNTPReply.isPositiveCompletion(stat(articleNumber)))
return false;
if (pointer != null)
__parseArticlePointer(getReplyString(), pointer);
return true;
|
public boolean | selectArticle(int articleNumber)Same as selectArticle(articleNumber, null)
return selectArticle(articleNumber, null);
|
public boolean | selectNewsgroup(java.lang.String newsgroup, NewsgroupInfo info)Select the specified newsgroup to be the target of for future article
retrieval and posting operations. Also return the newsgroup
information contained in the server reply through the info parameter.
if (!NNTPReply.isPositiveCompletion(group(newsgroup)))
return false;
if (info != null)
__parseGroupReply(getReplyString(), info);
return true;
|
public boolean | selectNewsgroup(java.lang.String newsgroup)Same as selectNewsgroup(newsgroup, null)
return selectNewsgroup(newsgroup, null);
|
public boolean | selectNextArticle(ArticlePointer pointer)Select the article following the currently selected article in the
currently selected newsgroup and return its number and unique id
through the pointer parameter. Because of deviating server
implementations, the articleId information cannot be trusted. To
obtain the article identifier, issue a
selectArticle(pointer.articleNumber, pointer) immediately
afterward.
if (!NNTPReply.isPositiveCompletion(next()))
return false;
if (pointer != null)
__parseArticlePointer(getReplyString(), pointer);
return true;
|
public boolean | selectNextArticle()Same as selectNextArticle(null)
return selectNextArticle(null);
|
public boolean | selectPreviousArticle(ArticlePointer pointer)Select the article preceeding the currently selected article in the
currently selected newsgroup and return its number and unique id
through the pointer parameter. Because of deviating server
implementations, the articleId information cannot be trusted. To
obtain the article identifier, issue a
selectArticle(pointer.articleNumber, pointer) immediately
afterward.
if (!NNTPReply.isPositiveCompletion(last()))
return false;
if (pointer != null)
__parseArticlePointer(getReplyString(), pointer);
return true;
|
public boolean | selectPreviousArticle()Same as selectPreviousArticle(null)
return selectPreviousArticle(null);
|