public class TemplateParser extends AbstractParser
for the second pass| Modifier and Type | Field and Description |
|---|---|
protected static org.slf4j.Logger |
logger |
static String |
TEMPLATE_PARSER_ERROR |
fCurrentCharacter, fCurrentPosition, fWhiteStart, fWhiteStartPositionEOF, fScannerPosition, fSource, fStringSource, fWikiModel| Constructor and Description |
|---|
TemplateParser(String stringSource) |
TemplateParser(String stringSource,
boolean parseOnlySignature,
boolean renderTemplate) |
TemplateParser(String stringSource,
boolean parseOnlySignature,
boolean renderTemplate,
boolean onlyIncludeFlag) |
| Modifier and Type | Method and Description |
|---|---|
static int |
checkParserFunction(CharSequence plainContent)
Check if this template contains a template function
Note: repositions this#fCurrentPosition behind the parser function string
if possible
|
static Object[] |
createParameterMap(char[] src,
int startOffset,
int len)
Create a map from the parameters defined in a template call
|
static Map<String,String> |
createParameterMap(Object[] objs,
IWikiModel model) |
static void |
createSingleParameter(String srcString,
IWikiModel wikiModel,
Map<String,String> namedParameterMap,
List<String> unnamedParams)
Create a single parameter, defined in a template call, and add it to the
named parameters map or unnamed parameter list
|
static TemplateTag |
createTemplateTag(char[] src,
int startOffset,
int len,
IWikiModel model)
Create a
TemplateTag from the passed template call. |
static void |
mergeParameters(LinkedHashMap<String,String> parameterMap,
List<String> unnamedParameters)
If template calls have a mix between named and unnamed parameters, the
collected
unnamedParameters are merged into the
parameterMap. |
static void |
parse(String rawWikitext,
IWikiModel wikiModel,
Appendable writer,
boolean renderTemplate) |
static void |
parse(String rawWikitext,
IWikiModel wikiModel,
Appendable writer,
boolean parseOnlySignature,
boolean renderTemplate)
Parse the wiki texts templates, comments and signatures into the given
StringBuilder. |
protected boolean |
parseHTMLCommentTags(Appendable writer) |
static boolean |
parsePreprocessRecursive(int startIndex,
String rawWikitext,
IWikiModel wikiModel,
StringBuilder writer,
boolean renderTemplate,
boolean onlyIncludeFlag,
Map<String,String> templateParameterMap)
Preprocess parsing of the
<includeonly>,
<onlyinclude> and <noinclude> tags. |
protected static void |
parseRecursive(String rawWikitext,
IWikiModel wikiModel,
Appendable writer,
boolean parseOnlySignature,
boolean renderTemplate) |
static void |
parseRecursive(String rawWikitext,
IWikiModel wikiModel,
Appendable writer,
boolean parseOnlySignature,
boolean renderTemplate,
Map<String,String> templateParameterMap) |
StringBuilder |
replaceTemplateParameters(Map<String,String> templateParameters,
int curlyBraceOffset)
Replace the wiki template parameters in the given template string
|
protected void |
runPreprocessParser(int whiteStartPosition,
int currentPosition,
StringBuilder writer,
boolean ignoreTemplateTags)
Preprocess parsing of the
<includeonly>,
<onlyinclude> and <noinclude> tags,
HTML comments and <nowiki>, <source>
and <math> tags. |
protected void |
runPreprocessParser(StringBuilder writer,
boolean ignoreTemplateTags)
Preprocess parsing of the
<includeonly>,
<onlyinclude> and <noinclude> tags,
HTML comments and <nowiki>, <source>
and <math> tags. |
consumeWhitespace, findWikiLinkEnd, getNextChar, getNextCharAsWhitespace, isEmptyLine, readUntil, readUntilCharOrStopAtEOL, readUntilIgnoreCase, readUntilNestedIgnoreCase, readWhitespaceUntilEndOfLine, readWhitespaceUntilStartOfLinefindNestedEnd, findNestedEndSingle, findNestedParamEnd, findNestedTemplateEnd, getPosition, indexEndOfComment, indexEndOfNowiki, indexEndOfTable, indexOfUntilNoLetter, makeTag, nextNewline, nextNewlineCell, parseAttributes, parseTag, readSpecialWikiTags, readUntilIgnoreCase, setModel, setPosition, splitByChar, splitByChar, splitByPipe, splitByPipe, startsWith, wpList, wpTablepublic static final String TEMPLATE_PARSER_ERROR
protected static org.slf4j.Logger logger
public TemplateParser(String stringSource)
public TemplateParser(String stringSource, boolean parseOnlySignature, boolean renderTemplate)
public TemplateParser(String stringSource, boolean parseOnlySignature, boolean renderTemplate, boolean onlyIncludeFlag)
public static void parse(String rawWikitext, IWikiModel wikiModel, Appendable writer, boolean renderTemplate) throws IOException
IOExceptionpublic static void parse(String rawWikitext, IWikiModel wikiModel, Appendable writer, boolean parseOnlySignature, boolean renderTemplate) throws IOException
StringBuilder.rawWikitext - wikiModel - writer - parseOnlySignature - change only the signature string and ignore templates and comments
parsingrenderTemplate - IOExceptionprotected static void parseRecursive(String rawWikitext, IWikiModel wikiModel, Appendable writer, boolean parseOnlySignature, boolean renderTemplate) throws IOException
IOExceptionpublic static boolean parsePreprocessRecursive(int startIndex,
String rawWikitext,
IWikiModel wikiModel,
StringBuilder writer,
boolean renderTemplate,
boolean onlyIncludeFlag,
Map<String,String> templateParameterMap)
throws IOException
<includeonly>,
<onlyinclude> and <noinclude> tags.
Also performs template parameter substitution.IOExceptionpublic static void parseRecursive(String rawWikitext, IWikiModel wikiModel, Appendable writer, boolean parseOnlySignature, boolean renderTemplate, Map<String,String> templateParameterMap) throws IOException
IOExceptionprotected void runPreprocessParser(StringBuilder writer, boolean ignoreTemplateTags) throws IOException
<includeonly>,
<onlyinclude> and <noinclude> tags,
HTML comments and <nowiki>, <source>
and <math> tags.writer - ignoreTemplateTags - don't parse special template tags like <includeonly>,
<noinclude>, <onlyinclude>IOExceptionprotected void runPreprocessParser(int whiteStartPosition,
int currentPosition,
StringBuilder writer,
boolean ignoreTemplateTags)
throws IOException
<includeonly>,
<onlyinclude> and <noinclude> tags,
HTML comments and <nowiki>, <source>
and <math> tags.writer - whiteStartPosition - the position to start the normal content before the first
special template tagcurrentPosition - the position to continue with parsing special template tagsignoreTemplateTags - don't parse special template tags like <includeonly>,
<noinclude>, <onlyinclude>IOExceptionpublic static void mergeParameters(LinkedHashMap<String,String> parameterMap, List<String> unnamedParameters)
unnamedParameters are merged into the
parameterMap.
See Help:Template#Mix_of_named_and_unnamed_parameterspublic static Object[] createParameterMap(char[] src, int startOffset, int len)
java.util.List at index [0]
and the template name at index [1]public static TemplateTag createTemplateTag(char[] src, int startOffset, int len, IWikiModel model)
TemplateTag from the passed template call.public static Map<String,String> createParameterMap(Object[] objs, IWikiModel model)
public static void createSingleParameter(String srcString, IWikiModel wikiModel, Map<String,String> namedParameterMap, List<String> unnamedParams)
See Help:Template: Remember that whitespace characters (spaces, tabs, carriage returns and line feeds) are not automatically stripped from the start and end of unnamed parameters (as they are from named parameters). Including such characters (or any other non-visible characters in any parameters) may in some cases affect the template's behaviour in unexpected ways. (Template designers can use {{StripWhitespace}} to remove unwanted whitespace in unnamed parameters.)
srcString - namedParameterMap - a key/value pairs for name and value of a template parameterunnamedParams - a list of unnamed parameter valuespublic static int checkParserFunction(CharSequence plainContent)
plainContent - -1 if no parser function can
be found in this template.protected boolean parseHTMLCommentTags(Appendable writer) throws IOException
IOException@Nullable public StringBuilder replaceTemplateParameters(@Nullable Map<String,String> templateParameters, int curlyBraceOffset)
templateParameters - curlyBraceOffset - TODOtemplate - null if no replacement could be foundCopyright © 2017 Java Wikipedia API (Bliki engine). All rights reserved.