gate.yam.convert
Class JSPWikiMarkupParser

java.lang.Object
  extended by gate.yam.convert.JSPWikiMarkupParser

public class JSPWikiMarkupParser
extends Object

Parses JSPWiki-style markup into a WikiDocument DOM tree. This class is the heart and soul of JSPWiki : make sure you test properly anything that is added, or else it breaks down horribly.

Since:
2.4
Author:
Janne Jalkanen

Field Summary
static String CLASS_EDITPAGE
          The value for anchor element class attributes when used for edit page links.
static String CLASS_INTERWIKI
          The value for anchor element class attributes when used for interwiki page links.
static String CLASS_WIKIPAGE
          The value for anchor element class attributes when used for wiki page (normal) links.
static String DEFAULT_INLINEPATTERN
          The default inlining pattern.
protected  ArrayList m_attachmentLinkMutatorChain
           
protected  ArrayList m_externalLinkMutatorChain
           
protected  ArrayList m_headingListenerChain
           
protected  PushbackReader m_in
           
protected  boolean m_inlineImages
           
protected  ArrayList m_linkMutators
           
protected  ArrayList m_localLinkMutatorChain
          Optionally stores internal wikilinks
protected  boolean m_parseAccessRules
           
static String PROP_ALLOWHTML
          If set to "true", allows using raw HTML within Wiki text.
static String PROP_CAMELCASELINKS
          If true, consider CamelCase hyperlinks as well.
static String PROP_INLINEIMAGEPTRN
          This property defines the inline image pattern.
static String PROP_PLAINURIS
          If true, all hyperlinks are translated as well, regardless whether they are surrounded by brackets.
static String PROP_RUNPLUGINS
          If set to "true", enables plugins during parsing
static String PROP_USEATTACHMENTIMAGE
          If true, all outward attachment info links have a small link image appended.
static String PROP_USEOUTLINKIMAGE
          If true, all outward links (external links) have a small link image appended.
static String PROP_USERELNOFOLLOW
          If set to "true", all external links are tagged with 'rel="nofollow"'
protected static String PUNCTUATION_CHARS_ALLOWED
          Lists all punctuation characters allowed in WikiMarkup.
protected static int PUSHBACK_BUFFER_SIZE
          Allow this many characters to be pushed back in the stream.
 
Constructor Summary
JSPWikiMarkupParser(Reader in)
          Creates a markup parser.
 
Method Summary
static String cleanLink(String link)
          Cleans a Wiki name.
 void disableAccessRules()
           
 void enableImageInlining(boolean toggle)
          Use this to turn on or off image inlining.
static boolean getBooleanProperty(Properties props, String key, boolean defval)
          Gets a boolean property from a standard Properties list.
static Collection getImagePatterns()
          Figure out which image suffixes should be inlined.
 int getPosition()
          Return the current position in the reader stream.
static boolean isExternalLink(String link)
          Figures out if a link is an off-site link.
static boolean isNumber(String s)
          Returns true, if the argument contains a number, otherwise false.
static boolean isPositive(String val)
          Returns true, if the string "val" denotes a positive string.
static org.jdom.Element makeError(String error)
          Writes HTML for error message.
 org.jdom.Element makeHeading(int level, String pageName, String title, gate.yam.convert.JSPWikiMarkupParser.Heading hd)
          Returns XHTML for the start of the heading.
protected  int nextToken()
           
 org.jdom.Document parse()
           
protected  void pushBack(int c)
          Push back any character to the current input.
 Reader setInputReader(Reader in)
          Replaces the current input character stream with a new one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PUSHBACK_BUFFER_SIZE

protected static final int PUSHBACK_BUFFER_SIZE
Allow this many characters to be pushed back in the stream. In effect, this limits the size of a single line.

See Also:
Constant Field Values

m_in

protected PushbackReader m_in

m_localLinkMutatorChain

protected ArrayList m_localLinkMutatorChain
Optionally stores internal wikilinks


m_externalLinkMutatorChain

protected ArrayList m_externalLinkMutatorChain

m_attachmentLinkMutatorChain

protected ArrayList m_attachmentLinkMutatorChain

m_headingListenerChain

protected ArrayList m_headingListenerChain

m_linkMutators

protected ArrayList m_linkMutators

m_inlineImages

protected boolean m_inlineImages

m_parseAccessRules

protected boolean m_parseAccessRules

PROP_ALLOWHTML

public static final 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

PROP_RUNPLUGINS

public static final String PROP_RUNPLUGINS
If set to "true", enables plugins during parsing

See Also:
Constant Field Values

