org.pf.textx
Class TextEngine

java.lang.Object
  extended by org.pf.textx.TextEngine

public class TextEngine
extends java.lang.Object

Instances of this class are able to replace all variables by their values in a given text

Version:
1.7.2
Author:
Manfred Duchrow

Constructor Summary
TextEngine(VariableResolver varResolver)
          Initializes the new created instance with the given objects for resolving variable and function names to values.
TextEngine(VariableResolver varResolver, FunctionResolver funcResolver)
          Initializes the new created instance with the given objects for resolving variable and function names to values.
 
Method Summary
 void allowMissingPlaceholders()
          Allows placeholders that cannot be resolved by the variable resolver.
 java.lang.String completeText(java.lang.String text)
          Returns the given text, after replaceing all placeholders with according text.
 void forbidMissingPlaceholders()
          Forbids placeholders that cannot be resolved by the variable resolver.
 FunctionResolver getFunctionResolver()
          Returns the function resolver
 java.lang.String getSpecialNameCharacters()
          Returns all extra charcters, that are allowed in placeholder names.
 java.lang.Character getVarEndDelimiter()
          Returns the delimiter that marks the end of a variable
 VariableResolver getVariableResolver()
          Returns the variable resolver
 java.lang.Character getVarStartDelimiter()
          Returns the delimiter that marks the start of a variable
 java.lang.Character getVarStartPrefix()
          Returns the character that is specified as prefix of the placeholder delimiter or null, if none is used.
 void setFunctionResolver(FunctionResolver fr)
          Sets the function resolver
 void setIndentation(int indentSize)
          Sets the number of spaces a text must be indented.
 void setSpecialNameCharacters(java.lang.String newValue)
          Sets all extra charcters, that are allowed in placeholder names.
 void setVarEndDelimiter(char newValue)
          Sets the character that indicates the end of a placeholder or directive to the specified value.
 void setVarEndDelimiter(java.lang.Character newValue)
          Sets the delimiter that marks the end of a variable
 void setVariableResolver(VariableResolver vr)
          Sets the variable resolver
 void setVarStartDelimiter(char newValue)
          Sets the character that indicates the start of a placeholder or directive to the specified value.
 void setVarStartDelimiter(java.lang.Character newValue)
          Sets the delimiter that marks the start of a variable
 void setVarStartPrefix(java.lang.Character prefix)
          Sets the character that is is used as prefix of the placeholder start delimiter.
 void useDollarCurlyBrackets()
          Sets the delimiters to ${} Placeholders then must look like ${varName}.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextEngine

public TextEngine(VariableResolver varResolver)
Initializes the new created instance with the given objects for resolving variable and function names to values.

Parameters:
varResolver - The object that provides values for variables
See Also:
setVariableResolver( VariableResolver )

TextEngine

public TextEngine(VariableResolver varResolver,
                  FunctionResolver funcResolver)
Initializes the new created instance with the given objects for resolving variable and function names to values.

Parameters:
varResolver - The object that provides values for variables
funcResolver - The object that provides values for function calls
See Also:
setVariableResolver( VariableResolver ), setFunctionResolver( FunctionResolver )
Method Detail

getVariableResolver

public VariableResolver getVariableResolver()
Returns the variable resolver


setVariableResolver

public void setVariableResolver(VariableResolver vr)
Sets the variable resolver


getFunctionResolver

public FunctionResolver getFunctionResolver()
Returns the function resolver


setFunctionResolver

public void setFunctionResolver(FunctionResolver fr)
Sets the function resolver


getVarStartPrefix

public java.lang.Character getVarStartPrefix()
Returns the character that is specified as prefix of the placeholder delimiter or null, if none is used.
Example: %varName% -> Has no prefix, this method returns null
${varName} -> Uses '$' as prefix, this method returns Character('$')


setVarStartPrefix

public void setVarStartPrefix(java.lang.Character prefix)
Sets the character that is is used as prefix of the placeholder start delimiter.
Set to null, if no prefix is desired.

Parameters:
prefix - The prefix character of null to use none.

getVarStartDelimiter

public java.lang.Character getVarStartDelimiter()
Returns the delimiter that marks the start of a variable


setVarStartDelimiter

public void setVarStartDelimiter(java.lang.Character newValue)
Sets the delimiter that marks the start of a variable


getVarEndDelimiter

public java.lang.Character getVarEndDelimiter()
Returns the delimiter that marks the end of a variable


setVarEndDelimiter

public void setVarEndDelimiter(java.lang.Character newValue)
Sets the delimiter that marks the end of a variable


getSpecialNameCharacters

public java.lang.String getSpecialNameCharacters()
Returns all extra charcters, that are allowed in placeholder names.
By default only [A-Z][a-z][0-9] and '_' are allowed.


setSpecialNameCharacters

public void setSpecialNameCharacters(java.lang.String newValue)
Sets all extra charcters, that are allowed in placeholder names.
By default only [A-Z][a-z][0-9] and '_' are allowed.


completeText

public java.lang.String completeText(java.lang.String text)
                              throws TextReplacementException
Returns the given text, after replaceing all placeholders with according text.

Parameters:
text - The input text containing placeholders.
Returns:
the given input text with all placeholders replaced
Throws:
TextReplacementException

setIndentation

public void setIndentation(int indentSize)
Sets the number of spaces a text must be indented.

Parameters:
indentSize - the number of indentation spaces ( 0 means no indentation )

setVarStartDelimiter

public void setVarStartDelimiter(char newValue)
Sets the character that indicates the start of a placeholder or directive to the specified value.


setVarEndDelimiter

public void setVarEndDelimiter(char newValue)
Sets the character that indicates the end of a placeholder or directive to the specified value.


useDollarCurlyBrackets

public void useDollarCurlyBrackets()
Sets the delimiters to ${}

Placeholders then must look like ${varName}.


allowMissingPlaceholders

public void allowMissingPlaceholders()
Allows placeholders that cannot be resolved by the variable resolver. That means, that the placeholder's name itself will be placed in the text.
The default behaviour of a TextEngine is to throw an exception, if a placeholder can't be resolved.


forbidMissingPlaceholders

public void forbidMissingPlaceholders()
Forbids placeholders that cannot be resolved by the variable resolver. That means, that an exception will be thrown, if a placeholder can't be resolved.
The default behaviour of a TextEngine is to throw an exception, if a placeholder can't be resolved.