Package org.apache.wiki.parser

# Class MarkupParser

java.lang.Object
org.apache.wiki.parser.MarkupParser

Direct Known Subclasses:
  `JSPWikiMarkupParser`

public abstract class MarkupParser extends Object
Provides an abstract class for the parser instances.

Since:
  2.4

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`CLASS_ATTACHMENT`
The value for anchor element `class` attributes when used for attachments.
`static final String`
`CLASS_EDITPAGE`
The value for anchor element `class` attributes when used for edit page links.
`static final String`
`CLASS_EXTERNAL`
The value for anchor element `class` attributes when used for external links.
`static final String`
`CLASS_FOOTNOTE`
The value for anchor element `class` attributes when used for footnote links.
`static final String`
`CLASS_FOOTNOTE_REF`
The value for anchor element `class` attributes when used for footnote links.
`static final String`
`CLASS_INTERWIKI`
The value for anchor element `class` attributes when used for interwiki page links.
`static final String[]`
`CLASS_TYPES`
`static final String`
`CLASS_WIKIPAGE`
The value for anchor element `class` attributes when used for wiki page (normal) links.
`static final String`
`HASHLINK`
`protected final ArrayList<StringTransmutator>`
`m_attachmentLinkMutatorChain`
`protected final Context`
`m_context`
`protected final Engine`
`m_engine`
`protected final ArrayList<StringTransmutator>`
`m_externalLinkMutatorChain`
`protected final ArrayList<HeadingListener>`
`m_headingListenerChain`
`protected PushbackReader`
`m_in`
`protected List<org.apache.oro.text.regex.Pattern>`
`m_inlineImagePatterns`
Keeps image regexp Patterns
`protected boolean`
`m_inlineImages`
`protected final ArrayList<StringTransmutator>`
`m_linkMutators`
`protected final LinkParsingOperations`
`m_linkParsingOperations`
`protected final ArrayList<StringTransmutator>`
`m_localLinkMutatorChain`
Optionally stores internal wikilinks
`protected boolean`
`m_parseAccessRules`
`static final String`
`OUTLINK`
Outlink css class.
`static final String`
`OUTLINK_IMAGE`
Name of the outlink image; relative path to the JSPWiki directory.
`static final String`
`PROP_ALLOWHTML`
If set to "true", allows using raw HTML within Wiki text.
`static final String`
`PROP_CAMELCASELINKS`
If true, consider CamelCase hyperlinks as well.
`static final String`
`PROP_PLAINURIS`
If true, all hyperlinks are translated as well, regardless whether they are surrounded by brackets.
`static final String`
`PROP_RUNPLUGINS`
If set to "true", enables plugins during parsing
`static final String`
`PROP_USEATTACHMENTIMAGE`
If true, all outward attachment info links have a small link image appended.
`static final String`
`PROP_USEOUTLINKIMAGE`
If true, all outward links (external links) have a small link image appended.
`static final String`
`PROP_USERELNOFOLLOW`
If set to "true", all external links are tagged with 'rel="nofollow"'
`protected static final int`
`PUSHBACK_BUFFER_SIZE`
Allow this many characters to be pushed back in the stream.

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`MarkupParser(Context context, Reader in)`
Constructs a MarkupParser.

## Method Summary

