com.togethersoft.openapi.util.text
Class TextUtil


public class TextUtil

Implements Text manipulations

Author:
TogetherSoft
Since: Together 4.0

Field Summary
 private static StringmySpecDelimiter
          The delimiter, which rounds replacing macros

Method Summary
 private static StringexpandMacro(String macro, Properties macros, Stack pendingMacros)
          Implements recursive expanding of a single macro
 static StringexpandString(String stringWithMacros, Properties macros)
          Replaces all occurences of macros in the string
Examples:
stringWithMacros = "%%a%% = %%b%% + %%c%%";
macros = {{"a", "5"}, {"b", "2"}, {"c", "3"}}
result: "5 = 2 + 3"
stringWithMacros = "%%a%% = %%b%% + %%c%%";
macros = {{"a", "6"}, {"b", "%%c%%"}, {"c", "3"}}
result: "6 = 3 + 3"
stringWithMacros = "%%a%% = %%b%% + %%c%%";
macros = {{"a", "6"}, {"b", "%%c%%"}, {"c", "%%b%%"}}
result: thrown IllegalArgumentException - recursion found
 private static StringexpandString(String stringWithMacros, Properties macros, Stack pendingMacros)
          Implements recursive expanding of string with macros
 static StringgetPrefix(String str, char separator)
          Returns prefix of the line Example: getPrefix ("WebLogic.PublicID", '.') will return "WebLogic"
getPrefix ("WebLogic.PublicID", ',') will return "WebLogic.PublicID"
 static Stringreplace(String source, String searchFor, String replaceWith)
          Replaces a part(s) of the source string by new contents The method replaces all occurences of searchFor in original
string.
 static StringreplaceMacro(String source, String macroName, String macroValue)
          Calls replace method to replace all occurence of source macroName rounded with mySpecDelimiter by macroValue.

Field Detail

mySpecDelimiter

private static String mySpecDelimiter
The delimiter, which rounds replacing macros
Method Detail

expandMacro

private static String expandMacro(String macro, Properties macros, Stack pendingMacros)
throws java.lang.IllegalArgumentException
Implements recursive expanding of a single macro

expandString

public static String expandString(String stringWithMacros, Properties macros)
throws java.lang.IllegalArgumentException
Replaces all occurences of macros in the string
Examples:
stringWithMacros = "%%a%% = %%b%% + %%c%%";
macros = {{"a", "5"}, {"b", "2"}, {"c", "3"}}
result: "5 = 2 + 3"
stringWithMacros = "%%a%% = %%b%% + %%c%%";
macros = {{"a", "6"}, {"b", "%%c%%"}, {"c", "3"}}
result: "6 = 3 + 3"
stringWithMacros = "%%a%% = %%b%% + %%c%%";
macros = {{"a", "6"}, {"b", "%%c%%"}, {"c", "%%b%%"}}
result: thrown IllegalArgumentException - recursion found
Parameters:
stringWithMacros - original string
macros - properties table with macro name-values pairs
Returns: expanded string
Throws:
IllegalArgumentException in case of recursive definition of macros

expandString

private static String expandString(String stringWithMacros, Properties macros, Stack pendingMacros)
throws java.lang.IllegalArgumentException
Implements recursive expanding of string with macros

getPrefix

public static String getPrefix(String str, char separator)
Returns prefix of the line Example: getPrefix ("WebLogic.PublicID", '.') will return "WebLogic"
getPrefix ("WebLogic.PublicID", ',') will return "WebLogic.PublicID"

replace

public static String replace(String source, String searchFor, String replaceWith)
Replaces a part(s) of the source string by new contents The method replaces all occurences of searchFor in original
string. It means that after first replacing new text (replaceWith) will not be searched for searchFor, and it's
possible to make replacement of "%%tag%%" by "%%tag%%%%tag%%" without getting of infinitive cycle.
Parameters:
source a source string
searchFor a string which should be replaced
replaceWith a string which replaces searchFor

replaceMacro

public static String replaceMacro(String source, String macroName, String macroValue)
Calls replace method to replace all occurence of source macroName rounded with mySpecDelimiter by macroValue.
Example, if macroName is "dir", then "%%dir%%" string occurences will be under replacement by macroValue

Association Links

to Class java.lang.String

The delimiter, which rounds replacing macros