com.artenum.forceria.template
Class StringTemplate

java.lang.Object
  extended by com.artenum.forceria.template.StringTemplate

public class StringTemplate
extends Object

A string template is a string with the ability of replacing some special parts with some text. the replacement patterns are defined as the PATTERN_FORMAT enclosed with the 'enclosing char'

Author:
JeT - Artenum

Constructor Summary
StringTemplate()
          Default Constructor.
StringTemplate(String initialContent)
          Constructor
 
Method Summary
static String escRegExp(String inStr)
          This procedure is used to ensure that a string is not interpreted as a regular expression.
 String getContent()
          get the initial content with enclosing patterns replaced by all added replacements
 Set<String> getPatterns()
          get the set of patterns to be replaced
 boolean replace(StringTemplatePattern pattern, String text)
          replace a pattern composed of [CHAR]pattern[CHAR] by the given text, where [CHAR] is the defined enclosing char (which can be a string in fact)
 void reset()
          reset the replacement process from the initial content
 void setInitialContent(String initialContent)
          Set the initial content of the string to replace.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringTemplate

public StringTemplate()
Default Constructor. Do not forget to set the template content afterward


StringTemplate

public StringTemplate(String initialContent)
Constructor

Parameters:
content -
Method Detail

reset

public void reset()
reset the replacement process from the initial content


setInitialContent

public void setInitialContent(String initialContent)
Set the initial content of the string to replace. A map with element to replace is created.

Parameters:
initialContent -

replace

public boolean replace(StringTemplatePattern pattern,
                       String text)
replace a pattern composed of [CHAR]pattern[CHAR] by the given text, where [CHAR] is the defined enclosing char (which can be a string in fact)

Parameters:
pattern -
text -

getContent

public String getContent()
                  throws StringTemplateException
get the initial content with enclosing patterns replaced by all added replacements

Returns:
Throws:
StringTemplateException

getPatterns

public Set<String> getPatterns()
get the set of patterns to be replaced

Returns:

escRegExp

public static String escRegExp(String inStr)
This procedure is used to ensure that a string is not interpreted as a regular expression. This is useful when using the String.replaceAll() or String.split() functions with user input. This will escape special characters from the input string so that it will not be interpreted as a regular expression. This alternate version does not use a precompiled pattern so it may be copied and pasted into your code as is.

Parameters:
strIn - - a string that we want to ensure does not interfere with a regular expression.
Returns:
- strIn with the following chars escaped: [](){}+*^?$.\


Copyright © 2010-2013 Artenum. All Rights Reserved.