|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpds.ruleset.PPIRuleset
public class PPIRuleset
PPIRuleset is a class that contains methods for parsing and running rulesets and generating output which defined by the ruleset. A ruleset can be defined in a file or be generated by external applications. Templates are used to determine the form and structure of any output generated.
Field Summary | |
---|---|
boolean |
mAbort
A flag indicating whether the processing should end |
java.util.ArrayList |
mActionList
The list of elements in the label |
java.util.ArrayList |
mGlobalList
The list of global options which can be preserved and passed by the calling application. |
int |
mLineCount
Tracks which line in a file (or list) is currently being processed |
(package private) pds.util.PPIOption |
mOption
Internal map of names to IDs |
java.util.ArrayList |
mOptionList
The list of options defined during the execution of a rule set |
static javax.servlet.jsp.JspWriter |
mOut
Output destination. |
java.lang.String |
mSourceName
The name of the ruleset source |
java.lang.String |
mTemplateFile
The pathname for a text file (non-label) template |
(package private) pds.label.PDSLabel |
mTemplateLabel
The place where the label template is stored once loaded |
java.util.ArrayList |
mVariableList
The list of variables defined during the execution of a rule set |
boolean |
mWriteOutput
A flag indicating whether output should be written |
Constructor Summary | |
---|---|
PPIRuleset()
Creates an instance of a Ruleset |
Method Summary | |
---|---|
java.lang.String |
argFirst(java.lang.String buffer)
Extract the first argument in the string. |
java.util.ArrayList |
argSplit(java.lang.String buffer,
boolean onlyWhitespace)
Split a string into one or more substrings by parsing on whitespace and treating "!" and "=" as individual arguments. |
boolean |
convertYesNo(java.lang.String value)
Converts a string to a boolean state. |
void |
dump(boolean doAction)
Prints out the current rule set in tokenized form. |
void |
dumpList(java.lang.String title,
java.util.ArrayList list)
Print out all items in a list. |
boolean |
evalCondition(java.util.ArrayList stack)
Evaluate a condition that is coded into a array. |
char |
evalToken(java.lang.String text)
Examines a string and returns a token representing the contents. |
boolean |
findAndSet(java.util.ArrayList list,
pds.util.PPIVariable variable)
Finds a variable in the variable list and set its value. |
boolean |
findAndSet(java.util.ArrayList list,
java.lang.String name,
java.lang.String value)
Finds an item in an array list and set its value. |
boolean |
findAndSet(java.util.ArrayList list,
java.lang.String name,
java.lang.String value,
boolean resolve)
Finds an item in an array list and set its value. |
boolean |
findAndSet(pds.util.PPIVariable variable)
Finds a variable in the variable list and set its value. |
boolean |
findAndSet(java.lang.String name,
java.lang.String value)
Finds an item in an array list and set its value. |
boolean |
findAndSet(java.lang.String name,
java.lang.String value,
boolean resolve)
Finds an item in an array list and set its value. |
boolean |
getBooleanValue(java.util.ArrayList list,
java.lang.String name)
Finds an item in a variable list and returns its value as an boolean. |
java.lang.String |
getExtension(java.lang.String name)
Extracts the extension from a file name and returns the extension in uppercase. |
int |
getIntValue(java.util.ArrayList list,
java.lang.String name)
Finds an item in a variable list and returns its value as an integer. |
java.lang.String |
getValue(java.util.ArrayList list,
java.lang.String name,
boolean blank)
Finds a variable in the variable list and returns its value. |
java.lang.String |
getValue(java.lang.String name)
Finds a variable in the variable list and returns its value. |
boolean |
isExtension(java.lang.String name,
java.lang.String extension)
Determines if the extension of a file name matches a given string. |
static void |
main(java.lang.String[] args)
Loads a rule set and processes one or more files. |
java.lang.String |
makeRegex(java.lang.String pattern)
Converts a string to a regular expression pattern. |
static java.lang.String |
makeRule(int type,
java.lang.String arg1,
java.lang.String arg2)
Creates a syntactically correct rule with the parameters passed. |
void |
mergeList(java.util.ArrayList dest,
java.util.ArrayList list)
Set variable list to match a passed list. |
void |
output()
Writes the template to the output files. |
boolean |
parse(java.lang.String pathName)
Parses a file containing a ruleset into its constitute elments. |
boolean |
parseLine(java.lang.String buffer)
Parses a string containing a single ruleset into its constitute elments. |
java.lang.String |
readLine(java.io.BufferedReader stream)
Parses the next line from a BufferedStream stream. |
java.lang.String |
replaceVariable(java.lang.String buffer)
Searches the passed string for variables and replaces each variable with its current value. |
java.lang.String |
replaceVariable(java.lang.String buffer,
boolean plain)
Searches the passed string for variables and replaces each variable with its current value. |
void |
reset()
Clear all variables, rules and states in the ruleset. |
boolean |
run(java.lang.String pathname)
Run the current rule set. |
boolean |
runRuleset(java.lang.String ruleFile,
java.lang.String pathName)
Runs a ruleset on a single file. |
void |
setOption(java.lang.String name,
java.lang.String value)
Sets the value of an option. |
void |
setOutput(javax.servlet.jsp.JspWriter out)
Sets the writer used to output messages. |
static void |
show(java.lang.String message)
Prints text to the display. |
void |
showMessage(boolean location,
java.lang.String message)
Prints and error message to the display. |
static void |
showRule(int type)
Prints text to the display. |
static void |
showRule(int type,
java.lang.String arg1)
Prints text to the display. |
static void |
showRule(int type,
java.lang.String arg1,
double arg2)
Prints text to the display. |
static void |
showRule(int type,
java.lang.String arg1,
int arg2)
Prints text to the display. |
static void |
showRule(int type,
java.lang.String arg1,
java.lang.String arg2)
Prints text to the display. |
int |
skipBlock(int start,
int type)
Skips a block of code. |
static java.lang.String |
unquote(java.lang.String buffer)
Removes quotes from a string if the string starts with and ends with a quote character ("). |
boolean |
update()
Update the current template by replacing all variables with the defined values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public java.util.ArrayList mActionList
public java.util.ArrayList mVariableList
public java.util.ArrayList mOptionList
public java.util.ArrayList mGlobalList
public java.lang.String mTemplateFile
pds.label.PDSLabel mTemplateLabel
public int mLineCount
public java.lang.String mSourceName
public boolean mWriteOutput
public boolean mAbort
pds.util.PPIOption mOption
public static javax.servlet.jsp.JspWriter mOut
Constructor Detail |
---|
public PPIRuleset()
Method Detail |
---|
public static void main(java.lang.String[] args)
Options:
-d: Scan only the current directory. Do not recurse sub-directories. -r: Scan the current directory and recursely scan sub-directories.Usage:
labeler ruleset [-d | -R] pathname [pathname ...]
public void setOutput(javax.servlet.jsp.JspWriter out) throws java.lang.Exception
out
- a JspWriter to use.
java.lang.Exception
public boolean runRuleset(java.lang.String ruleFile, java.lang.String pathName) throws java.lang.Exception
ruleset
- the fully qualified path and name of the file containing
the ruleset to run.pathName
- the fully qualified path and name of the file to parse.
true
if the ruleset completed without errors;
false
otherwise.
java.lang.Exception
public boolean parse(java.lang.String pathName)
pathName
- the fully qualified path and name of the file to parse.
true
if the file could be opened;
false
otherwise.public boolean parseLine(java.lang.String buffer)
buffer
- the line of text to parse.
true
if the file could be opened;
false
otherwise.public boolean run(java.lang.String pathname)
pathname
- the pathname of the file to run the rule set on.
true
if an variable was set or added;
false
if error occured.
The variable mWriteOutput is set to
true
if output is to generated,
false
otherwise.
Since:
- 1.0
skipBlock
public int skipBlock(int start,
int type)
- Skips a block of code. The skip can be to the next
executable block or an entire block set. Returns the
number of lines to skip in the action list.
- Parameters:
start
- the line in the action list to start at.skip
- the type of skip. If set to null
it
will skip the to the next block. Otherwise it
will skip the blockset given. Pass PPIAction.IF
to the next block in an IF block set. Pass PPIAction.ENDIF
to skip the end of the current IF block set.
the title to print for the list.
- Returns:
- the line of the next executable statement.
- Since:
- 1.0
dumpList
public void dumpList(java.lang.String title,
java.util.ArrayList list)
- Print out all items in a list.
- Parameters:
title
- the title to print for the list.list
- the ArrayList
containing a set of PPIVariable
to merge with dest
.- Since:
- 1.0
evalToken
public char evalToken(java.lang.String text)
- Examines a string and returns a token representing the contents.
The following tokens are returned:
Token If String is
! !
= =
e exists
d isdir
f isfile
$ anything else
- Parameters:
text
- the string containing the text to examine
- Returns:
token
representing content.- Since:
- 1.0
evalCondition
public boolean evalCondition(java.util.ArrayList stack)
- Evaluate a condition that is coded into a array. Returns the result of
the evaluation.
- Parameters:
stack
- the array containing the tokens for the condition
to check.
- Returns:
true
if an variable was set or added;
false
if unable to add the variable.- Since:
- 1.0
makeRegex
public java.lang.String makeRegex(java.lang.String pattern)
- Converts a string to a regular expression pattern. All "*"
in the string are converted to ".*" and all "." are made
literal.
- Parameters:
pattern
- the string containing "nice" tokens for wild cards.
- Returns:
- the string altered to be a regular expression.
- Since:
- 1.0
dump
public void dump(boolean doAction)
- Prints out the current rule set in tokenized form.
- Parameters:
doAction
- the type of list to dump. If true then the
action list will be dumped, otherwise the variable
list will be dumped.- Since:
- 1.0
argFirst
public java.lang.String argFirst(java.lang.String buffer)
- Extract the first argument in the string. This is the text up the
first whitespace delimiter.
- Parameters:
buffer
- the string to parse.
- Returns:
String
containing the first argument.- Since:
- 1.0
argSplit
public java.util.ArrayList argSplit(java.lang.String buffer,
boolean onlyWhitespace)
- Split a string into one or more substrings by parsing on
whitespace and treating "!" and "=" as individual arguments.
Arguments in quotes are kept intack. Escaped characters are
converted preserved with the escape removed.
- Parameters:
buffer
- the string to parse.onlyWhitespace
- if true
split the string
using only whitespace as a delimiter. If false
the string is parsed on whitespace and "!" and "="
are considered as individual arguments.
- Returns:
ArrayList
an array of arguments.- Since:
- 1.0
convertYesNo
public boolean convertYesNo(java.lang.String value)
- Converts a string to a boolean state. If the string contains
"YES" then the state returned is
true
. If it
is anything else then false
is returned.
- Parameters:
value
- the string to convert.
- Returns:
true
if the string is "YES";
false
if string is anything else.- Since:
- 1.0
setOption
public void setOption(java.lang.String name,
java.lang.String value)
- Sets the value of an option.
- Parameters:
name
- the name of the variable to set.value
- the value to set for the variable.- Since:
- 1.0
mergeList
public void mergeList(java.util.ArrayList dest,
java.util.ArrayList list)
- Set variable list to match a passed list.
- Parameters:
dest
- the ArrayList
to merge the contents of
list
to.list
- the ArrayList
containing a set of PPIVariable
to merge with dest
.- Since:
- 1.0
findAndSet
public boolean findAndSet(pds.util.PPIVariable variable)
- Finds a variable in the variable list and set its value.
If the variable does not exist one is added.
- Parameters:
variable
- the name of the variable to set.
- Returns:
true
if an variable was set or added;
false
if unable to add the variable.- Since:
- 1.0
findAndSet
public boolean findAndSet(java.util.ArrayList list,
pds.util.PPIVariable variable)
- Finds a variable in the variable list and set its value.
If the variable does not exist one is added.
- Parameters:
list
- the ArrayList
containing a set of PPIVariable
to merge with dest
.variable
- the name of the variable to set.
- Returns:
true
if an variable was set or added;
false
if unable to add the variable.- Since:
- 1.0
findAndSet
public boolean findAndSet(java.lang.String name,
java.lang.String value)
- Finds an item in an array list and set its value.
If the item does not exist one is added.
- Parameters:
name
- the name of the variable to set.value
- the value to set for the variable.
- Returns:
true
if an variable was set or added;
false
if unable to add the variable.- Since:
- 1.0
findAndSet
public boolean findAndSet(java.util.ArrayList list,
java.lang.String name,
java.lang.String value)
- Finds an item in an array list and set its value.
If the item does not exist one is added.
- Parameters:
list
- the ArrayList
containing a set of PPIVariable
to merge with dest
.name
- the name of the variable to set.value
- the value to set for the variable.
- Returns:
true
if an variable was set or added;
false
if unable to add the variable.- Since:
- 1.0
findAndSet
public boolean findAndSet(java.lang.String name,
java.lang.String value,
boolean resolve)
- Finds an item in an array list and set its value.
If the item does not exist one is added.
- Parameters:
list
- the ArrayList
containing a set of PPIVariable
to merge with dest
.name
- the name of the variable to set.value
- the value to set for the variable.resolve
- a flag indicating whether to resolve variables in the
value.
- Returns:
true
if an variable was set or added;
false
if unable to add the variable.- Since:
- 1.0
findAndSet
public boolean findAndSet(java.util.ArrayList list,
java.lang.String name,
java.lang.String value,
boolean resolve)
- Finds an item in an array list and set its value.
If the item does not exist one is added.
- Parameters:
list
- the ArrayList
containing a set of PPIVariable
to merge with dest
.name
- the name of the variable to set.value
- the value to set for the variable.resolve
- a flag indicating whether to resolve variables in the
value.
- Returns:
true
if an variable was set or added;
false
if unable to add the variable.- Since:
- 1.0
getValue
public java.lang.String getValue(java.lang.String name)
- Finds a variable in the variable list and returns its value.
If the variable does not exist null is returned.
- Parameters:
name
- the name of the variable to set.
- Returns:
null
if an variable does not exist;
the value assigned to the variable if it does.- Since:
- 1.0
getValue
public java.lang.String getValue(java.util.ArrayList list,
java.lang.String name,
boolean blank)
- Finds a variable in the variable list and returns its value.
If the variable does not exist null is returned.
- Parameters:
list
- the ArrayList
containing a set of PPIVariable
to merge with dest
.name
- the name of the variable to set.blank
- indicates whether to return a blank string if
the variable is not found. If true
a
blank is returned. Otherwise null
is returned.
- Returns:
- The variable
null
if a variable does not exist and
blank
is false
. Returns a blank string
if blank
is true;
the value assigned to the variable if it does. - Since:
- 1.0
getIntValue
public int getIntValue(java.util.ArrayList list,
java.lang.String name)
- Finds an item in a variable list and returns its value as an integer.
If the variable does not exist 0 is returned. Since 0 is a valid integer
it can not be considered and indication that a variable does not exist.
- Parameters:
list
- the ArrayList
containing a set of PPIVariable
to merge with dest
.name
- the name of the variable to set.
- Returns:
- integer value assigned to the variable.
- Since:
- 1.0
getBooleanValue
public boolean getBooleanValue(java.util.ArrayList list,
java.lang.String name)
- Finds an item in a variable list and returns its value as an boolean.
If the variable does not exist false is returned.
- Parameters:
list
- the ArrayList
containing a set of PPIVariable
to merge with dest
.name
- the name of the variable to set.
- Returns:
- boolean value assigned to the variable.
- Since:
- 1.0
getExtension
public java.lang.String getExtension(java.lang.String name)
- Extracts the extension from a file name and returns the extension in uppercase.
- Parameters:
name
- the name of the file.
- Returns:
- String containing the extension in uppercase.
- Since:
- 1.0
isExtension
public boolean isExtension(java.lang.String name,
java.lang.String extension)
- Determines if the extension of a file name matches a given string.
- Parameters:
name
- the name of the file.
- Returns:
- boolean value of true if the extension is the same as the string.
- Since:
- 1.0
readLine
public java.lang.String readLine(java.io.BufferedReader stream)
- Parses the next line from a
BufferedStream
stream. A logical line
can span multiple physical lines when quotes (") or tag
delimiters (<>) are used.
- Parameters:
file
- the input file stream
- Returns:
true
if an element was parsed from the stream;
false
if the end of file or an error was encountered.- Since:
- 1.0
- See Also:
FileInputStream
reset
public void reset()
- Clear all variables, rules and states in the ruleset.
- Parameters:
file
- the input file stream- Since:
- 1.0
replaceVariable
public java.lang.String replaceVariable(java.lang.String buffer)
- Searches the passed string for variables and replaces each
variable with its current value. The string is passed through
only once.
- Parameters:
buffer
- the string to search for variables.
- Returns:
- the string with all variables replaced with
the current value.
- Since:
- 1.0
replaceVariable
public java.lang.String replaceVariable(java.lang.String buffer,
boolean plain)
- Searches the passed string for variables and replaces each
variable with its current value. The string is passed through
only once. Variable can have quotations escaped.
- Parameters:
buffer
- the string to search for variables.plain
- if true then values are taken as is (plain) otherwise
quote marks (") are escaped.
- Returns:
- the string with all variables replaced with
the current value.
- Since:
- 1.0
showMessage
public void showMessage(boolean location,
java.lang.String message)
- Prints and error message to the display. Adds information to the
message to help identify where the error occurred.
- Parameters:
location
- indicates whether location information should be
displayed before the message.message
- the text of the message to display.- Since:
- 1.0
show
public static void show(java.lang.String message)
- Prints text to the display.
- Parameters:
message
- the text of the message to display.- Since:
- 1.0
showRule
public static void showRule(int type)
- Prints text to the display. May be used for rules that require only one argument.
- Parameters:
type
- the type of rule to create. See PPIAction
for valid types.- Since:
- 1.0
showRule
public static void showRule(int type,
java.lang.String arg1)
- Prints text to the display. May be used for rules that require only one argument.
- Parameters:
type
- the type of rule to create. See PPIAction
for valid types.arg1
- the first argument for the rule. If argument is not
set pass null
.- Since:
- 1.0
showRule
public static void showRule(int type,
java.lang.String arg1,
java.lang.String arg2)
- Prints text to the display. Used for rules which require multiple arguments.
If an argument is not defined or not required pass
null
as the
value.
- Parameters:
type
- the type of rule to create. See PPIAction
for valid types.arg1
- the first argument for the rule. If argument is not
set pass null
.arg2
- the second argument for the rule. If argument is not
set pass null
.- Since:
- 1.0
showRule
public static void showRule(int type,
java.lang.String arg1,
int arg2)
- Prints text to the display. Used for rules which require multiple arguments.
If an argument is not defined or not required pass
null
as the
value.
- Parameters:
type
- the type of rule to create. See PPIAction
for valid types.arg1
- the first argument for the rule. If argument is not
set pass null
.arg2
- the second argument for the rule. If argument is not
set pass null
.- Since:
- 1.0
showRule
public static void showRule(int type,
java.lang.String arg1,
double arg2)
- Prints text to the display. Used for rules which require multiple arguments.
If an argument is not defined or not required pass
null
as the
value.
- Parameters:
type
- the type of rule to create. See PPIAction
for valid types.arg1
- the first argument for the rule. If argument is not
set pass null
.arg2
- the second argument for the rule. If argument is not
set pass null
.- Since:
- 1.0
update
public boolean update()
- Update the current template by replacing all variables
with the defined values. The template is a PDS label
and only the values assigned to an element may contain
variables.
- Since:
- 1.0
output
public void output()
throws java.lang.Exception
- Writes the template to the output files. The name and format
for the output file is controlled by various global options.
- Throws:
java.lang.Exception
- Since:
- 1.0
unquote
public static java.lang.String unquote(java.lang.String buffer)
- Removes quotes from a string if the string starts with and ends with
a quote character (").
- Parameters:
buffer
- the string to remove the quotes from.
- Returns:
- the string with the quotes removed, or the
orginal string of it is not quoted.
- Since:
- 1.0
makeRule
public static java.lang.String makeRule(int type,
java.lang.String arg1,
java.lang.String arg2)
- Creates a syntactically correct rule with the parameters passed.
- Parameters:
type
- the type of rule to create. See PPIAction
for valid types.arg1
- the first argument for the rule. If argument is not
set pass null
.arg2
- the second argument for the rule. If argument is not
set pass null
.
- Returns:
- the string with the fully formed rule or
null
if the type is unknown. - Since:
- 1.0
Package
Class
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD