public class TextEngine
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
CONTROL_ELSE |
protected static java.lang.String |
CONTROL_ENDIF |
protected static java.lang.String |
CONTROL_IF |
protected static java.lang.String |
CONTROL_IFDEF |
protected static java.lang.Character |
CONTROL_INDICATOR |
protected static java.lang.Character |
DEFAULT_FUNCPARAM_END |
protected static java.lang.Character |
DEFAULT_FUNCPARAM_START |
protected static java.lang.Character |
DEFAULT_PARAM_SEPARATOR |
protected static java.lang.Character |
DEFAULT_TEXT_DELIMITER |
protected static java.lang.Character |
DEFAULT_VAR_END_DELIMITER |
protected static java.lang.Character |
DEFAULT_VAR_START_DELIMITER |
protected static int |
EMPTY_CACHE |
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
allowMissingPlaceholders()
Allows placeholders that cannot be resolved by the variable resolver.
|
protected java.lang.String |
asString(java.lang.Object anObject) |
protected void |
checkEndAfterFunction(java.lang.String funcName) |
protected void |
checkFunctionEnd(java.lang.String funcName) |
protected void |
checkFunctionStart(java.lang.String funcName) |
protected void |
checkParameterCount(java.lang.String funcName,
int expected,
int actual) |
java.lang.String |
completeText(java.lang.String text)
Returns the given text, after replaceing all placeholders with according text.
|
protected void |
copyText() |
protected java.lang.String |
evaluateControl() |
protected java.lang.String |
evaluateControlELSE() |
protected java.lang.String |
evaluateControlENDIF() |
protected java.lang.String |
evaluateControlIF() |
protected java.lang.String |
evaluateControlIFDEF() |
protected java.lang.String |
evaluateFunction(java.lang.String funcName) |
protected java.lang.String |
evaluateFunction(java.lang.String funcName,
java.util.List<java.lang.String> parameter) |
protected java.lang.String |
evaluatePlaceholder(java.lang.String varName) |
void |
forbidMissingPlaceholders()
Forbids placeholders that cannot be resolved by the variable resolver.
|
protected int |
getCharCache() |
protected java.lang.Character |
getControlIndicator() |
protected java.util.Stack<Bool> |
getExecutionControl() |
protected java.lang.Character |
getFunctionParameterEnd() |
protected java.lang.String |
getFunctionParameterName()
Returns the next name for a function parameter.
|
protected java.util.List<java.lang.String> |
getFunctionParameters() |
protected java.lang.Character |
getFunctionParameterSeparator() |
protected java.lang.Character |
getFunctionParameterStart() |
FunctionResolver |
getFunctionResolver()
Returns the function resolver
|
protected java.lang.String |
getIndentationFiller() |
protected java.lang.Character |
getNextChar() |
protected boolean |
getNextCharFilled() |
protected java.lang.String |
getPlaceholderName() |
protected java.lang.String |
getPlaceholderValue() |
protected java.io.StringWriter |
getResultBuffer() |
protected java.io.StringReader |
getSourceBuffer() |
java.lang.String |
getSpecialNameCharacters()
Returns all extra charcters, that are allowed in placeholder names.
|
protected java.lang.String |
getTextConstant() |
protected java.lang.Character |
getTextDelimiter() |
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.
|
protected boolean |
hasDelimiterPrefix() |
protected boolean |
hasMoreChars() |
protected void |
initializeBuffers(java.lang.String text) |
protected void |
initializeResultBuffer(int initialCapacity) |
protected void |
initializeSourceBuffer(java.lang.String source) |
protected boolean |
isConditionalControlOn() |
protected boolean |
isDefinedPlaceholder(java.lang.String varName) |
protected boolean |
isIndentationOn() |
protected boolean |
isInsertionStart(java.lang.Character character) |
protected boolean |
isNextCharBufferEmpty() |
protected boolean |
isValidPlaceholderNameCharacter(char ch) |
protected boolean |
isWritingOn() |
protected java.lang.Character |
nextChar() |
protected java.lang.Character |
nextCharacter()
This is a convinient method for retreiving the
next character, without always catching IOException.
|
protected void |
putBackNextChar() |
protected void |
readAhead() |
protected void |
readNext() |
protected void |
removeLastWritingSwitch() |
protected java.lang.String |
resultString() |
protected void |
setCharCache(int newValue) |
protected void |
setExecutionControl(java.util.Stack<Bool> newValue) |
void |
setFunctionResolver(FunctionResolver fr)
Sets the function resolver
|
void |
setIndentation(int indentSize)
Sets the number of spaces a text must be indented.
|
protected void |
setIndentationFiller(java.lang.String newValue) |
protected void |
setNextChar(java.lang.Character ch) |
protected void |
setNextCharFilled(boolean flag) |
protected void |
setResultBuffer(java.io.StringWriter rb) |
protected void |
setSourceBuffer(java.io.StringReader sb) |
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.
|
protected java.lang.Character |
skipSpaces() |
protected StringUtil |
strUtil() |
protected boolean |
supressMissingVariableException() |
protected void |
supressMissingVariableException(boolean newValue) |
protected void |
switchWritingOff() |
protected void |
switchWritingOn() |
protected void |
switchWritingTo(Bool bool) |
protected void |
toggleWritingSwitch() |
void |
useDollarCurlyBrackets()
Sets the delimiters to ${}
|
protected void |
writeToResultBuffer(char ch) |
protected void |
writeToResultBuffer(java.lang.String text) |
protected static final java.lang.Character DEFAULT_VAR_START_DELIMITER
protected static final java.lang.Character DEFAULT_VAR_END_DELIMITER
protected static final java.lang.Character DEFAULT_TEXT_DELIMITER
protected static final java.lang.Character DEFAULT_PARAM_SEPARATOR
protected static final java.lang.Character DEFAULT_FUNCPARAM_START
protected static final java.lang.Character DEFAULT_FUNCPARAM_END
protected static final java.lang.Character CONTROL_INDICATOR
protected static final java.lang.String CONTROL_IF
protected static final java.lang.String CONTROL_ELSE
protected static final java.lang.String CONTROL_ENDIF
protected static final java.lang.String CONTROL_IFDEF
protected static final int EMPTY_CACHE
public TextEngine(VariableResolver varResolver)
varResolver
- The object that provides values for variablessetVariableResolver( VariableResolver )
public TextEngine(VariableResolver varResolver, FunctionResolver funcResolver)
varResolver
- The object that provides values for variablesfuncResolver
- The object that provides values for function callssetVariableResolver( VariableResolver )
,
setFunctionResolver( FunctionResolver )
public VariableResolver getVariableResolver()
public void setVariableResolver(VariableResolver vr)
public FunctionResolver getFunctionResolver()
public void setFunctionResolver(FunctionResolver fr)
public java.lang.Character getVarStartPrefix()
public void setVarStartPrefix(java.lang.Character prefix)
prefix
- The prefix character of null to use none.public java.lang.Character getVarStartDelimiter()
public void setVarStartDelimiter(java.lang.Character newValue)
public java.lang.Character getVarEndDelimiter()
public void setVarEndDelimiter(java.lang.Character newValue)
public java.lang.String getSpecialNameCharacters()
public void setSpecialNameCharacters(java.lang.String newValue)
public java.lang.String completeText(java.lang.String text) throws TextReplacementException
text
- The input text containing placeholders.TextReplacementException
public void setIndentation(int indentSize)
indentSize
- the number of indentation spaces ( 0 means no indentation )public void setVarStartDelimiter(char newValue)
public void setVarEndDelimiter(char newValue)
public void useDollarCurlyBrackets()
Placeholders then must look like ${varName}.
public void allowMissingPlaceholders()
public void forbidMissingPlaceholders()
protected void initializeResultBuffer(int initialCapacity)
protected void initializeSourceBuffer(java.lang.String source)
protected void initializeBuffers(java.lang.String text)
protected void copyText() throws TextReplacementException
TextReplacementException
protected boolean isInsertionStart(java.lang.Character character)
protected boolean hasDelimiterPrefix()
protected void writeToResultBuffer(java.lang.String text)
protected void writeToResultBuffer(char ch)
protected java.lang.String getPlaceholderName()
protected java.lang.String getPlaceholderValue() throws TextReplacementException
TextReplacementException
protected void checkEndAfterFunction(java.lang.String funcName) throws TextReplacementException
TextReplacementException
protected void checkFunctionStart(java.lang.String funcName) throws TextReplacementException
TextReplacementException
protected void checkFunctionEnd(java.lang.String funcName) throws TextReplacementException
TextReplacementException
protected void checkParameterCount(java.lang.String funcName, int expected, int actual) throws TextReplacementException
TextReplacementException
protected java.lang.String evaluateControlIF() throws TextReplacementException
TextReplacementException
protected java.lang.String evaluateControlIFDEF() throws TextReplacementException
TextReplacementException
protected java.lang.String evaluateControlELSE() throws TextReplacementException
TextReplacementException
protected java.lang.String evaluateControlENDIF() throws TextReplacementException
TextReplacementException
protected java.lang.String evaluateControl() throws TextReplacementException
TextReplacementException
protected java.lang.String getTextConstant()
protected java.lang.String asString(java.lang.Object anObject)
protected java.lang.String evaluatePlaceholder(java.lang.String varName) throws UnknownVariableException
UnknownVariableException
protected boolean isDefinedPlaceholder(java.lang.String varName)
protected java.util.List<java.lang.String> getFunctionParameters() throws TextReplacementException
TextReplacementException
protected java.lang.String getFunctionParameterName() throws TextReplacementException
TextReplacementException
protected java.lang.String evaluateFunction(java.lang.String funcName, java.util.List<java.lang.String> parameter) throws UnknownFunctionException, InvalidParameterException
protected java.lang.String evaluateFunction(java.lang.String funcName) throws TextReplacementException
TextReplacementException
protected void readAhead() throws java.io.IOException
java.io.IOException
protected void readNext() throws java.io.IOException
java.io.IOException
protected boolean hasMoreChars()
protected java.lang.Character nextChar() throws java.io.IOException
java.io.IOException
protected java.lang.Character nextCharacter()
protected void putBackNextChar()
protected boolean isNextCharBufferEmpty()
protected java.lang.Character skipSpaces()
protected java.lang.String resultString()
protected java.lang.Character getFunctionParameterStart()
protected java.lang.Character getFunctionParameterEnd()
protected java.lang.Character getFunctionParameterSeparator()
protected java.lang.Character getTextDelimiter()
protected boolean isValidPlaceholderNameCharacter(char ch)
protected java.lang.Character getControlIndicator()
protected boolean isIndentationOn()
protected boolean isWritingOn()
protected boolean isConditionalControlOn()
protected void removeLastWritingSwitch() throws java.util.EmptyStackException
java.util.EmptyStackException
protected void switchWritingTo(Bool bool)
protected void toggleWritingSwitch() throws java.util.EmptyStackException
java.util.EmptyStackException
protected void switchWritingOn()
protected void switchWritingOff()
protected StringUtil strUtil()
protected java.io.StringReader getSourceBuffer()
protected void setSourceBuffer(java.io.StringReader sb)
protected java.io.StringWriter getResultBuffer()
protected void setResultBuffer(java.io.StringWriter rb)
protected java.lang.Character getNextChar()
protected void setNextChar(java.lang.Character ch)
protected boolean getNextCharFilled()
protected void setNextCharFilled(boolean flag)
protected int getCharCache()
protected void setCharCache(int newValue)
protected java.util.Stack<Bool> getExecutionControl()
protected void setExecutionControl(java.util.Stack<Bool> newValue)
protected boolean supressMissingVariableException()
protected void supressMissingVariableException(boolean newValue)
protected java.lang.String getIndentationFiller()
protected void setIndentationFiller(java.lang.String newValue)