Oracle

com.compoze.util
Class SubstitutionWriter

java.lang.Object
  extended by java.io.Writer
      extended by java.io.FilterWriter
          extended by com.compoze.util.TextLineFilterWriter
              extended by com.compoze.util.SubstitutionWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable

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%%.


Field Summary
 
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
append, append, append, 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.

Specified by:
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)

Oracle

Copyright ©1999-2008 Oracle All rights reserved.