public class LinkParser extends Object
The parser recognizes three link forms:
where the attributes are space-delimited, each in the form of
name1='value1' name2='value2' name3='value3' (etc.)
If the attribute parsing fails, the parser will still return the basic link, writing a warning to the log.
Attributes that aren't declared on <a> or those that permit scripting in HTML (as this is a security risk) are ignored and have no effect on parsing, nor show up in the resulting attribute list). The 'href' and 'name' attributes are also ignored as spurious. The permitted list is: 'accesskey', 'charset', 'class', 'hreflang', 'id', 'lang', 'dir', 'rel', 'rev', 'style' , 'tabindex', 'target' , 'title', and 'type'. The declared attributes that will be ignored are: 'href', 'name', 'shape', 'coords', 'onfocus', 'onblur', or any of the other 'on*' event attributes.
The permitted attributes and target attribute values are static
String arrays (PERMITTED_ATTRIBUTES
and
PERMITTED_TARGET_VALUES
resp.) that could be compile-time
modified (i.e., predeclared).
The following target names are reserved in HTML 4 and have special meanings. These are the only values permitted by the parser.
This returns a Link object, a public inner class with methods:
The attributeCount() method can be used to circumvent calling getAttributes(), which will create an empty Iterator rather than return a null.
From an incoming wikitext link of:
[Acme]returns:
getText(): "Acme" getReference(): "Acme" attributeCount(): 0 getAttributes(): an empty Iterator
From an incoming wikitext link of:
[Acme | http://www.acme.com/]returns:
getText(): "Acme" getReference(): "http://www.acme.com/" attributeCount(): 0 getAttributes(): an empty Iterator
From an incoming wikitext link of:
[Acme | http://www.acme.com/ | id='foo' rel='Next']returns:
getText(): "Acme" getReference(): "http://www.acme.com/" attributeCount(): 2 getAttributes(): an Iterator containing: JDOM Attribute: id="foo" JDOM Attribute: rel="Next"
Modifier and Type | Class and Description |
---|---|
static class |
LinkParser.Link
Inner class serving as a struct containing the parsed
components of a link.
|
Constructor and Description |
---|
LinkParser() |
Modifier and Type | Method and Description |
---|---|
static boolean |
isSpace(char c)
Returns true if char c is a member of
S (space) [XML 1.1 production 3].
|
static boolean |
isSpace(String s)
Returns true if the String s is completely
composed of whitespace.
|
LinkParser.Link |
parse(String linktext)
Processes incoming link text, separating out the link text, the link
URI, and then any specified attributes.
|
public LinkParser()
public LinkParser.Link parse(String linktext) throws ParseException
linktext
- the wiki link text to be parsedParseException
- if the parameter is nullpublic static final boolean isSpace(String s)
s
- The string to checkpublic static final boolean isSpace(char c)
c
- Character to check.Copyright © 2001-2019 The Apache Software Foundation. All rights reserved.