    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
    018package org.apache.commons.net.nntp;
    019
    020/**
    021 * 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
    022 * names are transcriptions from the code descriptions of RFC 977.
    023 */
    024
    025public final class NNTPReply {
    026
    027    public static final int HELP_TEXT_FOLLOWS = 100;
    028    public static final int DEBUG_OUTPUT = 199;
    029    public static final int SERVER_READY_POSTING_ALLOWED = 200;
    030    public static final int SERVER_READY_POSTING_NOT_ALLOWED = 201;
    031    public static final int SLAVE_STATUS_NOTED = 202;
    032    public static final int CLOSING_CONNECTION = 205;
    033    public static final int GROUP_SELECTED = 211;
    034    public static final int ARTICLE_RETRIEVED_HEAD_AND_BODY_FOLLOW = 220;
    035    public static final int ARTICLE_RETRIEVED_HEAD_FOLLOWS = 221;
    036    public static final int ARTICLE_RETRIEVED_BODY_FOLLOWS = 222;
    037    public static final int ARTICLE_RETRIEVED_REQUEST_TEXT_SEPARATELY = 223;
    038    public static final int ARTICLE_LIST_BY_MESSAGE_ID_FOLLOWS = 230;
    039    public static final int NEW_NEWSGROUP_LIST_FOLLOWS = 231;
    040    public static final int ARTICLE_TRANSFERRED_OK = 235;
    041    public static final int ARTICLE_POSTED_OK = 240;
    042    public static final int AUTHENTICATION_ACCEPTED = 281;
    043    public static final int SEND_ARTICLE_TO_TRANSFER = 335;
    044    public static final int SEND_ARTICLE_TO_POST = 340;
    045    public static final int MORE_AUTH_INFO_REQUIRED = 381;
    046    public static final int SERVICE_DISCONTINUED = 400;
    047    public static final int NO_SUCH_NEWSGROUP = 411;
    048    public static final int NO_NEWSGROUP_SELECTED = 412;
    049    public static final int NO_CURRENT_ARTICLE_SELECTED = 420;
    050    public static final int NO_NEXT_ARTICLE = 421;
    051    public static final int NO_PREVIOUS_ARTICLE = 422;
    052    public static final int NO_SUCH_ARTICLE_NUMBER = 423;
    053    public static final int NO_SUCH_ARTICLE_FOUND = 430;
    054    public static final int ARTICLE_NOT_WANTED = 435;
    055    public static final int TRANSFER_FAILED = 436;
    056    public static final int ARTICLE_REJECTED = 437;
    057    public static final int POSTING_NOT_ALLOWED = 440;
    058    public static final int POSTING_FAILED = 441;
    059    /** @since 2.2 - corrected value to 480 */
    060    public static final int AUTHENTICATION_REQUIRED = 480;
    061    public static final int AUTHENTICATION_REJECTED = 482;
    062    public static final int COMMAND_NOT_RECOGNIZED = 500;
    063    public static final int COMMAND_SYNTAX_ERROR = 501;
    064    public static final int PERMISSION_DENIED = 502;
    065    public static final int PROGRAM_FAULT = 503;
    066
    067    // Cannot be instantiated
    068
    069    /**
    070     * Determine if a reply code is an informational response. All codes beginning with a 1 are positive informational responses. Informational responses are
    071     * used to provide human readable information such as help text.
    072     * <p>
    073     *
    074     * @param reply The reply code to test.
    075     * @return True if a reply code is an informational response, false if not.
    076     */
    077    public static boolean isInformational(final int reply) {
    078        return reply >= 100 && reply < 200;
    079    }
    080
    081    /**
    082     * Determine 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
    083     * negative permanent response when it does not implement a command, a command is incorrectly formatted, or a serious program error occurs.
    084     * <p>
    085     *
    086     * @param reply The reply code to test.
    087     * @return True if a reply code is a negative permanent response, false if not.
    088     */
    089    public static boolean isNegativePermanent(final int reply) {
    090        return reply >= 500 && reply < 600;
    091    }
    092
    093    /**
    094     * Determine 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
    095     * negative transient response on the failure of a correctly formatted command that could not be performed for some reason. For example, retrieving an
    096     * article that does not exist will result in a negative transient response.
    097     * <p>
    098     *
    099     * @param reply The reply code to test.
    100     * @return True if a reply code is a negative transient response, false if not.
    101     */
    102    public static boolean isNegativeTransient(final int reply) {
    103        return reply >= 400 && reply < 500;
    104    }
    105
    106    /**
    107     * Determine 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
    108     * positive completion response on the final successful completion of a command.
    109     * <p>
    110     *
    111     * @param reply The reply code to test.
    112     * @return True if a reply code is a positive completion response, false if not.
    113     */
    114    public static boolean isPositiveCompletion(final int reply) {
    115        return reply >= 200 && reply < 300;
    116    }
    117
    118    /**
    119     * Determine if a reply code is a positive intermediate response. All codes beginning with a 3 are positive intermediate responses. The NNTP server will
    120     * send a positive intermediate response on the successful completion of one part of a multi-part command or sequence of commands. For example, after a
    121     * successful POST command, a positive intermediate response will be sent to indicate that the server is ready to receive the article to be posted.
    122     * <p>
    123     *
    124     * @param reply The reply code to test.
    125     * @return True if a reply code is a positive intermediate response, false if not.
    126     */
    127    public static boolean isPositiveIntermediate(final int reply) {
    128        return reply >= 300 && reply < 400;
    129    }
    130
    131    private NNTPReply() {
    132    }
    133
    134}