View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.net.nntp;
19  
20  /***
21   * NNTPReply stores a set of constants for NNTP reply codes.  To interpret
22   * the meaning of the codes, familiarity with RFC 977 is assumed.
23   * The mnemonic constant names are transcriptions from the code descriptions
24   * of RFC 977.  For those who think in terms of the actual reply code values,
25   * a set of CODE_NUM constants are provided where NUM is the numerical value
26   * of the code.
27   * <p>
28   * <p>
29   * @author Daniel F. Savarese
30   ***/
31  
32  public final class NNTPReply
33  {
34  
35      public static final int CODE_100 = 100;
36      public static final int CODE_199 = 199;
37      public static final int CODE_200 = 200;
38      public static final int CODE_201 = 201;
39      public static final int CODE_202 = 202;
40      public static final int CODE_205 = 205;
41      public static final int CODE_211 = 211;
42      public static final int CODE_215 = 215;
43      public static final int CODE_220 = 220;
44      public static final int CODE_221 = 221;
45      public static final int CODE_222 = 222;
46      public static final int CODE_223 = 223;
47      public static final int CODE_230 = 230;
48      public static final int CODE_231 = 231;
49      public static final int CODE_235 = 235;
50      public static final int CODE_240 = 240;
51      public static final int CODE_281 = 281;
52      public static final int CODE_335 = 335;
53      public static final int CODE_340 = 340;
54      public static final int CODE_381 = 381;
55      public static final int CODE_400 = 400;
56      public static final int CODE_408 = 408;
57      public static final int CODE_411 = 411;
58      public static final int CODE_412 = 412;
59      public static final int CODE_420 = 420;
60      public static final int CODE_421 = 421;
61      public static final int CODE_422 = 422;
62      public static final int CODE_423 = 423;
63      public static final int CODE_430 = 430;
64      public static final int CODE_435 = 435;
65      public static final int CODE_436 = 436;
66      public static final int CODE_437 = 437;
67      public static final int CODE_440 = 440;
68      public static final int CODE_441 = 441;
69      public static final int CODE_482 = 482;
70      public static final int CODE_500 = 500;
71      public static final int CODE_501 = 501;
72      public static final int CODE_502 = 502;
73      public static final int CODE_503 = 503;
74  
75      public static final int HELP_TEXT_FOLLOWS                = CODE_100;
76      public static final int DEBUG_OUTPUT                     = CODE_199;
77      public static final int SERVER_READY_POSTING_ALLOWED     = CODE_200;
78      public static final int SERVER_READY_POSTING_NOT_ALLOWED = CODE_201;
79      public static final int SLAVE_STATUS_NOTED               = CODE_202;
80      public static final int CLOSING_CONNECTION               = CODE_205;
81      public static final int GROUP_SELECTED                   = CODE_211;
82      public static final int ARTICLE_RETRIEVED_HEAD_AND_BODY_FOLLOW = CODE_220;
83      public static final int ARTICLE_RETRIEVED_HEAD_FOLLOWS = CODE_221;
84      public static final int ARTICLE_RETRIEVED_BODY_FOLLOWS = CODE_222;
85      public static final int
86        ARTICLE_RETRIEVED_REQUEST_TEXT_SEPARATELY = CODE_223;
87      public static final int ARTICLE_LIST_BY_MESSAGE_ID_FOLLOWS = CODE_230;
88      public static final int NEW_NEWSGROUP_LIST_FOLLOWS         = CODE_231;
89      public static final int ARTICLE_TRANSFERRED_OK             = CODE_235;
90      public static final int ARTICLE_POSTED_OK                  = CODE_240;
91      public static final int AUTHENTICATION_ACCEPTED            = CODE_281;
92      public static final int SEND_ARTICLE_TO_TRANSFER           = CODE_335;
93      public static final int SEND_ARTICLE_TO_POST               = CODE_340;
94      public static final int MORE_AUTH_INFO_REQUIRED            = CODE_381;
95      public static final int SERVICE_DISCONTINUED               = CODE_400;
96      public static final int NO_SUCH_NEWSGROUP                  = CODE_411;
97      public static final int AUTHENTICATION_REQUIRED            = CODE_408;
98      public static final int NO_NEWSGROUP_SELECTED              = CODE_412;
99      public static final int NO_CURRENT_ARTICLE_SELECTED        = CODE_420;
100     public static final int NO_NEXT_ARTICLE                    = CODE_421;
101     public static final int NO_PREVIOUS_ARTICLE                = CODE_422;
102     public static final int NO_SUCH_ARTICLE_NUMBER             = CODE_423;
103     public static final int NO_SUCH_ARTICLE_FOUND              = CODE_430;
104     public static final int ARTICLE_NOT_WANTED                 = CODE_435;
105     public static final int TRANSFER_FAILED                    = CODE_436;
106     public static final int ARTICLE_REJECTED                   = CODE_437;
107     public static final int POSTING_NOT_ALLOWED                = CODE_440;
108     public static final int POSTING_FAILED                     = CODE_441;
109     public static final int AUTHENTICATION_REJECTED            = CODE_482;
110     public static final int COMMAND_NOT_RECOGNIZED             = CODE_500;
111     public static final int COMMAND_SYNTAX_ERROR               = CODE_501;
112     public static final int PERMISSION_DENIED                  = CODE_502;
113     public static final int PROGRAM_FAULT                      = CODE_503;
114 
115     // Cannot be instantiated
116 
117     private NNTPReply()
118     {}
119 
120     /***
121      * Determine if a reply code is an informational response.  All
122      * codes beginning with a 1 are positive informational responses.
123      * Informational responses are used to provide human readable
124      * information such as help text.
125      * <p>
126      * @param reply  The reply code to test.
127      * @return True if a reply code is an informational response, false
128      *         if not.
129      ***/
130     public static boolean isInformational(int reply)
131     {
132         return (reply >= 100 && reply < 200);
133     }
134 
135     /***
136      * Determine if a reply code is a positive completion response.  All
137      * codes beginning with a 2 are positive completion responses.
138      * The NNTP server will send a positive completion response on the final
139      * successful completion of a command.
140      * <p>
141      * @param reply  The reply code to test.
142      * @return True if a reply code is a postive completion response, false
143      *         if not.
144      ***/
145     public static boolean isPositiveCompletion(int reply)
146     {
147         return (reply >= 200 && reply < 300);
148     }
149 
150     /***
151      * Determine if a reply code is a positive intermediate response.  All
152      * codes beginning with a 3 are positive intermediate responses.
153      * The NNTP server will send a positive intermediate response on the
154      * successful completion of one part of a multi-part command or
155      * sequence of commands.  For example, after a successful POST command,
156      * a positive intermediate response will be sent to indicate that the
157      * server is ready to receive the article to be posted.
158      * <p>
159      * @param reply  The reply code to test.
160      * @return True if a reply code is a postive intermediate response, false
161      *         if not.
162      ***/
163     public static boolean isPositiveIntermediate(int reply)
164     {
165         return (reply >= 300 && reply < 400);
166     }
167 
168     /***
169      * Determine if a reply code is a negative transient response.  All
170      * codes beginning with a 4 are negative transient responses.
171      * The NNTP server will send a negative transient response on the
172      * failure of a correctly formatted command that could not be performed
173      * for some reason.  For example, retrieving an article that does not
174      * exist will result in a negative transient response.
175      * <p>
176      * @param reply  The reply code to test.
177      * @return True if a reply code is a negative transient response, false
178      *         if not.
179      ***/
180     public static boolean isNegativeTransient(int reply)
181     {
182         return (reply >= 400 && reply < 500);
183     }
184 
185     /***
186      * Determine if a reply code is a negative permanent response.  All
187      * codes beginning with a 5 are negative permanent responses.
188      * The NNTP server will send a negative permanent response when
189      * it does not implement a command, a command is incorrectly formatted,
190      * or a serious program error occurs.
191      * <p>
192      * @param reply  The reply code to test.
193      * @return True if a reply code is a negative permanent response, false
194      *         if not.
195      ***/
196     public static boolean isNegativePermanent(int reply)
197     {
198         return (reply >= 500 && reply < 600);
199     }
200 
201 }
202 
203 /* Emacs configuration
204  * Local variables:        **
205  * mode:             java  **
206  * c-basic-offset:   4     **
207  * indent-tabs-mode: nil   **
208  * End:                    **
209  */