public class SymbolCommuter extends Object implements StringProcessor
Symbols can be inserted into text as a placeholder for variables. SymbolCommuter will replace the symbols with values defined by a key/value pair mapping.
Symbols are denoted by a name and one or two tokens that either preceed or surround the symbol. The SymbolType class represents types of symbols that can be inserted into text as a placeholder for a value.
This class implements the StringProcessor interface so that it can be used with LineFilterReader to process a stream.
| Modifier and Type | Field and Description | 
|---|---|
static int | 
RAISE_EXCEPTION
Raise exceptions when symbols are undefined. 
 | 
static int | 
REMOVE_SYMBOL
Remove symbols that are undefined 
 | 
static int | 
SKIP
Skip symbols that are undefined. 
 | 
| Constructor and Description | 
|---|
SymbolCommuter(Hashtable symbolTable)
Creates a new SymbolCommuter with default settings. 
 | 
SymbolCommuter(Hashtable symbolTable,
              SymbolType type)
Creates a new SymbolCommuter given a SymbolType to search for. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
void | 
addSymbolType(SymbolType type)
Adds a SymbolType to search for when substituting values for symbols. 
 | 
Vector | 
getSymbolsInFile(String inputFile)
Returns all the symbols in a file, even if they are not mapped
 to values in this SymbolCommuter's table of key/value pairs. 
 | 
Vector | 
getSymbolsInString(String str)
Returns all the symbols in a String, even if they are not mapped
 to values in this SymbolCommuter's table of key/value pairs. 
 | 
Enumeration | 
getSymbolTypes()
Returns an Enumeration of the SymbolTypes in use. 
 | 
void | 
processDirectory(String sourceDir)
Replaces symbols in all text files in a given directory. 
 | 
void | 
processDirectory(String sourceDir,
                String destDir)
Replaces symbols in all text files in a given directory. 
 | 
void | 
processFile(String inputFile)
Replaces symbols with values in a text file. 
 | 
void | 
processFile(String inputFile,
           String outputFile)
Replaces symbols with values in a text file. 
 | 
String | 
processString(String input)
Replaces all symbols in the input String with values from this
 SymbolCommuter's symbol table. 
 | 
void | 
removeSymbolType(SymbolType type)
Removes a SymbolType to look for when substituting values for symbols. 
 | 
void | 
setUndefinedAction(int action)
Sets the action to take when an undefined symbol is found. 
 | 
public static final int SKIP
public static final int RAISE_EXCEPTION
public static final int REMOVE_SYMBOL
public SymbolCommuter(Hashtable symbolTable)
symbolTable - a Hashtable mapping symbol names to values.public SymbolCommuter(Hashtable symbolTable, SymbolType type)
symbolTable - a Hashtable mapping symbol names to values.type - the SymbolType to search for when processing Strings.public void setUndefinedAction(int action)
action - the action to take: SKIP, RAISE_EXCEPTION, or REMOVE_SYMBOL.public void addSymbolType(SymbolType type)
type - the SymbolType to add.public void removeSymbolType(SymbolType type)
type - the SymbolType to remove.public Enumeration getSymbolTypes()
public String processString(String input)
processString in interface StringProcessorinput - the input String.public void processFile(String inputFile) throws IOException, FileNotFoundException
inputFile - the file to process.IOExceptionFileNotFoundExceptionpublic void processFile(String inputFile, String outputFile) throws IOException, FileNotFoundException
inputFile - the file to process.outputFile - the file to save changes into.IOExceptionFileNotFoundExceptionpublic void processDirectory(String sourceDir) throws DirectoryItemHandlerException
sourceDir - the directory to process.DirectoryItemHandlerExceptionpublic void processDirectory(String sourceDir, String destDir) throws DirectoryItemHandlerException
sourceDir - the directory to process.destDir - the directory to save processed files to.DirectoryItemHandlerExceptionpublic Vector getSymbolsInFile(String inputFile) throws IOException, FileNotFoundException
IOException - if an I/O error occurs.FileNotFoundException - if the file could not be found.public Vector getSymbolsInString(String str)
Copyright © 2025. All rights reserved.