imcode.server.parser
Class MapSubstitution

java.lang.Object
  extended by imcode.server.parser.MapSubstitution
All Implemented Interfaces:
org.apache.oro.text.regex.Substitution

public class MapSubstitution
extends java.lang.Object
implements org.apache.oro.text.regex.Substitution

This class is a generic Substitiution to be used with the jakarta-oro regexp classes. It uses a java.util.Map as a Substitution source. This allows you to use a HashMap or some other Map for the substitutions.

Example: // Create the matcher needed for the substitution Perl5Matcher matcher = new Perl5Matcher() ;

// Create a pattern that will match words Perl5Compiler compiler = new Perl5Compiler() ; Pattern pattern = compiler.compile("\\b\\w+\\b") ;

// Create and populate the map HashMap map = new HashMap() ; map.put("foo","bar") ; // Replace 'foo' with 'bar'. map put("baz","quux") ; // Replace 'baz' with 'quux'.

// Create the MapSubstitution MapSubstitution substitution = new MapSubstitution(map, false) ;

// Create the input String input = "foo bar baz quux" ;

// Do the substitution String output = Util.substitute(matcher, pattern, substitution, input) ;

// 'output' will now contain "bar bar quux quux".


Constructor Summary
MapSubstitution(java.util.Map map, boolean removeNulls)
           
 
Method Summary
 void appendSubstitution(java.lang.StringBuffer sb, org.apache.oro.text.regex.MatchResult matres, int sc, org.apache.oro.text.regex.PatternMatcherInput originalInput, org.apache.oro.text.regex.PatternMatcher patMat, org.apache.oro.text.regex.Pattern pat)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapSubstitution

public MapSubstitution(java.util.Map map,
                       boolean removeNulls)
Method Detail

appendSubstitution

public void appendSubstitution(java.lang.StringBuffer sb,
                               org.apache.oro.text.regex.MatchResult matres,
                               int sc,
                               org.apache.oro.text.regex.PatternMatcherInput originalInput,
                               org.apache.oro.text.regex.PatternMatcher patMat,
                               org.apache.oro.text.regex.Pattern pat)
Specified by:
appendSubstitution in interface org.apache.oro.text.regex.Substitution