Package org.mycore.frontend.cli
Class MCRCommandLineInterface
java.lang.Object
org.mycore.frontend.cli.MCRCommandLineInterface
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 Summary
Modifier and TypeFieldDescriptionA queue of commands waiting to be executed -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
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.static String
expandCommand
(String command) Expands variables in a command.static void
Reads XML content from URIResolver and sends output to a local file.protected static void
static void
The main method that either shows up an interactive command prompt or reads a file containing a list of commands to be processedprotected static void
processCommand
(String command) Processes a command entered by searching a matching command in the list of known commands and executing its method.readCommandsFile
(String file) Reads a file containing a list of commands to be executed and adds them to the commands queue for processing.readCommandsRessource
(String resource) protected static void
saveFailedCommand
(String lastCommand) protected static void
static void
Show contents of a local text file, including line numbers.static void
static void
whoami()
Prints out the current user.
-
Field Details
-
commandQueue
A queue of commands waiting to be executed -
failedCommands
-
-
Constructor Details
-
MCRCommandLineInterface
public MCRCommandLineInterface()
-
-
Method Details
-
main
The main method that either shows up an interactive command prompt or reads a file containing a list of commands to be processed -
processCommand
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
Expands variables in a command. Replaces any variables in form ${propertyName} to the value defined byMCRConfiguration2.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
-
saveFailedCommand
-
handleFailedCommands
protected static void handleFailedCommands() -
show
Show contents of a local text file, including line numbers.- Parameters:
fname
- the filename- Throws:
Exception
-
getURI
Reads XML content from URIResolver and sends output to a local file.- Throws:
Exception
-
readCommandsFile
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 readFileNotFoundException
- when the file was not found
-
readCommandsRessource
- Throws:
IOException
-
executeShellCommand
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 commandSecurityException
- when the command could not be executed for security reasonsException
-
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.
-