org.mmbase.util.transformers
Class ChunkedTransformer<P>

java.lang.Object
  extended by org.mmbase.util.transformers.ReaderTransformer
      extended by org.mmbase.util.transformers.ConfigurableReaderTransformer
          extended by org.mmbase.util.transformers.ChunkedTransformer<P>
All Implemented Interfaces:
Serializable, CharTransformer, ConfigurableTransformer, Transformer
Direct Known Subclasses:
RegexpReplacer, ResourceBundleReplacer

public abstract class ChunkedTransformer<P>
extends ConfigurableReaderTransformer
implements CharTransformer

A chunked transformer is a transformer that transforms on a 'chunk by chunk' base. A chunck is typically a word or a line or so. The type of the 'chunks' is controled by the 'mode' parameter. It can ignored existing XML markup (the 'XMLTEXT' modes), 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  class ChunkedTransformer.Status
           
 
Field Summary
static int ENTIRE
          Match the entire stream (so, one String must be created).
static int LINES
          Match line by line.
static int ONLY_REPLACE_FIRST_MATCH
          If this is added to the config-int, then only the first match of all patterns should be used.
static int ONLY_USE_FIRST_MATCHING_PATTERN
          If this is added to the config-int, then only the first match of any one pattern should be used.
protected  boolean onlyFirstMatch
           
protected  boolean onlyFirstPattern
           
static int WORDS
          Match word by word.
static int XMLTEXT
          Match in PCDATA of xml elements.
static int XMLTEXT_WORDS
          Match word by word, but only in PCDATA of xml elements.
 
Fields inherited from class org.mmbase.util.transformers.ConfigurableReaderTransformer
to
 
Constructor Summary
  ChunkedTransformer()
           
protected ChunkedTransformer(int i)
           
 
Method Summary
protected abstract  String base()
           
 void configure(int i)
          If a transformer can handle more then one destination format, it can be configured with this.
 String getEncoding()
          Returns the encoding that is currently active
static void main(String[] argv)
           
protected  ChunkedTransformer.Status newStatus()
           
protected  boolean replace(ChunkedTransformer.Status status)
          Whether still to do replacing, given status.
protected abstract  boolean replace(String string, Writer w, ChunkedTransformer.Status status)
          Implement this.
protected  boolean replaceWord(StringBuilder word, Writer writer, ChunkedTransformer.Status status)
           
 Writer transform(Reader r, Writer w)
           
 Writer transformEntire(Reader r, Writer w)
           
 Map<String,Config> transformers()
          Returns which transformations can be done by an object of this class.
 Writer transformLines(Reader r, Writer w)
           
 Writer transformWords(Reader r, Writer w)
           
 Writer transformXmlText(Reader r, Writer w)
           
 Writer transformXmlTextWords(Reader r, Writer w)
           
 
Methods inherited from class org.mmbase.util.transformers.ConfigurableReaderTransformer
toString
 
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
 
Methods inherited from interface org.mmbase.util.transformers.Transformer
toString
 

Field Detail

XMLTEXT_WORDS

public static final int XMLTEXT_WORDS
Match word by word, but only in PCDATA of xml elements.

See Also:
Constant Field Values

XMLTEXT

public static final int XMLTEXT
Match in PCDATA of xml elements.

See Also:
Constant Field Values

WORDS

public static final int WORDS
Match word by word.

See Also:
Constant Field Values

LINES

public static final int LINES
Match line by line.

See Also:
Constant Field Values

ENTIRE

public static final int ENTIRE
Match the entire stream (so, one String must be created).

See Also:
Constant Field Values

ONLY_USE_FIRST_MATCHING_PATTERN

public static final int ONLY_USE_FIRST_MATCHING_PATTERN
If this is added to the config-int, then only the first match of any one pattern should be used.

See Also:
Constant Field Values

ONLY_REPLACE_FIRST_MATCH

public static final int ONLY_REPLACE_FIRST_MATCH
If this is added to the config-int, then only the first match of all patterns should be used.

See Also:
Constant Field Values

onlyFirstPattern

protected boolean onlyFirstPattern

onlyFirstMatch

protected boolean onlyFirstMatch
Constructor Detail

ChunkedTransformer

protected ChunkedTransformer(int i)

ChunkedTransformer

public ChunkedTransformer()
Method Detail

configure

public void configure(int i)
Description copied from interface: ConfigurableTransformer
If a transformer can handle more then one destination format, it can be configured with this. There must be a default, since to can be null.

Specified by:
configure in interface ConfigurableTransformer
Overrides:
configure in class ConfigurableReaderTransformer

newStatus

protected ChunkedTransformer.Status newStatus()

replace

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

Throws:
IOException

replaceWord

protected boolean replaceWord(StringBuilder word,
                              Writer writer,
                              ChunkedTransformer.Status status)
                       throws IOException
Throws:
IOException

replace

protected boolean replace(ChunkedTransformer.Status status)
Whether still to do replacing, given status.


transformXmlTextWords

public Writer transformXmlTextWords(Reader r,
                                    Writer w)

transformXmlText

public Writer transformXmlText(Reader r,
                               Writer w)

transformWords

public Writer transformWords(Reader r,
                             Writer w)

transformLines

public Writer transformLines(Reader r,
                             Writer w)

transformEntire

public Writer transformEntire(Reader r,
                              Writer w)

transform

public Writer transform(Reader r,
                        Writer w)
Specified by:
transform in interface CharTransformer
Specified by:
transform in class ReaderTransformer

base

protected abstract String base()

getEncoding

public String getEncoding()
Description copied from interface: ConfigurableTransformer
Returns the encoding that is currently active

Specified by:
getEncoding in interface ConfigurableTransformer
Specified by:
getEncoding in class ConfigurableReaderTransformer
Returns:
An String representing the coding that is currently used.

transformers

public Map<String,Config> transformers()
Description copied from interface: ConfigurableTransformer
Returns which transformations can be done by an object of this class.

Specified by:
transformers in interface ConfigurableTransformer
Specified by:
transformers in class ConfigurableReaderTransformer
Returns:
A Map with String Integer/Class pairs.

main

public static void main(String[] argv)


MMBase 2.0-SNAPSHOT - null