trunk/com/so/news/command/Command.java
author chris <chris@marvin>
Tue, 20 Jan 2009 10:21:03 +0100
changeset 0 f907866f0e4b
permissions -rw-r--r--
Initial import.
     1 /*
     2  *   StarOffice News Server
     3  *   see AUTHORS for the list of contributors
     4  *
     5  *   This program is free software: you can redistribute it and/or modify
     6  *   it under the terms of the GNU General Public License as published by
     7  *   the Free Software Foundation, either version 3 of the License, or
     8  *   (at your option) any later version.
     9  *
    10  *   This program is distributed in the hope that it will be useful,
    11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  *   GNU General Public License for more details.
    14  *
    15  *   You should have received a copy of the GNU General Public License
    16  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  */
    18 
    19 package com.so.news.command;
    20 
    21 import java.io.IOException;
    22 import java.util.List;
    23 import com.so.news.NNTPConnection;
    24 import com.so.news.storage.Article;
    25 import com.so.news.storage.Group;
    26 
    27 /**
    28  * Base class for all command handling classes.
    29  * @author Christian Lins
    30  * @author Dennis Schwerdel
    31  */
    32 public abstract class Command
    33 {
    34   protected NNTPConnection connection;
    35 
    36   public Command(NNTPConnection connection)
    37   {
    38     this.connection = connection;
    39   }
    40 
    41   protected static String NEWLINE = NNTPConnection.NEWLINE;
    42 
    43   protected List<String> readText() 
    44     throws IOException
    45   {
    46     return connection.readText();
    47   }
    48 
    49   protected String readTextLine() throws IOException
    50   {
    51     return connection.readTextLine();
    52   }
    53 
    54   protected void printStatus(int status, String text) throws IOException
    55   {
    56     connection.printStatus(status, text);
    57   }
    58 
    59   protected void printTextLine(CharSequence text) throws IOException
    60   {
    61     connection.printTextLine(text);
    62   }
    63 
    64   protected void printTextPart(CharSequence text) throws IOException
    65   {
    66     connection.printTextPart(text);
    67   }
    68   
    69   protected void printText(CharSequence text) throws IOException
    70   {
    71     connection.printText(text);
    72   }
    73 
    74   protected void println(CharSequence text) throws IOException
    75   {
    76     connection.println(text);
    77   }
    78 
    79   protected void flush() throws IOException
    80   {
    81     connection.flush();
    82   }
    83 
    84   protected Article getCurrentArticle()
    85   {
    86     return connection.getCurrentArticle();
    87   }
    88 
    89   protected Group getCurrentGroup()
    90   {
    91     return connection.getCurrentGroup();
    92   }
    93 
    94   protected void setCurrentArticle(Article current)
    95   {
    96     connection.setCurrentArticle(current);
    97   }
    98 
    99   protected void setCurrentGroup(Group current)
   100   {
   101     connection.setCurrentGroup(current);
   102   }
   103 
   104   public abstract boolean process(String[] command)
   105     throws Exception;
   106 }