com.ecyrd.jspwiki
Class TranslatorReader

java.lang.Object
  |
  +--java.io.Reader
        |
        +--com.ecyrd.jspwiki.TranslatorReader

public class TranslatorReader
extends java.io.Reader

Handles conversion from Wiki format into fully featured HTML. This is where all the magic happens. It is CRITICAL that this class is tested, or all Wikis might die horribly.

The output of the HTML has not yet been validated against the HTML DTD. However, it is very simple.

Author:
Janne Jalkanen

Field Summary
static int ATTACHMENT
           
static java.lang.String DEFAULT_INLINEPATTERN
          The default inlining pattern.
static int EDIT
           
static java.lang.String PROP_ALLOWHTML
          If set to "true", allows using raw HTML within Wiki text.
static java.lang.String PROP_CAMELCASELINKS
          If true, consider CamelCase hyperlinks as well.
static java.lang.String PROP_INLINEIMAGEPTRN
          This property defines the inline image pattern.
static java.lang.String PROP_PLAINURIS
          If true, all hyperlinks are translated as well, regardless whether they are surrounded by brackets.
static java.lang.String PROP_USEOUTLINKIMAGE
          If true, all outward links (external links) have a small link image appended.
static int READ
           
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
TranslatorReader(WikiContext context, java.io.Reader in)
           
 
Method Summary
 void addAttachmentLinkHook(StringTransmutator mutator)
          Adds a hook for processing attachment links.
 void addExternalLinkHook(StringTransmutator mutator)
          Adds a hook for processing external links.
 void addLinkTransmutator(StringTransmutator mutator)
          Adds a hook for processing link texts.
 void addLocalLinkHook(StringTransmutator mutator)
          Adds a hook for processing local links.
static java.lang.String cleanLink(java.lang.String link)
          Cleans a Wiki name.
 void close()
           
protected static java.util.Collection getImagePatterns(WikiEngine engine)
          Figure out which image suffixes should be inlined.
 java.lang.String makeLink(int type, java.lang.String link, java.lang.String text)
          Write a HTMLized link depending on its type.
 int read()
           
 int read(char[] buf, int off, int len)
           
 boolean ready()
           
 
Methods inherited from class java.io.Reader
mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

READ

public static final int READ
See Also:
Constant Field Values

EDIT

public static final int EDIT
See Also:
Constant Field Values

ATTACHMENT

public static final int ATTACHMENT
See Also:
Constant Field Values

PROP_INLINEIMAGEPTRN

public static final java.lang.String PROP_INLINEIMAGEPTRN
This property defines the inline image pattern. It's current value is jspwiki.translatorReader.inlinePattern

See Also:
Constant Field Values

PROP_CAMELCASELINKS

public static final java.lang.String PROP_CAMELCASELINKS
If true, consider CamelCase hyperlinks as well.

See Also:
Constant Field Values

PROP_PLAINURIS

public static final java.lang.String PROP_PLAINURIS
If true, all hyperlinks are translated as well, regardless whether they are surrounded by brackets.

See Also:
Constant Field Values

PROP_USEOUTLINKIMAGE

public static final java.lang.String PROP_USEOUTLINKIMAGE
If true, all outward links (external links) have a small link image appended.

See Also:
Constant Field Values

PROP_ALLOWHTML

public static final java.lang.String PROP_ALLOWHTML
If set to "true", allows using raw HTML within Wiki text. Be warned, this is a VERY dangerous option to set - never turn this on in a publicly allowable Wiki, unless you are absolutely certain of what you're doing.

See Also:
Constant Field Values

DEFAULT_INLINEPATTERN

public static final java.lang.String DEFAULT_INLINEPATTERN
The default inlining pattern. Currently "*.png"

See Also:
Constant Field Values
Constructor Detail

TranslatorReader

public TranslatorReader(WikiContext context,
                        java.io.Reader in)
Method Detail

addLinkTransmutator

public void addLinkTransmutator(StringTransmutator mutator)
Adds a hook for processing link texts. This hook is called when the link text is written into the output stream, and you may use it to modify the text. It does not affect the actual link, only the user-visible text.

Parameters:
mutator - The hook to call. Null is safe.

addLocalLinkHook

public void addLocalLinkHook(StringTransmutator mutator)
Adds a hook for processing local links. The engine transforms both non-existing and existing page links.

Parameters:
mutator - The hook to call. Null is safe.

addExternalLinkHook

public void addExternalLinkHook(StringTransmutator mutator)
Adds a hook for processing external links. This includes all http:// ftp://, etc. links, including inlined images.

Parameters:
mutator - The hook to call. Null is safe.

addAttachmentLinkHook

public void addAttachmentLinkHook(StringTransmutator mutator)
Adds a hook for processing attachment links.

Parameters:
mutator - The hook to call. Null is safe.

getImagePatterns

protected static java.util.Collection getImagePatterns(WikiEngine engine)
Figure out which image suffixes should be inlined.

Returns:
Collection of Strings with patterns.

makeLink

public java.lang.String makeLink(int type,
                                 java.lang.String link,
                                 java.lang.String text)
Write a HTMLized link depending on its type. The link mutator chain is processed.

Parameters:
type - Type of the link.
link - The actual link.
text - The user-visible text for the link.

cleanLink

public static java.lang.String cleanLink(java.lang.String link)
Cleans a Wiki name.

[ This is a link ] -> ThisIsALink

Parameters:
link - Link to be cleared. Null is safe, and causes this to return null.
Returns:
A cleaned link.
Since:
2.0

read

public int read()
         throws java.io.IOException
Overrides:
read in class java.io.Reader
java.io.IOException

read

public int read(char[] buf,
                int off,
                int len)
         throws java.io.IOException
Specified by:
read in class java.io.Reader
java.io.IOException

ready

public boolean ready()
              throws java.io.IOException
Overrides:
ready in class java.io.Reader
java.io.IOException

close

public void close()
Specified by:
close in class java.io.Reader