org.pfsw.text
Class MatchRulePrinter

java.lang.Object
  extended by org.pfsw.text.MatchRulePrinter
All Implemented Interfaces:
MatchRuleVisitor

public class MatchRulePrinter
extends java.lang.Object
implements MatchRuleVisitor

Converts a MatchRule to a String using the default syntax. The only necessary method to call is:

asString( matchRule )


Constructor Summary
MatchRulePrinter()
          Initialize the new instance with default values.
MatchRulePrinter(MatchRuleChars ruleCharacters)
          Initialize the new instance with match rule characters.
 
Method Summary
protected  void appendOperators(boolean andOperator, boolean notOperator)
           
protected  void appendValue(java.lang.String value)
           
protected  void appendValueList(java.lang.String[] values)
           
 java.lang.String asString(MatchRule matchRule)
          Returns the specified match rule as a string.
 void attribute(java.lang.String name, MatchRuleCompareOperator compareOperator, java.lang.String[] values, boolean andOperator, boolean notOperator)
          This method will be called for each attribute.
protected  boolean containsSpecialCharacter(java.lang.String value)
           
 void endGroup()
          This method will be called for each group end occurence.
protected  char getAndChar()
          Returns the character for AND operations ( DEFAULT = '&' )
protected  java.lang.StringBuffer getBuffer()
           
protected  char getGroupEndChar()
          Returns the character that ends a logical group ( DEFAULT = ')' )
protected  char getGroupStartChar()
          Returns the character that starts a logical group ( DEFAULT = '(' )
