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 the meaning of the codes, familiarity with RFC 977 is assumed. The mnemonic constant
22   * names are transcriptions from the code descriptions of RFC 977.
23   */
24  public final class NNTPReply {
25  
26      /** NNTP reply code {@value}. */
27      public static final int HELP_TEXT_FOLLOWS = 100;
28  
29      /** NNTP reply code {@value}. */
30      public static final int DEBUG_OUTPUT = 199;
31  
32      /** NNTP reply code {@value}. */
33      public static final int SERVER_READY_POSTING_ALLOWED = 200;
34  
35      /** NNTP reply code {@value}. */
36      public static final int SERVER_READY_POSTING_NOT_ALLOWED = 201;
37  
38      /** NNTP reply code {@value}. */
39      public static final int SLAVE_STATUS_NOTED = 202;
40  
41      /** NNTP reply code {@value}. */
42      public static final int CLOSING_CONNECTION = 205;
43  
44      /** NNTP reply code {@value}. */
45      public static final int GROUP_SELECTED = 211;
46  
47      /** NNTP reply code {@value}. */
48      public static final int ARTICLE_RETRIEVED_HEAD_AND_BODY_FOLLOW = 220;
49  
50      /** NNTP reply code {@value}. */
51      public static final int ARTICLE_RETRIEVED_HEAD_FOLLOWS = 221;
52  
53      /** NNTP reply code {@value}. */
54      public static final int ARTICLE_RETRIEVED_BODY_FOLLOWS = 222;
55  
56      /** NNTP reply code {@value}. */
57      public static final int ARTICLE_RETRIEVED_REQUEST_TEXT_SEPARATELY = 223;
58  
59      /** NNTP reply code {@value}. */
60      public static final int ARTICLE_LIST_BY_MESSAGE_ID_FOLLOWS = 230;
61  
62      /** NNTP reply code {@value}. */
63      public static final int NEW_NEWSGROUP_LIST_FOLLOWS = 231;
64  
65      /** NNTP reply code {@value}. */
66      public static final int ARTICLE_TRANSFERRED_OK = 235;
67  
68      /** NNTP reply code {@value}. */
69      public static final int ARTICLE_POSTED_OK = 240;
70  
71      /** NNTP reply code {@value}. */
72      public static final int AUTHENTICATION_ACCEPTED = 281;
73  
74      /** NNTP reply code {@value}. */
75      public static final int SEND_ARTICLE_TO_TRANSFER = 335;
76  
77      /** NNTP reply code {@value}. */
78      public static final int SEND_ARTICLE_TO_POST = 340;
79  
80      /** NNTP reply code {@value}. */
81      public static final int MORE_AUTH_INFO_REQUIRED = 381;
82  
83      /** NNTP reply code {@value}. */
84      public static final int SERVICE_DISCONTINUED = 400;
85  
86      /** NNTP reply code {@value}. */
87      public static final int NO_SUCH_NEWSGROUP = 411;
88  
89      /** NNTP reply code {@value}. */
90      public static final int NO_NEWSGROUP_SELECTED = 412;
91  
92      /** NNTP reply code {@value}. */
93      public static final int NO_CURRENT_ARTICLE_SELECTED = 420;
94  
95      /** NNTP reply code {@value}. */
96      public static final int NO_NEXT_ARTICLE = 421;
97  
98      /** NNTP reply code {@value}. */
99      public static final int NO_PREVIOUS_ARTICLE = 422;
100 
101     /** NNTP reply code {@value}. */
102     public static final int NO_SUCH_ARTICLE_NUMBER = 423;
103 
104     /** NNTP reply code {@value}. */
105     public static final int NO_SUCH_ARTICLE_FOUND = 430;
106 
107     /** NNTP reply code {@value}. */
108     public static final int ARTICLE_NOT_WANTED = 435;
109 
110     /** NNTP reply code {@value}. */
111     public static final int TRANSFER_FAILED = 436;
112 
113     /** NNTP reply code {@value}. */
114     public static final int ARTICLE_REJECTED = 437;
115 
116     /** NNTP reply code {@value}. */
117     public static final int POSTING_NOT_ALLOWED = 440;
118 
119     /** NNTP reply code {@value}. */
120     public static final int POSTING_FAILED = 441;
121 
122     /**
123      * NNTP reply code {@value}.
124      *
125      * @since 2.2 - corrected value to 480
126      */
127     public static final int AUTHENTICATION_REQUIRED = 480;
128 
129     /** NNTP reply code {@value}. */
130     public static final int AUTHENTICATION_REJECTED = 482;
131 
132     /** NNTP reply code {@value}. */
133     public static final int COMMAND_NOT_RECOGNIZED = 500;
134 
135     /** NNTP reply code {@value}. */
136     public static final int COMMAND_SYNTAX_ERROR = 501;
137 
138     /** NNTP reply code {@value}. */
139     public static final int PERMISSION_DENIED = 502;
140 
141     /** NNTP reply code {@value}. */
142     public static final int PROGRAM_FAULT = 503;
143 
144     /**
145      * Tests if a reply code is an informational response. All codes beginning with a 1 are positive informational responses. Informational responses are
146      * used to provide human-readable information such as help text.
147      *
148      * @param reply The reply code to test.
149      * @return True if a reply code is an informational response, false if not.
150      */
151     public static boolean isInformational(final int reply) {
152         return reply >= 100 && reply < 200;
153     }
154 
155     /**
156      * Tests if a reply code is a negative permanent response. All codes beginning with a 5 are negative permanent responses. The NNTP server will send a
157      * negative permanent response when it does not implement a command, a command is incorrectly formatted, or a serious program error occurs.
158      *
159      * @param reply The reply code to test.
160      * @return True if a reply code is a negative permanent response, false if not.
161      */
162     public static boolean isNegativePermanent(final int reply) {
163         return reply >= 500 && reply < 600;
164     }
165 
166     /**
167      * Tests if a reply code is a negative transient response. All codes beginning with a 4 are negative transient responses. The NNTP server will send a
168      * negative transient response on the failure of a correctly formatted command that could not be performed for some reason. For example, retrieving an
169      * article that does not exist will result in a negative transient response.
170      *
171      * @param reply The reply code to test.
172      * @return True if a reply code is a negative transient response, false if not.
173      */
174     public static boolean isNegativeTransient(final int reply) {
175         return reply >= 400 && reply < 500;
176     }
177 
178     /**
179      * Tests if a reply code is a positive completion response. All codes beginning with a 2 are positive completion responses. The NNTP server will send a
180      * positive completion response on the final successful completion of a command.
181      *
182      * @param reply The reply code to test.
183      * @return True if a reply code is a positive completion response, false if not.
184      */
185     public static boolean isPositiveCompletion(final int reply) {
186         return reply >= 200 && reply < 300;
187     }
188 
189     /**
190      * Tests if a reply code is a positive intermediate response. All codes beginning with a 3 are positive intermediate responses. The NNTP server will
191      * send a positive intermediate response on the successful completion of one part of a multipart command or sequence of commands. For example, after a
192      * successful POST command, a positive intermediate response will be sent to indicate that the server is ready to receive the article to be posted.
193      *
194      * @param reply The reply code to test.
195      * @return True if a reply code is a positive intermediate response, false if not.
196      */
197     public static boolean isPositiveIntermediate(final int reply) {
198         return reply >= 300 && reply < 400;
199     }
200 
201     private NNTPReply() {
202     }
203 
204 }