org.mmbase.util.transformers
Class RegexpReplacer

Package class diagram package RegexpReplacer
java.lang.Object
  extended by org.mmbase.util.transformers.ReaderTransformer
      extended by org.mmbase.util.transformers.ConfigurableReaderTransformer
          extended by org.mmbase.util.transformers.ChunkedTransformer<Pattern>
              extended by org.mmbase.util.transformers.RegexpReplacer
All Implemented Interfaces:
Serializable, CharTransformer, ConfigurableTransformer, Transformer
Direct Known Subclasses:
Censor, LinkFinder

public class RegexpReplacer
extends ChunkedTransformer<Pattern>

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
Version:
$Id: RegexpReplacer.java 44739 2011-01-12 08:52:31Z michiel $
Author:
Michiel Meeuwissen
See Also:
Serialized Form

Nested Class Summary
protected  class RegexpReplacer.PatternWatcher
           
 
Nested classes/interfaces inherited from class org.mmbase.util.transformers.ChunkedTransformer
ChunkedTransformer.Status
 
Field Summary
protected static Collection<Entry<Pattern,String>> regexps
          The regexps for the unextended RegexpReplacer
protected  boolean replaceInA
           
 
Fields inherited from class org.mmbase.util.transformers.ChunkedTransformer
ENTIRE, LINES, ONLY_REPLACE_FIRST_MATCH, ONLY_USE_FIRST_MATCHING_PATTERN, onlyFirstMatch, onlyFirstPattern, 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<Map.Entry<String,String>> list, Collection<Entry<Pattern,String>> 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<Entry<Pattern,String>> getPatterns()
          This on default gives the regexps configured for the base-class (a static member).
static void main(String[] arg)
           
protected  void readDefaultPatterns(Collection<Entry<Pattern,String>> patterns)
          Reads defaults translation patterns into the given collection patterns.
protected  void readPatterns(Collection<Entry<Pattern,String>> 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<Entry<Pattern,String>> regexps
The regexps for the unextended RegexpReplacer


replaceInA

protected boolean replaceInA
Constructor Detail

RegexpReplacer

public RegexpReplacer(int i)

RegexpReplacer

public RegexpReplacer()
Method Detail

getPatterns

protected Collection<Entry<Pattern,String>> 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<Entry<Pattern,String>> patterns)
Reads defaults translation patterns into the given collection patterns. Override this for other default patterns.


readPatterns

protected final void readPatterns(Collection<Entry<Pattern,String>> patterns)
Reads patterns from config-file into given Collection


addPatterns

protected static void addPatterns(Collection<Map.Entry<String,String>> list,
                                  Collection<Entry<Pattern,String>> 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<Pattern>
Throws:
IOException

base

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

toString

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

main

public static void main(String[] arg)


MMBase2 Utils 2.0-SNAPSHOT - 2013-03-30T06:24