Modifier and Type
Method
Description
`void`
`addAttachmentLinkHook(StringTransmutator mutator)`
Adds a hook for processing attachment links.
`void`
`addExternalLinkHook(StringTransmutator mutator)`
Adds a hook for processing external links.
`void`
`addHeadingListener(HeadingListener listener)`
Adds a HeadingListener to the parser chain.
`void`
`addLinkTransmutator(StringTransmutator mutator)`
Adds a hook for processing link texts.
`void`
`addLocalLinkHook(StringTransmutator mutator)`
Adds a hook for processing local links.
`static String`
`cleanLink(String link)`
Cleans a Wiki name.
`void`
`disableAccessRules()`
Disables access rule parsing.
`void`
`enableImageInlining(boolean toggle)`
Use this to turn on or off image inlining.
`List<org.apache.oro.text.regex.Pattern>`
`getInlineImagePatterns()`
`int`
`getPosition()`
Return the current position in the reader stream.
`protected final void`
`initInlineImagePatterns()`
`boolean`
`isImageInlining()`
`boolean`
`isParseAccessRules()`
`static org.jdom2.Element`
`makeError(String error)`
Writes HTML for error message.
`protected final int`
`nextToken()`
Returns the next token in the stream.
`abstract WikiDocument`
`parse()`
Parses the document.
`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.
`static String`
`wikifyLink(String link)`
Cleans away extra legacy characters.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### 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_engine

protected final Engine m_engine

### m_context

protected final Context m_context

### m_localLinkMutatorChain

protected final ArrayList<StringTransmutator> m_localLinkMutatorChain
Optionally stores internal wikilinks

### m_externalLinkMutatorChain

protected final ArrayList<StringTransmutator> m_externalLinkMutatorChain

### m_attachmentLinkMutatorChain

protected final ArrayList<StringTransmutator> m_attachmentLinkMutatorChain

### m_linkMutators

protected final ArrayList<StringTransmutator> m_linkMutators

### m_headingListenerChain

protected final ArrayList<HeadingListener> m_headingListenerChain

### m_inlineImages

protected boolean m_inlineImages

### m_parseAccessRules

protected boolean m_parseAccessRules

### m_inlineImagePatterns

protected List<org.apache.oro.text.regex.Pattern> m_inlineImagePatterns
Keeps image regexp Patterns

### m_linkParsingOperations

protected final LinkParsingOperations m_linkParsingOperations

### 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

### 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_USERELNOFOLLOW

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

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_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

### HASHLINK

public static final String HASHLINK

See Also:
  - Constant Field Values

### OUTLINK_IMAGE

public static final String OUTLINK_IMAGE
Name of the outlink image; relative path to the JSPWiki directory.

See Also:
  - Constant Field Values

### OUTLINK

public static final String OUTLINK
Outlink css class.

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

### CLASS_FOOTNOTE

public static final String CLASS_FOOTNOTE
The value for anchor element `class` attributes when used for footnote links. The value is "footnote".

See Also:
  - Constant Field Values

### CLASS_FOOTNOTE_REF

public static final String CLASS_FOOTNOTE_REF
The value for anchor element `class` attributes when used for footnote links. The value is "footnote".

See Also:
  - Constant Field Values

### CLASS_EXTERNAL

public static final String CLASS_EXTERNAL
The value for anchor element `class` attributes when used for external links. The value is "external".

See Also:
  - Constant Field Values

### CLASS_ATTACHMENT

public static final String CLASS_ATTACHMENT
The value for anchor element `class` attributes when used for attachments. The value is "attachment".

See Also:
  - Constant Field Values

### CLASS_TYPES

public static final String[] CLASS_TYPES

## Constructor Details

### MarkupParser

protected MarkupParser(Context context, Reader in)
Constructs a MarkupParser. The subclass must call this constructor to set up the necessary bits and pieces.

Parameters:
  `context` - The WikiContext.
  `in` - The reader from which we are reading the bytes from.

## Method Details

### 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

### 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.

### addHeadingListener

public void addHeadingListener(HeadingListener listener)
Adds a HeadingListener to the parser chain. It will be called whenever a parsed header is found.

Parameters:
  `listener` - The listener to add.

### disableAccessRules

public void disableAccessRules()
Disables access rule parsing.

### isParseAccessRules

public boolean isParseAccessRules()

### 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

### isImageInlining

public boolean isImageInlining()

### initInlineImagePatterns

protected final void initInlineImagePatterns()

### getInlineImagePatterns

public List<org.apache.oro.text.regex.Pattern> getInlineImagePatterns()

### parse

public abstract WikiDocument parse() throws IOException
Parses the document.

Returns:
  the parsed document, as a WikiDocument
Throws:
  `IOException` - If something goes wrong.

### 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 final int nextToken() throws IOException, NullPointerException
Returns the next token in the stream. This is the most called method in the entire parser, so it needs to be lean and mean.

Returns:
  The next token in the stream; or, if the stream is ended, -1.
Throws:
  `IOException` - If something bad happens
  `NullPointerException` - If you have not yet created an input document.

### pushBack

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

Parameters:
  `c` - Character to push back.
Throws:
  `IOException` - In case the character cannot be pushed back.

### 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.

### cleanLink

public static String cleanLink(String link)
Cleans a Wiki name. The functionality of this method was changed in 2.6 so that the list of allowed characters is much larger. Use `wikifyLink(String)` to get the legacy behaviour.

[ This is a link ] -> This is a link

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

### wikifyLink

public static String wikifyLink(String link)
Cleans away extra legacy characters. This method functions exactly like pre-2.6 cleanLink()

[ 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.6