    001    /*
    002     * Licensed to the Apache Software Foundation (ASF) under one or more
    003     * contributor license agreements.  See the NOTICE file distributed with
    004     * this work for additional information regarding copyright ownership.
    005     * The ASF licenses this file to You under the Apache License, Version 2.0
    006     * (the "License"); you may not use this file except in compliance with
    007     * the License.  You may obtain a copy of the License at
    008     *
    009     *      http://www.apache.org/licenses/LICENSE-2.0
    010     *
    011     * Unless required by applicable law or agreed to in writing, software
    012     * distributed under the License is distributed on an "AS IS" BASIS,
    013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014     * See the License for the specific language governing permissions and
    015     * limitations under the License.
    016     */
    017
    018    package org.apache.commons.net.nntp;
    019
    020    /***
    021     * NNTPReply stores a set of constants for NNTP reply codes.  To interpret
    022     * the meaning of the codes, familiarity with RFC 977 is assumed.
    023     * The mnemonic constant names are transcriptions from the code descriptions
    024     * of RFC 977.  For those who think in terms of the actual reply code values,
    025     * a set of CODE_NUM constants are provided where NUM is the numerical value
    026     * of the code.
    027     * <p>
    028     * <p>
    029     * @author Daniel F. Savarese
    030     ***/
    031
    032    public final class NNTPReply
    033    {
    034
    035        // TODO - drop all these numeric constants?
    036        public static final int CODE_100 = 100;
    037        public static final int CODE_199 = 199;
    038        public static final int CODE_200 = 200;
    039        public static final int CODE_201 = 201;
    040        public static final int CODE_202 = 202;
    041        public static final int CODE_205 = 205;
    042        public static final int CODE_211 = 211;
    043        public static final int CODE_215 = 215;
    044        public static final int CODE_220 = 220;
    045        public static final int CODE_221 = 221;
    046        public static final int CODE_222 = 222;
    047        public static final int CODE_223 = 223;
    048        public static final int CODE_230 = 230;
    049        public static final int CODE_231 = 231;
    050        public static final int CODE_235 = 235;
    051        public static final int CODE_240 = 240;
    052        public static final int CODE_281 = 281;
    053        public static final int CODE_335 = 335;
    054        public static final int CODE_340 = 340;
    055        public static final int CODE_381 = 381;
    056        public static final int CODE_400 = 400;
    057        public static final int CODE_408 = 408; // Not actually needed; kept for API compatibility
    058        public static final int CODE_411 = 411;
    059        public static final int CODE_412 = 412;
    060        public static final int CODE_420 = 420;
    061        public static final int CODE_421 = 421;
    062        public static final int CODE_422 = 422;
    063        public static final int CODE_423 = 423;
    064        public static final int CODE_430 = 430;
    065        public static final int CODE_435 = 435;
    066        public static final int CODE_436 = 436;
    067        public static final int CODE_437 = 437;
    068        public static final int CODE_440 = 440;
    069        public static final int CODE_441 = 441;
    070        /** @since 2.2 */
    071        public static final int CODE_480 = 480;
    072        public static final int CODE_482 = 482;
    073        public static final int CODE_500 = 500;
    074        public static final int CODE_501 = 501;
    075        public static final int CODE_502 = 502;
    076        public static final int CODE_503 = 503;
    077
    078        public static final int HELP_TEXT_FOLLOWS                = CODE_100;
    079        public static final int DEBUG_OUTPUT                     = CODE_199;
    080        public static final int SERVER_READY_POSTING_ALLOWED     = CODE_200;
    081        public static final int SERVER_READY_POSTING_NOT_ALLOWED = CODE_201;
    082        public static final int SLAVE_STATUS_NOTED               = CODE_202;
    083        public static final int CLOSING_CONNECTION               = CODE_205;
    084        public static final int GROUP_SELECTED                   = CODE_211;
    085        public static final int ARTICLE_RETRIEVED_HEAD_AND_BODY_FOLLOW = CODE_220;
    086        public static final int ARTICLE_RETRIEVED_HEAD_FOLLOWS = CODE_221;
    087        public static final int ARTICLE_RETRIEVED_BODY_FOLLOWS = CODE_222;
    088        public static final int
    089          ARTICLE_RETRIEVED_REQUEST_TEXT_SEPARATELY = CODE_223;
    090        public static final int ARTICLE_LIST_BY_MESSAGE_ID_FOLLOWS = CODE_230;
    091        public static final int NEW_NEWSGROUP_LIST_FOLLOWS         = CODE_231;
    092        public static final int ARTICLE_TRANSFERRED_OK             = CODE_235;
    093        public static final int ARTICLE_POSTED_OK                  = CODE_240;
    094        public static final int AUTHENTICATION_ACCEPTED            = CODE_281;
    095        public static final int SEND_ARTICLE_TO_TRANSFER           = CODE_335;
    096        public static final int SEND_ARTICLE_TO_POST               = CODE_340;
    097        public static final int MORE_AUTH_INFO_REQUIRED            = CODE_381;
    098        public static final int SERVICE_DISCONTINUED               = CODE_400;
    099        public static final int NO_SUCH_NEWSGROUP                  = CODE_411;
    100        public static final int NO_NEWSGROUP_SELECTED              = CODE_412;
    101        public static final int NO_CURRENT_ARTICLE_SELECTED        = CODE_420;
    102        public static final int NO_NEXT_ARTICLE                    = CODE_421;
    103        public static final int NO_PREVIOUS_ARTICLE                = CODE_422;
    104        public static final int NO_SUCH_ARTICLE_NUMBER             = CODE_423;
    105        public static final int NO_SUCH_ARTICLE_FOUND              = CODE_430;
    106        public static final int ARTICLE_NOT_WANTED                 = CODE_435;
    107        public static final int TRANSFER_FAILED                    = CODE_436;
    108        public static final int ARTICLE_REJECTED                   = CODE_437;
    109        public static final int POSTING_NOT_ALLOWED                = CODE_440;
    110        public static final int POSTING_FAILED                     = CODE_441;
    111        /** @since 2.2 - corrected value to 480 */
    112        public static final int AUTHENTICATION_REQUIRED            = CODE_480;
    113        public static final int AUTHENTICATION_REJECTED            = CODE_482;
    114        public static final int COMMAND_NOT_RECOGNIZED             = CODE_500;
    115        public static final int COMMAND_SYNTAX_ERROR               = CODE_501;
    116        public static final int PERMISSION_DENIED                  = CODE_502;
    117        public static final int PROGRAM_FAULT                      = CODE_503;
    118
    119        // Cannot be instantiated
    120
    121        private NNTPReply()
    122        {}
    123
    124        /***
    125         * Determine if a reply code is an informational response.  All
    126         * codes beginning with a 1 are positive informational responses.
    127         * Informational responses are used to provide human readable
    128         * information such as help text.
    129         * <p>
    130         * @param reply  The reply code to test.
    131         * @return True if a reply code is an informational response, false
    132         *         if not.
    133         ***/
    134        public static boolean isInformational(int reply)
    135        {
    136            return (reply >= 100 && reply < 200);
    137        }
    138
    139        /***
    140         * Determine if a reply code is a positive completion response.  All
    141         * codes beginning with a 2 are positive completion responses.
    142         * The NNTP server will send a positive completion response on the final
    143         * successful completion of a command.
    144         * <p>
    145         * @param reply  The reply code to test.
    146         * @return True if a reply code is a postive completion response, false
    147         *         if not.
    148         ***/
    149        public static boolean isPositiveCompletion(int reply)
    150        {
    151            return (reply >= 200 && reply < 300);
    152        }
    153
    154        /***
    155         * Determine if a reply code is a positive intermediate response.  All
    156         * codes beginning with a 3 are positive intermediate responses.
    157         * The NNTP server will send a positive intermediate response on the
    158         * successful completion of one part of a multi-part command or
    159         * sequence of commands.  For example, after a successful POST command,
    160         * a positive intermediate response will be sent to indicate that the
    161         * server is ready to receive the article to be posted.
    162         * <p>
    163         * @param reply  The reply code to test.
    164         * @return True if a reply code is a postive intermediate response, false
    165         *         if not.
    166         ***/
    167        public static boolean isPositiveIntermediate(int reply)
    168        {
    169            return (reply >= 300 && reply < 400);
    170        }
    171
    172        /***
    173         * Determine if a reply code is a negative transient response.  All
    174         * codes beginning with a 4 are negative transient responses.
    175         * The NNTP server will send a negative transient response on the
    176         * failure of a correctly formatted command that could not be performed
    177         * for some reason.  For example, retrieving an article that does not
    178         * exist will result in a negative transient response.
    179         * <p>
    180         * @param reply  The reply code to test.
    181         * @return True if a reply code is a negative transient response, false
    182         *         if not.
    183         ***/
    184        public static boolean isNegativeTransient(int reply)
    185        {
    186            return (reply >= 400 && reply < 500);
    187        }
    188
    189        /***
    190         * Determine if a reply code is a negative permanent response.  All
    191         * codes beginning with a 5 are negative permanent responses.
    192         * The NNTP server will send a negative permanent response when
    193         * it does not implement a command, a command is incorrectly formatted,
    194         * or a serious program error occurs.
    195         * <p>
    196         * @param reply  The reply code to test.
    197         * @return True if a reply code is a negative permanent response, false
    198         *         if not.
    199         ***/
    200        public static boolean isNegativePermanent(int reply)
    201        {
    202            return (reply >= 500 && reply < 600);
    203        }
    204
    205    }
    206
    207    /* Emacs configuration
    208     * Local variables:        **
    209     * mode:             java  **
    210     * c-basic-offset:   4     **
    211     * indent-tabs-mode: nil   **
    212     * End:                    **
    213     */