DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=24078>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=24078 [PATCH] Add support for XHDR NNTP command Summary: [PATCH] Add support for XHDR NNTP command Product: Commons Version: 1.1.0 Platform: Other OS/Version: Other Status: NEW Severity: Enhancement Priority: Other Component: Net AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] Index: net/src/java/org/apache/commons/net/nntp/NNTP.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/net/src/java/org/apache/commons/net/nntp/NNTP.java,v retrieving revision 1.7 diff -u -p -r1.7 NNTP.java --- net/src/java/org/apache/commons/net/nntp/NNTP.java 4 Sep 2003 20:32:43 -0000 1.7 +++ net/src/java/org/apache/commons/net/nntp/NNTP.java 23 Oct 2003 19:37:57 -0000 @@ -110,9 +110,11 @@ import org.apache.commons.net.SocketClie * <p> * <p> * @author Daniel F. Savarese + * @author Ted Wise * @see NNTPClient * @see NNTPConnectionClosedException * @see org.apache.commons.net.MalformedServerReplyException + * @version $Id$ ***/ public class NNTP extends SocketClient @@ -998,6 +1000,35 @@ public class NNTP extends SocketClient ***/ 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()); } /** Index: net/src/java/org/apache/commons/net/nntp/NNTPClient.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/net/src/java/org/apache/commons/net/nntp/NNTPClient.java,v retrieving revision 1.5 diff -u -p -r1.5 NNTPClient.java --- net/src/java/org/apache/commons/net/nntp/NNTPClient.java 4 Sep 2003 20:32:43 -0000 1.5 +++ net/src/java/org/apache/commons/net/nntp/NNTPClient.java 23 Oct 2003 19:37:58 -0000 @@ -116,9 +116,11 @@ import org.apache.commons.net.MalformedS * <p> * <p> * @author Daniel F. Savarese + * @author Ted Wise * @see NNTP * @see NNTPConnectionClosedException * @see org.apache.commons.net.MalformedServerReplyException + * @version $Id$ ***/ public class NNTPClient extends NNTP @@ -1245,6 +1247,59 @@ public class NNTPClient extends NNTP { 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, new Integer(articleNumber).toString()); + } + + /** + * 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)); } } Index: net/src/java/org/apache/commons/net/nntp/NNTPCommand.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/net/src/java/org/apache/commons/net/nntp/NNTPCommand.java,v retrieving revision 1.4 diff -u -p -r1.4 NNTPCommand.java --- net/src/java/org/apache/commons/net/nntp/NNTPCommand.java 4 Sep 2003 20:32:43 -0000 1.4 +++ net/src/java/org/apache/commons/net/nntp/NNTPCommand.java 23 Oct 2003 19:37:58 -0000 @@ -59,6 +59,8 @@ package org.apache.commons.net.nntp; * the meaning of the codes, familiarity with RFC 977 is assumed. * <p> * @author Daniel F. Savarese + * @author Ted Wise + * @version $Id$ ***/ public final class NNTPCommand @@ -81,6 +83,7 @@ public final class NNTPCommand 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() @@ -89,7 +92,7 @@ public final class NNTPCommand 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]
