org.mycore.frontend.cli
Class MCRCommandLineInterface

java.lang.Object
  extended by org.mycore.frontend.cli.MCRCommandLineInterface

public class MCRCommandLineInterface
extends Object

The main class implementing the MyCoRe command line interface. With the command line interface, you can import, export, update and delete documents and other data from/to the filesystem. Metadata is imported from and exported to XML files. The command line interface is for administrative purposes and to be used on the server side. It implements an interactive command prompt and understands a set of commands. Each command is an instance of the class MCRCommand.

Version:
$Revision: 14364 $ $Date: 2008-11-07 17:29:41 +0100 (Fr, 07 Nov 2008) $
Author:
Frank Lützenkirchen, Detlev Degenhardt, Jens Kupferschmidt, Thomas Scheffler (yagee)
See Also:
MCRCommand

Field Summary
protected static ConcurrentLinkedQueue<Number> benchList
           
protected static Vector<String> commandQueue
          A queue of commands waiting to be executed
protected static BufferedReader console
          The standard input console where the user enters commands
protected static Vector<String> failedCommands
           
protected static ArrayList<MCRCommand> knownCommands
          The array holding all known commands
(package private) static Logger logger
          The Logger
protected static HashMap<String,Integer> numInvocations
          Stores total number of executions for each command
protected static HashMap<String,Long> timeNeeded
          Stores total time needed for all executions of the given command
 
Constructor Summary
MCRCommandLineInterface()
           
 
Method Summary
static void addMillis(long l)
           
static void cancelOnError()
           
static void changeToUser(String user, String password)
          This command changes the user of the session context to a new user.
static void clearMillis()
           
static void executeShellCommand(String command)
          Executes simple shell commands from inside the command line interface and shows their output.
static void exit()
          Exits the command line interface.
protected static void handleFailedCommands()
           
protected static void initCommands()
          Reads command definitions from a configuration file and builds the MCRCommand instances
static void listKnownCommands()
          Shows a list of commands understood by the command line interface and shows their input syntax.
static void login(String user)
          This command changes the user of the session context to a new user.
static void main(String[] args)
          The main method that either shows up an interactive command prompt or reads a file containing a list of commands to be processed
protected static void processCommand(String command)
          Processes a command entered by searching a matching command in the list of known commands and executing its method.
protected static String readCommandFromPrompt()
          Shows up a command prompt.
static List<String> readCommandsFile(String file)
          Reads a file containing a list of commands to be executed and adds them to the commands queue for processing.
protected static void saveFailedCommand(String lastCommand)
           
static void saveMillis(String fileBaseName)
           
protected static void saveQueue(String lastCommand)
           
static void show(String fname)
          Show contents of a local text file, including line numbers.
static void showCommandsHelp(String com)
          Shows the help text of one or more commands.
static void showCommandStatistics()
          Shows statistics on number of invocations and time needed for each command successfully executed.
protected static void showException(Throwable ex)
          Shows details about an exception that occured during command processing
protected static void showOutput(InputStream in)
          Catches the output read from an input stream and prints it line by line on standard out.
static void skipOnError()
           
static void whoami()
          The method print the current user.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

static Logger logger
The Logger


knownCommands

protected static ArrayList<MCRCommand> knownCommands
The array holding all known commands


commandQueue

protected static Vector<String> commandQueue
A queue of commands waiting to be executed


failedCommands

protected static Vector<String> failedCommands

console

protected static BufferedReader console
The standard input console where the user enters commands


benchList

protected static ConcurrentLinkedQueue<Number> benchList

timeNeeded

protected static HashMap<String,Long> timeNeeded
Stores total time needed for all executions of the given command


numInvocations

protected static HashMap<String,Integer> numInvocations
Stores total number of executions for each command

Constructor Detail

MCRCommandLineInterface

public MCRCommandLineInterface()
Method Detail

initCommands

protected static void initCommands()
Reads command definitions from a configuration file and builds the MCRCommand instances


main

public static void main(String[] args)
The main method that either shows up an interactive command prompt or reads a file containing a list of commands to be processed


readCommandFromPrompt

protected static String readCommandFromPrompt()
Shows up a command prompt.

Returns:
The command entered by the user at stdin

processCommand

protected static void processCommand(String command)
Processes a command entered by searching a matching command in the list of known commands and executing its method.

Parameters:
command - The command string to be processed

showCommandStatistics

public static void showCommandStatistics()
Shows statistics on number of invocations and time needed for each command successfully executed.


saveQueue

protected static void saveQueue(String lastCommand)

saveFailedCommand

protected static void saveFailedCommand(String lastCommand)

handleFailedCommands

protected static void handleFailedCommands()

show

public static void show(String fname)
                 throws Exception
Show contents of a local text file, including line numbers.

Parameters:
fname - the filename
Throws:
Exception

showException

protected static void showException(Throwable ex)
Shows details about an exception that occured during command processing

Parameters:
ex - The exception that was catched while processing a command

readCommandsFile

public static List<String> readCommandsFile(String file)
                                     throws IOException,
                                            FileNotFoundException
Reads a file containing a list of commands to be executed and adds them to the commands queue for processing. This method implements the "process ..." command.

Parameters:
file - The file holding the commands to be processed
Throws:
IOException - when the file could not be read
FileNotFoundException - when the file was not found

listKnownCommands

public static void listKnownCommands()
Shows a list of commands understood by the command line interface and shows their input syntax. This method implements the "help" command


showCommandsHelp

public static void showCommandsHelp(String com)
Shows the help text of one or more commands.

Parameters:
com - the command

executeShellCommand

public static void executeShellCommand(String command)
                                throws IOException,
                                       SecurityException
Executes simple shell commands from inside the command line interface and shows their output. This method implements commands entered beginning with exclamation mark, like "! ls -l /temp"

Parameters:
command - the shell command to be executed
Throws:
IOException - when an IO error occured while catching the output returned by the command
SecurityException - when the command could not be executed for security reasons

whoami

public static void whoami()
The method print the current user.


changeToUser

public static void changeToUser(String user,
                                String password)
This command changes the user of the session context to a new user.

Parameters:
user - the new user ID
password - the password of the new user

login

public static void login(String user)
This command changes the user of the session context to a new user.

Parameters:
user - the new user ID

showOutput

protected static void showOutput(InputStream in)
                          throws IOException
Catches the output read from an input stream and prints it line by line on standard out. This is used to catch the stdout and stderr stream output when executing an external shell command.

Throws:
IOException

cancelOnError

public static void cancelOnError()

skipOnError

public static void skipOnError()

addMillis

public static void addMillis(long l)

clearMillis

public static void clearMillis()

saveMillis

public static void saveMillis(String fileBaseName)
                       throws IOException
Throws:
IOException

exit

public static void exit()
Exits the command line interface. This method implements the "exit" and "quit" commands.