edu.vt.middleware.crypt
Class AbstractCli

java.lang.Object
  extended by edu.vt.middleware.crypt.AbstractCli
Direct Known Subclasses:
AbstractEncryptionCli, DigestCli, KeyStoreCli, SignatureCli

public abstract class AbstractCli
extends Object

Abstract base class for all CLI handlers.

Version:
$Revision: 2745 $
Author:
Middleware Services

Field Summary
protected static String BASE_64_ENCODING
          Name of encoding option value for Base-64 encoding.
protected static String HEX_ENCODING
          Name of encoding option value for hexadecimal encoding.
protected static String OPT_EXAMPLE
          Example option.
protected static String OPT_INFILE
          Input file option.
protected  org.apache.commons.cli.Options options
          Command line options.
protected static String PEM_SUFFIX
          Suffix of files using PEM encoding.
 
Constructor Summary
AbstractCli()
           
 
Method Summary
protected  void closeStream(InputStream in)
          Attempts to close the given input stream.
protected  void closeStream(OutputStream out)
          Attempts to close the given output stream.
protected abstract  void dispatch(org.apache.commons.cli.CommandLine line)
          Dispatch command line data to the handler that can perform the operation requested on the command line.
protected abstract  String getCommandName()
          Gets the name of the command for which this class provides a CLI interface.
protected  InputStream getInputStream(org.apache.commons.cli.CommandLine line)
          Get an input stream containing data to be signed or verified based on CLI arguments.
protected  InputStream getInputStream(org.apache.commons.cli.CommandLine line, String opt)
          Get an input stream containing data to be signed or verified based on CLI arguments.
protected  void initOptions()
          Initialize CLI options.
 void performAction(String[] args)
          Parses command line options and invokes the proper handler to perform the requested action, or the default action if no action is specified.
protected  void printExamples()
          Prints CLI usage examples.
protected  void printHelp()
          Prints CLI help text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPT_INFILE

protected static final String OPT_INFILE
Input file option.

See Also:
Constant Field Values

OPT_EXAMPLE

protected static final String OPT_EXAMPLE
Example option.

See Also:
Constant Field Values

BASE_64_ENCODING

protected static final String BASE_64_ENCODING
Name of encoding option value for Base-64 encoding.

See Also:
Constant Field Values

HEX_ENCODING

protected static final String HEX_ENCODING
Name of encoding option value for hexadecimal encoding.

See Also:
Constant Field Values

PEM_SUFFIX

protected static final String PEM_SUFFIX
Suffix of files using PEM encoding.

See Also:
Constant Field Values

options

protected final org.apache.commons.cli.Options options
Command line options.

Constructor Detail

AbstractCli

public AbstractCli()
Method Detail

performAction

public final void performAction(String[] args)
Parses command line options and invokes the proper handler to perform the requested action, or the default action if no action is specified.

Parameters:
args - Command line arguments.

initOptions

protected void initOptions()
Initialize CLI options.


getCommandName

protected abstract String getCommandName()
Gets the name of the command for which this class provides a CLI interface.

Returns:
Name of CLI command.

dispatch

protected abstract void dispatch(org.apache.commons.cli.CommandLine line)
                          throws Exception
Dispatch command line data to the handler that can perform the operation requested on the command line.

Parameters:
line - Parsed command line arguments container.
Throws:
Exception - On errors thrown by handler.

printHelp

protected void printHelp()
Prints CLI help text.


printExamples

protected void printExamples()
Prints CLI usage examples.


getInputStream

protected InputStream getInputStream(org.apache.commons.cli.CommandLine line)
                              throws IOException
Get an input stream containing data to be signed or verified based on CLI arguments.

Parameters:
line - Parsed command line arguments container.
Returns:
Input stream.
Throws:
IOException - On stream creation errors.

getInputStream

protected InputStream getInputStream(org.apache.commons.cli.CommandLine line,
                                     String opt)
                              throws IOException
Get an input stream containing data to be signed or verified based on CLI arguments.

Parameters:
line - Parsed command line arguments container.
opt - Name of command line option used to specify file input stream.
Returns:
Input stream.
Throws:
IOException - On stream creation errors.

closeStream

protected void closeStream(InputStream in)
Attempts to close the given input stream.

Parameters:
in - Input stream to close.

closeStream

protected void closeStream(OutputStream out)
Attempts to close the given output stream.

Parameters:
out - output stream to close.


Copyright © 2003-2013 Virginia Tech. All Rights Reserved.