org.mmbase.util.transformers
Class ChunkedTransformer

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

public abstract class ChunkedTransformer
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 REPLACE_FIRST
          If this is added to the config-int, then only the first match should be used.
static int REPLACE_FIRST_ALL
          If this is added to the config-int, then only the first match should be used.
protected  boolean replaceFirst
           
protected  boolean replaceFirstAll
           
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
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(StringBuffer word, Writer writer, ChunkedTransformer.Status status)
           
 Writer transform(Reader r, Writer w)
           
 Writer transformEntire(Reader r, Writer w)
           
 Map 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

REPLACE_FIRST

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

See Also:
Constant Field Values

REPLACE_FIRST_ALL

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

See Also:
Constant Field Values

replaceFirst

protected boolean replaceFirst

replaceFirstAll

protected boolean replaceFirstAll
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(StringBuffer 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

transformers

public Map 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


MMBase build 1.8.1.20060716