Class MCRCommandLineInterface

java.lang.Object
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.
Author:
Frank Lützenkirchen, Detlev Degenhardt, Jens Kupferschmidt, Thomas Scheffler (yagee)
See Also:
  • Field Details

    • commandQueue

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

      protected static Vector<String> failedCommands
  • Constructor Details

    • MCRCommandLineInterface

      public MCRCommandLineInterface()
  • Method Details

    • 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
    • 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
    • expandCommand

      public static String expandCommand(String command)
      Expands variables in a command. Replaces any variables in form ${propertyName} to the value defined by MCRConfiguration2.getString(String). If the property is not defined no variable replacement takes place.
      Parameters:
      command - a CLI command that should be expanded
      Returns:
      expanded command
    • 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
    • getURI

      public static void getURI(String uri, String file) throws Exception
      Reads XML content from URIResolver and sends output to a local file.
      Throws:
      Exception
    • readCommandsFile

      public static List<String> readCommandsFile(String file) throws IOException
      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
    • readCommandsRessource

      public static List<String> readCommandsRessource(String resource) throws IOException
      Throws:
      IOException
    • executeShellCommand

      public static void executeShellCommand(String command) throws Exception
      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
      Exception
    • whoami

      public static void whoami()
      Prints out the current user.
    • cancelOnError

      public static void cancelOnError()
    • skipOnError

      public static void skipOnError()
    • exit

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