PUNCTUATION_CHARS_ALLOWED

protected static final String PUNCTUATION_CHARS_ALLOWED
Lists all punctuation characters allowed in WikiMarkup. These will not be cleaned away.

See Also:
Constant Field Values

CLASS_WIKIPAGE

public static final String CLASS_WIKIPAGE
The value for anchor element class attributes when used for wiki page (normal) links. The value is "wikipage".

See Also:
Constant Field Values

CLASS_EDITPAGE

public static final String CLASS_EDITPAGE
The value for anchor element class attributes when used for edit page links. The value is "editpage".

See Also:
Constant Field Values

CLASS_INTERWIKI

public static final String CLASS_INTERWIKI
The value for anchor element class attributes when used for interwiki page links. The value is "interwiki".

See Also:
Constant Field Values

PROP_INLINEIMAGEPTRN

public static final 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 String PROP_CAMELCASELINKS
If true, consider CamelCase hyperlinks as well.

See Also:
Constant Field Values

PROP_PLAINURIS

public static final 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 String PROP_USEOUTLINKIMAGE
If true, all outward links (external links) have a small link image appended.

See Also:
Constant Field Values

PROP_USEATTACHMENTIMAGE

public static final String PROP_USEATTACHMENTIMAGE
If true, all outward attachment info links have a small link image appended.

See Also:
Constant Field Values

PROP_USERELNOFOLLOW

public static final String PROP_USERELNOFOLLOW
If set to "true", all external links are tagged with 'rel="nofollow"'

See Also:
Constant Field Values

DEFAULT_INLINEPATTERN

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

See Also:
Constant Field Values
Constructor Detail

JSPWikiMarkupParser

public JSPWikiMarkupParser(Reader in)
Creates a markup parser.

Method Detail

setInputReader

public Reader setInputReader(Reader in)
Replaces the current input character stream with a new one.

Parameters:
in - New source for input. If null, this method does nothing.
Returns:
the old stream

disableAccessRules

public void disableAccessRules()

enableImageInlining

public void enableImageInlining(boolean toggle)
Use this to turn on or off image inlining.

Parameters:
toggle - If true, images are inlined (as per set in jspwiki.properties) If false, then images won't be inlined; instead, they will be treated as standard hyperlinks.
Since:
2.2.9

getPosition

public int getPosition()
Return the current position in the reader stream. The value will be -1 prior to reading.

Returns:
the reader position as an int.

nextToken

protected int nextToken()
                 throws IOException
Throws:
IOException

pushBack

protected void pushBack(int c)
                 throws IOException
Push back any character to the current input. Does not push back a read EOF, though.

Throws:
IOException

cleanLink

public static String cleanLink(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

getImagePatterns

public static Collection getImagePatterns()
Figure out which image suffixes should be inlined.

Returns:
Collection of Strings with patterns.

isExternalLink

public static boolean isExternalLink(String link)
Figures out if a link is an off-site link. This recognizes the most common protocols by checking how it starts.

Since:
2.4

getBooleanProperty

public static boolean getBooleanProperty(Properties props,
                                         String key,
                                         boolean defval)
Gets a boolean property from a standard Properties list. Returns the default value, in case the key has not been set.

The possible values for the property are "true"/"false", "yes"/"no", or "on"/"off". Any value not recognized is always defined as "false".

Parameters:
props - A list of properties to search.
key - The property key.
defval - The default value to return.
Returns:
True, if the property "key" was set to "true", "on", or "yes".
Since:
2.0.11

isPositive

public static boolean isPositive(String val)
Returns true, if the string "val" denotes a positive string. Allowed values are "yes", "on", and "true". Comparison is case-insignificant. Null values are safe.

Parameters:
val - Value to check.
Returns:
True, if val is "true", "on", or "yes"; otherwise false.
Since:
2.0.26

isNumber

public static boolean isNumber(String s)
Returns true, if the argument contains a number, otherwise false. In a quick test this is roughly the same speed as Integer.parseInt() if the argument is a number, and roughly ten times the speed, if the argument is NOT a number.

Since:
2.4

makeError

public static org.jdom.Element makeError(String error)
Writes HTML for error message.


makeHeading

public org.jdom.Element makeHeading(int level,
                                    String pageName,
                                    String title,
                                    gate.yam.convert.JSPWikiMarkupParser.Heading hd)
Returns XHTML for the start of the heading. Also sets the line-end emitter.

Parameters:
level -
title - the title for the heading
hd - a List to which heading should be added

parse

public org.jdom.Document parse()
                        throws IOException
Throws:
IOException