package ruleset.plugin; import java.io.*; import java.util.*; import pds.util.*; import pds.ruleset.*; /** * Multi-function time utility. This application is designed to function * as a plug-in the the PPI Rulesets. This plug-in supports a variety of time * related functions including the conversion between different time formats. *

* The general form of usage is:
*

* time service name [parameters...] *
* where service is the name of the service to run and * name is the variable name to use in the rule that is output * with the results of the requested service and parameters is one * or more parameters required by the service. *

* Supported services are:
*

* Convert: Convert from one time format to another.
* Now: Return the current time. *
* See the descriptions for each service for required parameters. *

* All time formats are specified using the format specified in {@link PPITime} * and also supports formats specified in {@link Date}. *

* Results are returned as a ruleset assignment and are in the form: * *

* $<name> = value *
* * @see Date * @author Todd King * @author IGPP/UCLA/PDS * @version 1.0, 05/21/03 * @since 1.0 */ public class Time { /** * Creates an instance. */ public Time() { } /** Entry point for the application */ public static void main(String[] args) { boolean good = false; if(args.length < 1) { PPIRuleset.showRule(PPIAction.MESSAGE, "time plugin. Proper usage: time service {...}"); PPIRuleset.showRule(PPIAction.MESSAGE, "Available services are:"); PPIRuleset.showRule(PPIAction.MESSAGE, "\tConvert: Convert time in one format into another."); PPIRuleset.showRule(PPIAction.MESSAGE, "\tNow: Output the current time a specified format."); return; } if(args[0].compareToIgnoreCase("Convert") == 0) { good = true; Convert(args); } if(args[0].compareToIgnoreCase("Now") == 0) { good = true; Now(args); } if(!good) System.out.println(""); } /** * Convert time from one format into another. * Proper use:
* * Convert name time format output * *
* where:
*
*
Parameter
the name of the variable to assign the output to.
*
time
the string with the time value to convert.
*
format
the name of the standard time format or a string containing the * the specification of the time format time is in. See {@link PPITime} * for details of how to specify a time format.
*
output
the name of the standard time format or a string containing the * the specification of the time format to convert time * into and to assign to name. See {@link PPITime} * for details of how to specify a time format.
*
* * @since 1.0 */ public static void Convert(String[] args) { String parameter = PPIOption.find(args, "PARAMETER", null, 1); String timeValue = PPIOption.find(args, "TIME", null, 1); String formatArg = PPIOption.find(args, "FORMAT", null, 1); String outputArg = PPIOption.find(args, "OUTPUT", null, 1); PPITime time = new PPITime(); String format; String output; if(parameter == null || timeValue == null || formatArg == null || outputArg == null) { PPIRuleset.showRule(PPIAction.MESSAGE, "'time convert' not called with the proper arguments."); PPIRuleset.showRule(PPIAction.MESSAGE, " proper usage 'time convert parameter time format output'."); return; } format = time.findSpec(formatArg); output = time.findSpec(outputArg); time.convert(format, timeValue); PPIRuleset.showRule(PPIAction.ASSIGN, parameter, time.format(output)); } /** * Determine the current time and assign it to a variable. * Proper use:
* * Now name output * *
* where:
*
*
parameter
the name of the variable to assign the output to.
*
output
the name of the standard time format or a string containing the * the specification of the time format time is in. See {@link PPITime} * for details of how to specify a time format.
*
* * @since 1.0 */ public static void Now(String[] args) { String parameter = PPIOption.find(args, "PARAMETER", null, 1); String outputArg = PPIOption.find(args, "OUTPUT", null, 1); PPITime time = new PPITime(); String format; if(parameter == null || outputArg == null) { PPIRuleset.showRule(PPIAction.MESSAGE, "'time now' not called with the proper arguments.>"); PPIRuleset.showRule(PPIAction.MESSAGE, " proper usage 'time now parameter output'."); return; } time.now(); format = time.findSpec(outputArg); PPIRuleset.showRule(PPIAction.ASSIGN, parameter, time.format(format)); } }