Compoze Software, Inc.

com.compoze.util
Class SubstitutionWriter

java.lang.Object
  |
  +--java.io.Writer
        |
        +--java.io.FilterWriter
              |
              +--com.compoze.util.TextLineFilterWriter
                    |
                    +--com.compoze.util.SubstitutionWriter

public class SubstitutionWriter
extends TextLineFilterWriter

This class substitutes text in a string as its being written. It takes a Map of text to replace and looks for substitution variables marked by an escape string. The escape string must appear both before and after the substitution variable. For example: %%substvar%%.


Fields inherited from class java.io.FilterWriter
out
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
SubstitutionWriter(java.io.Writer out, java.util.HashMap replacementMap)
          Constructor.
SubstitutionWriter(java.io.Writer out, java.lang.String sEscapeString, java.util.HashMap replacementMap)
          Constructor.
 
Method Summary
protected  java.lang.String filterLine(java.lang.String sLine)
          Filter a line of text.
static void main(java.lang.String[] args)
          Exerciser.
 
Methods inherited from class com.compoze.util.TextLineFilterWriter
flush, write, write, write
 
Methods inherited from class java.io.FilterWriter
close
 
Methods inherited from class java.io.Writer
write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SubstitutionWriter

public SubstitutionWriter(java.io.Writer out,
                          java.lang.String sEscapeString,
                          java.util.HashMap replacementMap)
Constructor.
Parameters:
out - the underlying writer
replacementMap - a hash mapping substitution variables to replacement strings
sEscapeString - the string appearing before and after each subtitution variable

SubstitutionWriter

public SubstitutionWriter(java.io.Writer out,
                          java.util.HashMap replacementMap)
Constructor. The default escape string "%%" is used.
Parameters:
out - the underlying writer
replacementMap - a hash mapping substitution variables to replacement strings
Method Detail

filterLine

protected java.lang.String filterLine(java.lang.String sLine)
Filter a line of text. This actually performs the replacement.
Overrides:
filterLine in class TextLineFilterWriter
Parameters:
sLine - the line to write (does not include line termination characters)
Returns:
the filtered line

main

public static void main(java.lang.String[] args)
Exerciser.
Parameters:
args - the command line arguments (input file then name/value pairs)

Compoze Software, Inc.

Copyright ©1999-2003 Compoze Software, Inc. All rights reserved.