Parses JSPWiki-style "augmented" link markup into a Link object containing the link text, link reference, and any optional link attributes (as JDOM Attributes).
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.
<!ELEMENT A - - (%inline;)* -(A) -- anchor --> <!ATTLIST A %attrs; -- %coreattrs, %i18n, %events -- charset %Charset; #IMPLIED -- char encoding of linked resource -- type %ContentType; #IMPLIED -- advisory content type -- name CDATA #IMPLIED -- named link end -- href %URI; #IMPLIED -- URI for linked resource -- hreflang %LanguageCode; #IMPLIED -- language code -- rel %LinkTypes; #IMPLIED -- forward link types -- rev %LinkTypes; #IMPLIED -- reverse link types -- accesskey %Character; #IMPLIED -- accessibility key character -- shape %Shape; rect -- for use with client-side image maps -- coords %Coords; #IMPLIED -- for use with client-side image maps -- tabindex NUMBER #IMPLIED -- position in tabbing order -- onfocus %Script; #IMPLIED -- the element got the focus -- onblur %Script; #IMPLIED -- the element lost the focus -- >
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: 'id', 'class', 'style', 'title' (from %coreattrs;); 'lang', 'dir' (from %i18n;); as well as 'accesskey', 'charset', 'hreflang', 'rel', 'rev', 'tabindex', 'target' , and 'type'. The declared attributes that will be ignored are: 'href', 'name', 'shape', 'coords', 'onfocus', 'onblur', or any of the other 'on*' event attributes. 'name' is not permitted in preference to 'id' (which should nowadays be used as its replacement).
This means that the list of permitted attributes includes (with their HTML 4 definitions):
Some of these could have real use on a wiki; others are more questionable. But being able to add IDs and titles is pretty helpful, with 'style' perhaps to highlight a link, and how to include target has been asked for a few times on the mailing list. Since permitted attributes are just passed along in the construction of normal HTML markup, whatever functionality they provide (i.e., whatever support a browser provides) is the same as any use of those attributes.
Note that the difference between 'lang' and 'hreflang' is that the former notes the language of the link text, the latter the language of the document at the end of the traversed link.
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). If you find an attribute is being abused by your users (e.g., 'style'), alter the list and recompile.
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.!! Examples
NOTE: these examples won't work correctly until jspwiki.org site is using version 2.5.13 or later. The current version running on this site is 2.11.3.! Example: Link Form 1
From an incoming wikitext link of:
[WikiEtiquette]WikiEtiquette
returns:
getText(): "WikiEtiquette" getReference(): "WikiEtiquette" attributeCount(): 0 getAttributes(): an empty Iterator
From an incoming wikitext link of:
[Acme | http://www.acme.com/]Acme
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/ | target='_blank' title='Purveyors of fine freeware since 1972. On the net since 1991.']Acme
returns:
getText(): "Acme" getReference(): "http://www.acme.com/" attributeCount(): 2 getAttributes(): an Iterator containing: JDOM Attribute: target="_blank" JDOM Attribute: title="Purveyors of fine freeware since 1972. On the net since 1991."