protected  char getNotChar()
          Returns the character for NOT operations ( DEFAULT = '!'
protected  char getOrChar()
          Returns the character for OR operations ( DEFAULT = '|' )
protected  MatchRuleChars getRuleChars()
           
protected  char getValueEndChar()
          Returns the character ends a list of values ( DEFAULT = '}' )
protected  char getValueSeparatorChar()
          Returns the character for separation of values ( DEFAULT = ',' )
protected  char getValueStartChar()
          Returns the character that starts a list of values ( DEFAULT = '{' )
protected  boolean groupStarted()
           
protected  void groupStarted(boolean newValue)
           
protected  void setAndChar(char newValue)
          Sets the character for AND operations
protected  void setBuffer(java.lang.StringBuffer newValue)
           
protected  void setGroupEndChar(char newValue)
          Sets the character that ends a group
protected  void setGroupStartChar(char newValue)
          Sets the character that starts a group
protected  void setNotChar(char newValue)
          Sets the character for NOT operations
protected  void setOrChar(char newValue)
          Sets the character for OR operations
protected  void setRuleChars(MatchRuleChars newValue)
           
protected  void setValueEndChar(char newValue)
          Sets the character that ends a value list
protected  void setValueSeparatorChar(char newValue)
          Sets the character that separates values in a value list
protected  void setValueStartChar(char newValue)
          Sets the character that starts a value list
 void startGroup(boolean andOperator, boolean notOperator)
          This method will be called for each start of a new group.
 boolean useNewSyntax()
          Returns true, if the printer uses the new syntax which is using an equals character rather than the curly brackets for single values.
 void useNewSyntax(boolean newValue)
          Sets if the printer uses the new syntax.
protected  boolean useSetSyntax(MatchRuleCompareOperator compareOperator, java.lang.String[] values)
           
 void walkThroughFinished()
          This method will be called when the MatchRule has finished to walk through its elements.
 void walkThroughInit()
          This method will be called right before the MatchRule walks through its elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatchRulePrinter

public MatchRulePrinter()
Initialize the new instance with default values.


MatchRulePrinter

public MatchRulePrinter(MatchRuleChars ruleCharacters)
Initialize the new instance with match rule characters.

Method Detail

useNewSyntax

public boolean useNewSyntax()
Returns true, if the printer uses the new syntax which is using an equals character rather than the curly brackets for single values.
The default is NOT to use the new syntax to be compatible to old usage.


useNewSyntax

public void useNewSyntax(boolean newValue)
Sets if the printer uses the new syntax.


walkThroughInit

public void walkThroughInit()
This method will be called right before the MatchRule walks through its elements.

Specified by:
walkThroughInit in interface MatchRuleVisitor

walkThroughFinished

public void walkThroughFinished()
This method will be called when the MatchRule has finished to walk through its elements.

Specified by:
walkThroughFinished in interface MatchRuleVisitor

startGroup

public void startGroup(boolean andOperator,
                       boolean notOperator)
This method will be called for each start of a new group.

Specified by:
startGroup in interface MatchRuleVisitor
Parameters:
andOperator - If true it is an AND combination otherwise it is OR
notOperator - Is only true for a NOT operation

endGroup

public void endGroup()
This method will be called for each group end occurence.

Specified by:
endGroup in interface MatchRuleVisitor

attribute

public void attribute(java.lang.String name,
                      MatchRuleCompareOperator compareOperator,
                      java.lang.String[] values,
                      boolean andOperator,
                      boolean notOperator)
This method will be called for each attribute.

Specified by:
attribute in interface MatchRuleVisitor
Parameters:
name - The attribute's name
compareOperator - The operator used to compare values
values - All values the attrubute my match (implicit OR combination !)
andOperator - If true it is an AND combination otherwise it is OR
notOperator - Is only true for a NOT operation

asString

public java.lang.String asString(MatchRule matchRule)
Returns the specified match rule as a string.


appendOperators

protected void appendOperators(boolean andOperator,
                               boolean notOperator)

appendValueList

protected void appendValueList(java.lang.String[] values)

appendValue

protected void appendValue(java.lang.String value)

useSetSyntax

protected boolean useSetSyntax(MatchRuleCompareOperator compareOperator,
                               java.lang.String[] values)

getAndChar

protected char getAndChar()
Returns the character for AND operations ( DEFAULT = '&' )


setAndChar

protected void setAndChar(char newValue)
Sets the character for AND operations


getOrChar

protected char getOrChar()
Returns the character for OR operations ( DEFAULT = '|' )


setOrChar

protected void setOrChar(char newValue)
Sets the character for OR operations


getNotChar

protected char getNotChar()
Returns the character for NOT operations ( DEFAULT = '!' )


setNotChar

protected void setNotChar(char newValue)
Sets the character for NOT operations


getValueSeparatorChar

protected char getValueSeparatorChar()
Returns the character for separation of values ( DEFAULT = ',' )


setValueSeparatorChar

protected void setValueSeparatorChar(char newValue)
Sets the character that separates values in a value list


getValueStartChar

protected char getValueStartChar()
Returns the character that starts a list of values ( DEFAULT = '{' )


setValueStartChar

protected void setValueStartChar(char newValue)
Sets the character that starts a value list


getValueEndChar

protected char getValueEndChar()
Returns the character ends a list of values ( DEFAULT = '}' )


setValueEndChar

protected void setValueEndChar(char newValue)
Sets the character that ends a value list


getGroupStartChar

protected char getGroupStartChar()
Returns the character that starts a logical group ( DEFAULT = '(' )


setGroupStartChar

protected void setGroupStartChar(char newValue)
Sets the character that starts a group


getGroupEndChar

protected char getGroupEndChar()
Returns the character that ends a logical group ( DEFAULT = ')' )


setGroupEndChar

protected void setGroupEndChar(char newValue)
Sets the character that ends a group


containsSpecialCharacter

protected boolean containsSpecialCharacter(java.lang.String value)

getBuffer

protected java.lang.StringBuffer getBuffer()

setBuffer

protected void setBuffer(java.lang.StringBuffer newValue)

getRuleChars

protected MatchRuleChars getRuleChars()

setRuleChars

protected void setRuleChars(MatchRuleChars newValue)

groupStarted

protected boolean groupStarted()

groupStarted

protected void groupStarted(boolean newValue)