org.mmbase.util.transformers
Class RegexpReplacer

java.lang.Object
  extended byorg.mmbase.util.transformers.ReaderTransformer
      extended byorg.mmbase.util.transformers.ConfigurableReaderTransformer
          extended byorg.mmbase.util.transformers.ChunkedTransformer
              extended byorg.mmbase.util.transformers.RegexpReplacer
All Implemented Interfaces:
CharTransformer, ConfigurableTransformer, Serializable, Transformer
Direct Known Subclasses:
Censor, LinkFinder

public class RegexpReplacer
extends ChunkedTransformer

Finds regexps in the Character String, and replaces them. The replaced regexps can be found in a configuration file 'regexps.xml' (if it is present). It ignores existing XML markup, and also avoids trailing dots and comments and surrounding quotes and parentheses.

Since:
MMBase-1.8
Author:
Michiel Meeuwissen
See Also:
Serialized Form

Nested Class Summary
protected static class RegexpReplacer.PatternWatcher
           
 
Nested classes inherited from class org.mmbase.util.transformers.ChunkedTransformer
ChunkedTransformer.Status
 
Field Summary
protected static Collection regexps
          The regexps for the unextended RegexpReplacer
 
Fields inherited from class org.mmbase.util.transformers.ChunkedTransformer
ENTIRE, LINES, REPLACE_FIRST, REPLACE_FIRST_ALL, replaceFirst, replaceFirstAll, WORDS, XMLTEXT, XMLTEXT_WORDS
 
Fields inherited from class org.mmbase.util.transformers.ConfigurableReaderTransformer
to
 
Constructor Summary
RegexpReplacer()
           
RegexpReplacer(int i)
           
 
Method Summary
protected static void addPatterns(Collection list, Collection patterns)
          Utility function to create a bunch of patterns.
protected  String base()
           
protected  String getConfigFile()
          This can be overridden if the implementation must use its own configuration file.
protected  Collection getPatterns()
          This on default gives the regexps configured for the base-class (a static member).
protected  void readDefaultPatterns(Collection patterns)
          Reads defaults translation patterns into the given collection patterns.
protected  void readPatterns(Collection patterns)
          Reads patterns from config-file into given Collection
protected  boolean replace(String string, Writer w, ChunkedTransformer.Status status)
          Implement this.
 String toString()
           
 
Methods inherited from class org.mmbase.util.transformers.ChunkedTransformer
configure, getEncoding, newStatus, replace, replaceWord, transform, transformEntire, transformers, transformLines, transformWords, transformXmlText, transformXmlTextWords
 
Methods inherited from class org.mmbase.util.transformers.ReaderTransformer
transform, transform, transformBack, transformBack, transformBack
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mmbase.util.transformers.CharTransformer
transform, transform, transformBack, transformBack, transformBack
 

Field Detail

regexps

protected static final Collection regexps
The regexps for the unextended RegexpReplacer

Constructor Detail

RegexpReplacer

public RegexpReplacer(int i)

RegexpReplacer

public RegexpReplacer()
Method Detail

getPatterns

protected Collection getPatterns()
This on default gives the regexps configured for the base-class (a static member). You can override this method to return another Collection.


getConfigFile

protected String getConfigFile()
This can be overridden if the implementation must use its own configuration file.


readDefaultPatterns

protected void readDefaultPatterns(Collection patterns)
Reads defaults translation patterns into the given collection patterns. Override this for other default patterns.


readPatterns

protected final void readPatterns(Collection patterns)
Reads patterns from config-file into given Collection


addPatterns

protected static void addPatterns(Collection list,
                                  Collection patterns)
Utility function to create a bunch of patterns.

Parameters:
list - A Collection of Map.Entry (like Map.entrySet()), containing pairs of Strings
patterns - This the Collection of Entries. The key of every entry is a compiled regular expression. The value is still a String. New entries will be added to this collection by this function.

replace

protected boolean replace(String string,
                          Writer w,
                          ChunkedTransformer.Status status)
                   throws IOException
Description copied from class: ChunkedTransformer
Implement this. Return true if a replacement done.

Specified by:
replace in class ChunkedTransformer
Throws:
IOException

base

protected final String base()
Specified by:
base in class ChunkedTransformer

toString

public String toString()
Specified by:
toString in interface Transformer
Overrides:
toString in class ConfigurableReaderTransformer


MMBase build 1.8.1.20060716