|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.marcelsauer.tokenreplacer.FiniteStateMachineTokenReplacer
public class FiniteStateMachineTokenReplacer
parser implementation based on Finite State machine design
NOT PART OF THE PUBLIC API! STILL HERE AND PUBLIC IN CASE YOU NEED TO
'EMERGENCY' SUBCLASS.
| Nested Class Summary | |
|---|---|
protected static class |
FiniteStateMachineTokenReplacer.State
|
| Field Summary | |
|---|---|
protected char |
argsEnd
|
protected char |
argsSep
|
protected char |
argsStart
|
protected boolean |
generatorCachingEnabled
|
protected boolean |
ignoreMissingValues
|
protected char |
tokenEnd
|
protected java.util.Map<java.lang.String,Token> |
tokens
|
protected char |
tokenStart
|
| Constructor Summary | |
|---|---|
FiniteStateMachineTokenReplacer()
|
|
| Method Summary | |
|---|---|
protected void |
checkArgumentsAreValid(java.lang.String tokenName,
java.lang.StringBuilder args)
stuff like {dynamic(1,)} or {dynamic(1,2,)} seems to be invalid TODO do proper parsing instead of regex |
TokenReplacer |
disableGeneratorCaching()
turns generator caching OFF. |
TokenReplacer |
doNotIgnoreMissingValues()
tells the TokenReplacer to report any tokens that can not be
replaced. |
TokenReplacer |
enableGeneratorCaching()
turns generator caching ON. |
protected void |
ensureOneChar(java.lang.String character)
|
protected java.lang.String |
evalToken(java.lang.StringBuilder token,
java.lang.StringBuilder args,
java.util.Map<java.lang.String,java.lang.String> generatorCache)
|
protected java.lang.String[] |
extractArgs(java.lang.String tokenName,
java.lang.StringBuilder args)
|
TokenReplacer |
ignoreMissingValues()
tells the TokenReplacer to IGNORE any tokens that can not be
replaced. |
protected boolean |
isEndOfArguments(char character)
|
protected boolean |
isEndOfToken(char character)
|
protected boolean |
isStartOfArguments(char character)
|
protected boolean |
isStartOfToken(char character)
|
TokenReplacer |
register(java.lang.String[] replacements)
registers an array of replacements for a string based in indexed tokens. |
TokenReplacer |
register(java.lang.String token,
Generator generator)
registers a Token that will be replaced by the given
Generator. |
TokenReplacer |
register(java.lang.String token,
java.lang.String value)
registers a static value for a given token. |
TokenReplacer |
register(Token token)
registers a Token that needs to be replaced. |
java.lang.String |
substitute(java.lang.String toSubstitute)
replaces all Token with one of the following:
the provided static values set via TokenReplacer.register(String, String)
the token registered via TokenReplacer.register(Token)
the generator registered via TokenReplacer.register(String, Generator)
|
TokenReplacer |
withArgumentDelimiter(java.lang.String argsSep)
|
TokenReplacer |
withArgumentEnd(java.lang.String argsEnd)
|
TokenReplacer |
withArgumentStart(java.lang.String argsStart)
|
TokenReplacer |
withTokenEnd(java.lang.String tokenEnd)
|
TokenReplacer |
withTokenStart(java.lang.String tokenStart)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected char tokenStart
protected char tokenEnd
protected char argsStart
protected char argsEnd
protected char argsSep
protected boolean ignoreMissingValues
protected boolean generatorCachingEnabled
protected final java.util.Map<java.lang.String,Token> tokens
| Constructor Detail |
|---|
public FiniteStateMachineTokenReplacer()
| Method Detail |
|---|
public java.lang.String substitute(java.lang.String toSubstitute)
TokenReplacerToken with one of the following:
TokenReplacer.register(String, String)
TokenReplacer.register(Token)
TokenReplacer.register(String, Generator)
substitute in interface TokenReplacertoSubstitute - the string that contains the tokens, will be returned as-is in
case of null or empty string
protected boolean isStartOfToken(char character)
protected boolean isStartOfArguments(char character)
protected boolean isEndOfArguments(char character)
protected boolean isEndOfToken(char character)
protected java.lang.String[] extractArgs(java.lang.String tokenName,
java.lang.StringBuilder args)
protected void checkArgumentsAreValid(java.lang.String tokenName,
java.lang.StringBuilder args)
protected java.lang.String evalToken(java.lang.StringBuilder token,
java.lang.StringBuilder args,
java.util.Map<java.lang.String,java.lang.String> generatorCache)
public TokenReplacer register(java.lang.String token,
java.lang.String value)
TokenReplacer#register(Generator). same as registering a token via
TokenReplacer.register(Token) and supplying a replacement value via
Token.replacedBy(String).
register in interface TokenReplacertoken - the name of the token to be replaced e.g. for ${date} ->
"date" would be the token, must not be null or emptyvalue - the static value that will be used when replacing the token,
must not be null or empty
TokenReplacer to allow method chainingpublic TokenReplacer register(Token token)
TokenReplacerToken that needs to be replaced.
register in interface TokenReplacertoken - the Token, must not be null, the token must have a
valid value or generator associated with it which was set via
Token.replacedBy(String) or
Token.replacedBy(String)
#TokenReplacer to allow method chaining
public TokenReplacer register(java.lang.String token,
Generator generator)
TokenReplacerToken that will be replaced by the given
Generator. same as registering a token via
TokenReplacer.register(Token) and supplying a generator via
Token.replacedBy(Generator)
register in interface TokenReplacertoken - the name of the token to be replaced e.g. for ${date} ->
"date" would be the token, must not be null or empty
#TokenReplacer to allow method chainingpublic TokenReplacer withTokenStart(java.lang.String tokenStart)
withTokenStart in interface TokenReplacertokenStart - sets the token start identifier to the given value e.g.
[dynamic] -> '[' would be the start identifier, e.g. '[', must
not be null or empty
#TokenReplacer to allow method chainingpublic TokenReplacer withTokenEnd(java.lang.String tokenEnd)
withTokenEnd in interface TokenReplacertokenEnd - sets the token end identifier to the given value e.g.
[dynamic] -> ']' would be the end identifier, e.g. '[', must
not be null or empty
#TokenReplacer to allow method chainingprotected void ensureOneChar(java.lang.String character)
public TokenReplacer withArgumentDelimiter(java.lang.String argsSep)
withArgumentDelimiter in interface TokenReplacerargsSep - changes the delimiter of the arguments to the given value e.g.
{dynamic(1;2;3)} -> ';' would be the delimiter, must not be
null or empty
#TokenReplacer to allow method chainingpublic TokenReplacer withArgumentStart(java.lang.String argsStart)
withArgumentStart in interface TokenReplacerargsStart - sets the argument start identifier to the given value e.g.
{dynamic[1;2;3]} -> '[' would be the delimiter e.g. '[', must
not be null or empty
#TokenReplacer to allow method chainingpublic TokenReplacer withArgumentEnd(java.lang.String argsEnd)
withArgumentEnd in interface TokenReplacerargsEnd - sets the argument end identifier to the given value e.g.
{dynamic[1;2;3]} -> ']' would be the delimiter e.g. ']', must
not be null or empty
#TokenReplacer to allow method chainingpublic TokenReplacer doNotIgnoreMissingValues()
TokenReplacerTokenReplacer to report any tokens that can not be
replaced. if turned on an IllegalStateException will be thrown
during token replacement. reporting errors is turned ON by DEFAULT.
doNotIgnoreMissingValues in interface TokenReplacer#TokenReplacer to allow method chainingpublic TokenReplacer ignoreMissingValues()
TokenReplacerTokenReplacer to IGNORE any tokens that can not be
replaced. if turned OFF no Exceptions will be thrown during token
replacement. reporting errors is turned ON by DEFAULT.
ignoreMissingValues in interface TokenReplacer#TokenReplacer to allow method chainingpublic TokenReplacer enableGeneratorCaching()
TokenReplacerGenerator all remaining values with the same token name will be
replaced by the cached version. use TokenReplacer.disableGeneratorCaching() to
turn caching off.
enableGeneratorCaching in interface TokenReplacer#TokenReplacer to allow method chainingpublic TokenReplacer disableGeneratorCaching()
TokenReplacerTokenReplacer.enableGeneratorCaching() to
turn caching on.
disableGeneratorCaching in interface TokenReplacer#TokenReplacer to allow method chainingpublic TokenReplacer register(java.lang.String[] replacements)
TokenReplacer
toky.register(new String[] { "one", "two", "three" });
toky.substitute("{0} {1} {2}")); // will result in "one two three"
register in interface TokenReplacerreplacements - the array of replacements that will be used when replacing an
indexed strings, must not be null but can be empty
#TokenReplacer to allow method chaining
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||