|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
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
public int skipBlock(int start, int type)
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.
public void dumpList(java.lang.String title, java.util.ArrayList list)
title
- the title to print for the list.list
- the ArrayList
containing a set of PPIVariable
to merge with dest
.public char evalToken(java.lang.String text)
text
- the string containing the text to examine
token
representing content.public boolean evalCondition(java.util.ArrayList stack)
stack
- the array containing the tokens for the condition
to check.
true
if an variable was set or added;
false
if unable to add the variable.public java.lang.String makeRegex(java.lang.String pattern)
pattern
- the string containing "nice" tokens for wild cards.
public void dump(boolean doAction)
doAction
- the type of list to dump. If true then the
action list will be dumped, otherwise the variable
list will be dumped.public java.lang.String argFirst(java.lang.String buffer)
buffer
- the string to parse.
String
containing the first argument.public java.util.ArrayList argSplit(java.lang.String buffer, boolean onlyWhitespace)
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.
ArrayList
an array of arguments.public boolean convertYesNo(java.lang.String value)
true
. If it
is anything else then false
is returned.
value
- the string to convert.
true
if the string is "YES";
false
if string is anything else.public void setOption(java.lang.String name, java.lang.String value)
name
- the name of the variable to set.value
- the value to set for the variable.public void mergeList(java.util.ArrayList dest, java.util.ArrayList list)
dest
- the ArrayList
to merge the contents of
list
to.list
- the ArrayList
containing a set of PPIVariable
to merge with dest
.public boolean findAndSet(pds.util.PPIVariable variable)
variable
- the name of the variable to set.
true
if an variable was set or added;
false
if unable to add the variable.public boolean findAndSet(java.util.ArrayList list, pds.util.PPIVariable variable)
list
- the ArrayList
containing a set of PPIVariable
to merge with dest
.variable
- the name of the variable to set.
true
if an variable was set or added;
false
if unable to add the variable.public boolean findAndSet(java.lang.String name, java.lang.String value)
name
- the name of the variable to set.value
- the value to set for the variable.
true
if an variable was set or added;
false
if unable to add the variable.public boolean findAndSet(java.util.ArrayList list, java.lang.String name, java.lang.String value)
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.
true
if an variable was set or added;
false
if unable to add the variable.public boolean findAndSet(java.lang.String name, java.lang.String value, boolean resolve)
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.
true
if an variable was set or added;
false
if unable to add the variable.public boolean findAndSet(java.util.ArrayList list, java.lang.String name, java.lang.String value, boolean resolve)
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.
true
if an variable was set or added;
false
if unable to add the variable.public java.lang.String getValue(java.lang.String name)
name
- the name of the variable to set.
null
if an variable does not exist;
the value assigned to the variable if it does.public java.lang.String getValue(java.util.ArrayList list, java.lang.String name, boolean blank)
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.
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.public int getIntValue(java.util.ArrayList list, java.lang.String name)
list
- the ArrayList
containing a set of PPIVariable
to merge with dest
.name
- the name of the variable to set.
public boolean getBooleanValue(java.util.ArrayList list, java.lang.String name)
list
- the ArrayList
containing a set of PPIVariable
to merge with dest
.name
- the name of the variable to set.
public java.lang.String getExtension(java.lang.String name)
name
- the name of the file.
public boolean isExtension(java.lang.String name, java.lang.String extension)
name
- the name of the file.
public java.lang.String readLine(java.io.BufferedReader stream)
BufferedStream
stream. A logical line
can span multiple physical lines when quotes (") or tag
delimiters (<>) are used.
file
- the input file stream
true
if an element was parsed from the stream;
false
if the end of file or an error was encountered.FileInputStream
public void reset()
file
- the input file streampublic java.lang.String replaceVariable(java.lang.String buffer)
buffer
- the string to search for variables.
public java.lang.String replaceVariable(java.lang.String buffer, boolean plain)
buffer
- the string to search for variables.plain
- if true then values are taken as is (plain) otherwise
quote marks (") are escaped.
public void showMessage(boolean location, java.lang.String message)
location
- indicates whether location information should be
displayed before the message.message
- the text of the message to display.public static void show(java.lang.String message)
message
- the text of the message to display.public static void showRule(int type)
type
- the type of rule to create. See PPIAction
for valid types.public static void showRule(int type, java.lang.String arg1)
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
.public static void showRule(int type, java.lang.String arg1, java.lang.String arg2)
null
as the
value.
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
.public static void showRule(int type, java.lang.String arg1, int arg2)
null
as the
value.
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
.public static void showRule(int type, java.lang.String arg1, double arg2)
null
as the
value.
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
.public boolean update()
public void output() throws java.lang.Exception
java.lang.Exception
public static java.lang.String unquote(java.lang.String buffer)
buffer
- the string to remove the quotes from.
public static java.lang.String makeRule(int type, java.lang.String arg1, java.lang.String arg2)
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
.
null
if the type is unknown.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |