org.apache.wiki.parser
Class JSPWikiMarkupParser

java.lang.Object
  extended by org.apache.wiki.parser.MarkupParser
      extended by org.apache.wiki.parser.JSPWikiMarkupParser

public class JSPWikiMarkupParser
extends MarkupParser

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

Field Summary
protected static int ATTACHMENT
           
protected static int CHARACTER
          The token is a plain character.
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.
protected static int EDIT
           
protected static int ELEMENT
          The token is a wikimarkup element.
protected static int EMPTY
           
protected static int EXTERNAL
           
protected static int IGNORE
          The token is to be ignored.
protected static int IMAGE
           
protected static int IMAGELINK
           
protected static int IMAGEWIKILINK
           
protected static int INTERWIKI
           
protected static int LOCAL
           
protected static int LOCALREF
           
static String PROP_CAMELCASELINKS
          If true, consider CamelCase hyperlinks as well.
static String PROP_PLAINURIS
          If true, all hyperlinks are translated as well, regardless whether they are surrounded by brackets.
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 int READ
           
 
Fields inherited from class org.apache.wiki.parser.MarkupParser
LEGACY_CHARS_ALLOWED, m_attachmentLinkMutatorChain, m_context, m_engine, m_externalLinkMutatorChain, m_headingListenerChain, m_in, m_inlineImages, m_linkMutators, m_localLinkMutatorChain, m_parseAccessRules, PROP_ALLOWHTML, PROP_RUNPLUGINS, PUNCTUATION_CHARS_ALLOWED, PUSHBACK_BUFFER_SIZE
 
Constructor Summary
JSPWikiMarkupParser(WikiContext context, Reader in)
          Creates a markup parser.
 
Method Summary
protected  void callHeadingListenerChain(Heading param)
          Calls the heading listeners.
protected  String callMutatorChain(Collection list, String text)
          Calls a transmutator chain.
protected  org.jdom2.Element createAnchor(int type, String link, String text, String section)
          Creates a JDOM anchor element.
static boolean isExternalLink(String link)
          Figures out if a link is an off-site link.
static boolean isPluginLink(String link)
          Returns true if the link is really command to insert a plugin.
static org.jdom2.Element makeError(String error)
          Writes HTML for error message.
 org.jdom2.Element makeHeading(int level, String title, Heading hd)
          Returns XHTML for the heading.
 WikiDocument parse()
          Parses the entire document from the Reader given in the constructor or set by MarkupParser.setInputReader(Reader).
protected  int parseToken(int ch)
          Return CHARACTER, if you think this was a plain character; ELEMENT, if you think this was a wiki markup element, and IGNORE, if you think we should ignore this altogether.
 
Methods inherited from class org.apache.wiki.parser.MarkupParser
addAttachmentLinkHook, addExternalLinkHook, addHeadingListener, addLinkTransmutator, addLocalLinkHook, cleanLink, cleanLink, disableAccessRules, enableImageInlining, getPosition, nextToken, pushBack, setInputReader, wikifyLink
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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 "createpage".

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

READ

protected static final int READ
See Also:
Constant Field Values

EDIT

protected static final int EDIT
See Also:
Constant Field Values

EMPTY

protected static final int EMPTY
See Also:
Constant Field Values

LOCAL

protected static final int LOCAL
See Also:
Constant Field Values

LOCALREF

protected static final int LOCALREF
See Also:
Constant Field Values

IMAGE

protected static final int IMAGE
See Also:
Constant Field Values

EXTERNAL

protected static final int EXTERNAL
See Also:
Constant Field Values

INTERWIKI

protected static final int INTERWIKI
See Also:
Constant Field Values

IMAGELINK

protected static final int IMAGELINK
See Also:
Constant Field Values

IMAGEWIKILINK

protected static final int IMAGEWIKILINK
See Also:
Constant Field Values

ATTACHMENT

protected static final int ATTACHMENT
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

CHARACTER

protected static final int CHARACTER
The token is a plain character.

See Also:
Constant Field Values

ELEMENT

protected static final int ELEMENT
The token is a wikimarkup element.

See Also:
Constant Field Values

IGNORE

protected static final int IGNORE
The token is to be ignored.

See Also:
Constant Field Values
Constructor Detail

JSPWikiMarkupParser

public JSPWikiMarkupParser(WikiContext context,
                           Reader in)
Creates a markup parser.

Parameters:
context - The WikiContext which controls the parsing
in - Where the data is read from.
Method Detail

callMutatorChain

protected String callMutatorChain(Collection list,
                                  String text)
Calls a transmutator chain.

Parameters:
list - Chain to call
text - Text that should be passed to the mutate() method of each of the mutators in the chain.
Returns:
The result of the mutation.

callHeadingListenerChain

protected void callHeadingListenerChain(Heading param)
Calls the heading listeners.

Parameters:
param - A Heading object.

createAnchor

protected org.jdom2.Element createAnchor(int type,
                                         String link,
                                         String text,
                                         String section)
Creates a JDOM anchor element. Can be overridden to change the URL creation, if you really know what you are doing.

Parameters:
type - One of the types above
link - URL to which to link to
text - Link text
section - If a particular section identifier is required.
Returns:
An A element.
Since:
2.4.78

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.

Parameters:
link - The link to check.
Returns:
true, if this is a link outside of this wiki.
Since:
2.4

isPluginLink

public static boolean isPluginLink(String link)
Returns true if the link is really command to insert a plugin.

Currently we just check if the link starts with "{INSERT", or just plain "{" but not "{$".

Parameters:
link - Link text, i.e. the contents of text between [].
Returns:
True, if this link seems to be a command to insert a plugin here.

makeError

public static org.jdom2.Element makeError(String error)
Writes HTML for error message. Does not add it to the document, you have to do it yourself.

Parameters:
error - The error string.
Returns:
An Element containing the error.

makeHeading

public org.jdom2.Element makeHeading(int level,
                                     String title,
                                     Heading hd)
Returns XHTML for the heading.

Parameters:
level - The level of the heading. @see Heading
title - the title for the heading
hd - a List to which heading should be added
Returns:
An Element containing the heading

parseToken

protected int parseToken(int ch)
                  throws IOException
Return CHARACTER, if you think this was a plain character; ELEMENT, if you think this was a wiki markup element, and IGNORE, if you think we should ignore this altogether.

To add your own MarkupParser, you can override this method, but it is recommended that you call super.parseToken() as well to gain advantage of JSPWiki's own markup. You can call it at the start of your own parseToken() or end - it does not matter.

Parameters:
ch - The character under investigation
Returns:
ELEMENT, CHARACTER or IGNORE.
Throws:
IOException - If parsing fails.

parse

public WikiDocument parse()
                   throws IOException
Parses the entire document from the Reader given in the constructor or set by MarkupParser.setInputReader(Reader).

Specified by:
parse in class MarkupParser
Returns:
A WikiDocument, ready to be passed to the renderer.
Throws:
IOException - If parsing cannot be accomplished.


Copyright © {inceptionYear}-2014 The Apache Software Foundation. All rights reserved.