dfs 2004/04/10 14:11:48
Modified: net/src/java/org/apache/commons/net/nntp NNTP.java
NNTPClient.java NNTPCommand.java
Log:
Applied Ted Wise's patch from issue report 24078 which added XHDR support to
NNTPClient.
Revision Changes Path
1.11 +37 -5
jakarta-commons/net/src/java/org/apache/commons/net/nntp/NNTP.java
Index: NNTP.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/nntp/NNTP.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- NNTP.java 29 Feb 2004 10:26:53 -0000 1.10
+++ NNTP.java 10 Apr 2004 21:11:48 -0000 1.11
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.net.nntp;
+package org.apache.commons.net.nntp;
+
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
@@ -70,6 +71,8 @@
* <p>
* <p>
* @author Daniel F. Savarese
+ * @author Rory Winston
+ * @author Ted Wise
* @see NNTPClient
* @see NNTPConnectionClosedException
* @see org.apache.commons.net.MalformedServerReplyException
@@ -922,7 +925,7 @@
* <p>
* @param password a valid password.
* @return The reply code received from the server. The server should
- * return a 281 or 502 for this command.
+ * return a 281 or 502 for this command.
* @exception NNTPConnectionClosedException
* If the NNTP server prematurely closes the connection as a result
* of the client being idle or some other reason causing the server
@@ -935,7 +938,7 @@
String passParameter = "PASS " + password;
return sendCommand(NNTPCommand.AUTHINFO, passParameter);
}
-
+
/***
* A convenience method to send the NNTP XOVER command to the server,
* receive the reply, and return the reply code.
@@ -959,7 +962,36 @@
public int xover(String selectedArticles) throws IOException {
return sendCommand(NNTPCommand.XOVER, selectedArticles);
}
-
+
+ /***
+ * A convenience method to send the NNTP XHDR command to the server,
+ * receive the reply, and return the reply code.
+ * <p>
+ * @param header a String naming a header line (e.g., "subject"). See
+ * RFC-1036 for a list of valid header lines.
+ * @param selectedArticles a String representation of the range of
+ * article headers required. This may be an article number, or a
+ * range of article numbers in the form "XXXX-YYYY", where XXXX
+ * and YYYY are valid article numbers in the current group. It
+ * also may be of the form "XXX-", meaning "return XXX and all
+ * following articles" In this revision, the last format is not
+ * possible (yet).
+ * @return The reply code received from the server.
+ * @exception NNTPConnectionClosedException
+ * If the NNTP server prematurely closes the connection as a result
+ * of the client being idle or some other reason causing the server
+ * to send NNTP reply code 400. This exception may be caught either
+ * as an IOException or independently as itself.
+ * @exception IOException If an I/O error occurs while either sending the
+ * command or receiving the server reply.
+ ***/
+ public int xhdr(String header, String selectedArticles) throws IOException {
+ StringBuffer command = new StringBuffer(header);
+ command.append(" ");
+ command.append(selectedArticles);
+ return sendCommand(NNTPCommand.XHDR, command.toString());
+ }
+
/**
* A convenience wrapper for the extended LIST command that takes
* an argument, allowing us to selectively list multiple groups.
@@ -973,7 +1005,7 @@
StringBuffer command = new StringBuffer("ACTIVE ");
command.append(wildmat);
return sendCommand(NNTPCommand.LIST, command.toString());
- }
+ }
}
/* Emacs configuration
1.10 +64 -7
jakarta-commons/net/src/java/org/apache/commons/net/nntp/NNTPClient.java
Index: NNTPClient.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/nntp/NNTPClient.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- NNTPClient.java 29 Feb 2004 10:26:53 -0000 1.9
+++ NNTPClient.java 10 Apr 2004 21:11:48 -0000 1.10
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.net.nntp;
+package org.apache.commons.net.nntp;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
@@ -76,6 +77,8 @@
* <p>
* <p>
* @author Daniel F. Savarese
+ * @author Rory Winston
+ * @author Ted Wise
* @see NNTP
* @see NNTPConnectionClosedException
* @see org.apache.commons.net.MalformedServerReplyException
@@ -1144,14 +1147,14 @@
* @throws IOException
*/
public boolean authenticate(String username, String password)
- throws IOException
+ throws IOException
{
int replyCode = authinfoUser(username);
-
+
if (replyCode == NNTPReply.MORE_AUTH_INFO_REQUIRED)
{
replyCode = authinfoPass(password);
-
+
if (replyCode == NNTPReply.AUTHENTICATION_ACCEPTED)
{
_isAllowedToPost = true;
@@ -1160,7 +1163,7 @@
}
return false;
}
-
+
/***
* Private implementation of XOVER functionality.
*
@@ -1180,7 +1183,7 @@
return new DotTerminatedMessageReader(_reader_);
}
-
+
/**
* Return article headers for a specified post.
* <p>
@@ -1192,7 +1195,7 @@
{
return __retrieveArticleInfo(new Integer(articleNumber).toString());
}
-
+
/**
* Return article headers for all articles between lowArticleNumber
* and highArticleNumber, inclusively.
@@ -1209,6 +1212,60 @@
return
__retrieveArticleInfo(new String(lowArticleNumber + "-" +
highArticleNumber));
+ }
+
+ /***
+ * Private implementation of XHDR functionality.
+ *
+ * See <a href="org.apache.commons.nntp.NNTP.html#xhdr">
+ * for legal agument formats. Alternatively, read RFC 1036.
+ * <p>
+ * @param header
+ * @param articleRange
+ * @return Returns a DotTerminatedMessageReader if successful, null
+ * otherwise
+ * @exception IOException
+ */
+ private Reader __retrieveHeader(String header, String articleRange)
+ throws IOException
+ {
+ if (!NNTPReply.isPositiveCompletion(xhdr(header, articleRange)))
+ return null;
+
+ return new DotTerminatedMessageReader(_reader_);
+ }
+
+ /**
+ * Return an article header for a specified post.
+ * <p>
+ * @param header the header to retrieve
+ * @param articleNumber the article to retrieve the header for
+ * @return a DotTerminatedReader if successful, null otherwise
+ * @throws IOException
+ */
+ public Reader retrieveHeader(String header, int articleNumber) throws
IOException
+ {
+ return __retrieveHeader(header, Integer.toString(articleNumber));
+ }
+
+ /**
+ * Return an article header for all articles between lowArticleNumber
+ * and highArticleNumber, inclusively.
+ * <p>
+ * @param header
+ * @param lowArticleNumber
+ * @param highArticleNumber
+ * @return a DotTerminatedReader if successful, null otherwise
+ * @throws IOException
+ */
+ public Reader retrieveHeader(String header, int lowArticleNumber,
+ int highArticleNumber)
+ throws IOException
+ {
+ return
+ __retrieveHeader(header,
+ new String(lowArticleNumber + "-" +
+ highArticleNumber));
}
}
1.9 +4 -1
jakarta-commons/net/src/java/org/apache/commons/net/nntp/NNTPCommand.java
Index: NNTPCommand.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/nntp/NNTPCommand.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- NNTPCommand.java 29 Feb 2004 10:26:53 -0000 1.8
+++ NNTPCommand.java 10 Apr 2004 21:11:48 -0000 1.9
@@ -20,6 +20,8 @@
* the meaning of the codes, familiarity with RFC 977 is assumed.
* <p>
* @author Daniel F. Savarese
+ * @author Rory Winston
+ * @author Ted Wise
***/
public final class NNTPCommand
@@ -42,6 +44,7 @@
public static final int STAT = 14;
public static final int AUTHINFO = 15;
public static final int XOVER = 16;
+ public static final int XHDR = 17;
// Cannot be instantiated
private NNTPCommand()
@@ -50,7 +53,7 @@
static final String[] _commands = {
"ARTICLE", "BODY", "GROUP", "HEAD", "HELP", "IHAVE", "LAST", "LIST",
"NEWGROUPS", "NEWNEWS", "NEXT", "POST", "QUIT", "SLAVE", "STAT",
- "AUTHINFO", "XOVER"
+ "AUTHINFO", "XOVER", "XHDR"
};
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]