Package org.daisy.cli
Class AbstractUI
- java.lang.Object
-
- org.daisy.cli.AbstractUI
-
- Direct Known Subclasses:
BasicUI
public abstract class AbstractUI extends java.lang.Object
Provides an abstract base for command line UI's.- Author:
- Joel HÃ¥kansson
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractUI.Argument
Provides the information needed by an application argument.static class
AbstractUI.Definition
Provides a definition, that is a name and a descriptionstatic class
AbstractUI.ExitCode
Provides exit codes to be used by implementing classes.static class
AbstractUI.OptionalArgument
Provides the information needed by an optional argument.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ARG_PREFIX
Prefix used for required arguments in the arguments map
-
Constructor Summary
Constructors Constructor Description AbstractUI()
Creates a new AbstractUI using the default key/value delimiter '=' and the default optional argument prefix '-'
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
displayHelp(java.io.PrintStream ps)
Displays a help text for the UI based on the implementation of the methods getName, getOptionalArguments and getRequiredArguments.static void
exitWithCode(AbstractUI.ExitCode e)
static void
exitWithCode(AbstractUI.ExitCode e, java.lang.String message)
void
expandShortForm(java.util.Map<java.lang.String,java.lang.String> map, java.lang.String key, ShortFormResolver resolver)
Expands the short form of the value with the given key in the provided map using the specified resolver.java.util.List<AbstractUI.Definition>
getDefinitionList(FactoryCatalog<? extends Factory> catalog, ShortFormResolver resolver)
Creates a list of definitions based on the contents of the supplied FactoryCatalog.abstract java.lang.String
getName()
Gets the name for the UIjava.util.Map<java.lang.String,java.lang.String>
getOptional(java.lang.String[] args)
abstract java.util.List<AbstractUI.OptionalArgument>
getOptionalArguments()
Gets optional argumentsjava.util.List<java.lang.String>
getRequired(java.lang.String[] args)
abstract java.util.List<AbstractUI.Argument>
getRequiredArguments()
Gets required argumentsvoid
setKeyValueDelimiter(java.lang.String value)
Sets the delimiter to use between key and value in the argument strings passed to the UI.void
setOptionalArgumentPrefix(java.lang.String value)
Sets the optional argument prefix to use in argument strings passed to the UI.java.util.Map<java.lang.String,java.lang.String>
toMap(java.lang.String[] args)
Converts a string based definition of UI arguments, typically passed by the main method, into a key-value map as described by displayHelp
-
-
-
Field Detail
-
ARG_PREFIX
public static final java.lang.String ARG_PREFIX
Prefix used for required arguments in the arguments map- See Also:
- Constant Field Values
-
-
Method Detail
-
expandShortForm
public void expandShortForm(java.util.Map<java.lang.String,java.lang.String> map, java.lang.String key, ShortFormResolver resolver)
Expands the short form of the value with the given key in the provided map using the specified resolver.- Parameters:
map
-key
-resolver
-
-
getDefinitionList
public java.util.List<AbstractUI.Definition> getDefinitionList(FactoryCatalog<? extends Factory> catalog, ShortFormResolver resolver)
Creates a list of definitions based on the contents of the supplied FactoryCatalog.- Parameters:
catalog
- the catalog to create definitions forresolver
-- Returns:
- returns a list of definitions
-
setKeyValueDelimiter
public void setKeyValueDelimiter(java.lang.String value)
Sets the delimiter to use between key and value in the argument strings passed to the UI.- Parameters:
value
- the delimiter to use
-
setOptionalArgumentPrefix
public void setOptionalArgumentPrefix(java.lang.String value)
Sets the optional argument prefix to use in argument strings passed to the UI.- Parameters:
value
- the prefix to use
-
getName
public abstract java.lang.String getName()
Gets the name for the UI- Returns:
- returns the UI name
-
getRequiredArguments
public abstract java.util.List<AbstractUI.Argument> getRequiredArguments()
Gets required arguments- Returns:
- returns a list of required arguments that can be passed to the UI on startup
-
getOptionalArguments
public abstract java.util.List<AbstractUI.OptionalArgument> getOptionalArguments()
Gets optional arguments- Returns:
- returns a list of optional arguments that can be passed to the UI on startup
-
toMap
public java.util.Map<java.lang.String,java.lang.String> toMap(java.lang.String[] args)
Converts a string based definition of UI arguments, typically passed by the main method, into a key-value map as described by displayHelp- Parameters:
args
- the arguments passed to the application- Returns:
- returns a map of application arguments
-
getOptional
public java.util.Map<java.lang.String,java.lang.String> getOptional(java.lang.String[] args)
-
getRequired
public java.util.List<java.lang.String> getRequired(java.lang.String[] args)
-
exitWithCode
public static void exitWithCode(AbstractUI.ExitCode e)
-
exitWithCode
public static void exitWithCode(AbstractUI.ExitCode e, java.lang.String message)
-
displayHelp
public void displayHelp(java.io.PrintStream ps)
Displays a help text for the UI based on the implementation of the methods getName, getOptionalArguments and getRequiredArguments.- Parameters:
ps
- The print stream to use, typically System.out
-
-