Package org.apache.wiki.parser

# Class LinkParser.Link

java.lang.Object
org.apache.wiki.parser.LinkParser.Link

Enclosing class:
  LinkParser

public static class LinkParser.Link extends Object
Inner class serving as a struct containing the parsed components of a link.

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`Link(String text)`
Create a new Link with text but no reference.
`protected`
`Link(String text, String ref)`
Create a new link with a given text and hyperlink (reference).

## Method Summary

Modifier and Type
Method
Description
`void`
`addAttribute(org.jdom2.Attribute attr)`
Adds another attribute to the link.
`int`
`attributeCount()`
Returns the number of attributes on this link.
`Iterator<org.jdom2.Attribute>`
`getAttributes()`
Returns an Iterator over the list of JDOM Attributes.
`String`
`getExternalWiki()`
Returns the name of the wiki if this is an interwiki link.
`String`
`getExternalWikiPage()`
Returns the wikiname part of an interwiki link.
`String`
`getReference()`
Returns the link reference, or the link text if null.
`String`
`getText()`
Returns the link text.
`boolean`
`hasReference()`
Returns true, if there is a reference.
`boolean`
`isInterwikiLink()`
Returns true, if this Link represents an InterWiki link (of the form wiki:page).
`protected void`
`setReference(String ref)`
Sets the hypertext reference.
`protected void`
`setText(String text)`
Sets the link text.
`String`
`toString()`
Returns a wikitext string representation of this Link.

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

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

## Constructor Details

### Link

protected Link(String text) throws ParseException
Create a new Link with text but no reference.

Parameters:
  `text` - The link text.
Throws:
  `ParseException` - If the link text is illegal.

### Link

protected Link(String text, String ref) throws ParseException
Create a new link with a given text and hyperlink (reference).

Parameters:
  `text` - The link text.
  `ref` - The hypertext reference.
Throws:
  `ParseException` - If the link text or reference are illegal.

## Method Details

### setText

protected void setText(String text) throws ParseException
Sets the link text.

Parameters:
  `text` - The link text.
Throws:
  `ParseException` - If the text is illegal (e.g. null).

### getText

public String getText()
Returns the link text.

Returns:
  Link text.

### setReference

protected void setReference(String ref) throws ParseException
Sets the hypertext reference. Typically, this is an URI or an interwiki link, or a wikilink.

Parameters:
  `ref` - The reference.
Throws:
  `ParseException` - If the reference is illegal.

### hasReference

public boolean hasReference()
Returns true, if there is a reference.

Returns:
  True, if there's a reference; false otherwise.

### getReference

public String getReference()
Returns the link reference, or the link text if null.

Returns:
  A link reference.

### isInterwikiLink

public boolean isInterwikiLink()
Returns true, if this Link represents an InterWiki link (of the form wiki:page).

Returns:
  True, if this Link represents an InterWiki link.

### getExternalWiki

public String getExternalWiki()
Returns the name of the wiki if this is an interwiki link.

        Link link = new Link("Foo","Wikipedia:Foobar");
        assert( link.getExternalWikiPage(), "Wikipedia" );

Returns:
  Name of the wiki, or null, if this is not an interwiki link.

### getExternalWikiPage

public String getExternalWikiPage()
Returns the wikiname part of an interwiki link. Used only with interwiki links.

        Link link = new Link("Foo","Wikipedia:Foobar");
        assert( link.getExternalWikiPage(), "Foobar" );

Returns:
  Wikiname part, or null, if this is not an interwiki link.

### attributeCount

public int attributeCount()
Returns the number of attributes on this link.

Returns:
  The number of attributes.

### addAttribute

public void addAttribute(org.jdom2.Attribute attr)
Adds another attribute to the link.

Parameters:
  `attr` - A JDOM Attribute.

### getAttributes

public Iterator<org.jdom2.Attribute> getAttributes()
Returns an Iterator over the list of JDOM Attributes.

Returns:
  Iterator over the attributes.

### toString

public String toString()
Returns a wikitext string representation of this Link.

Overrides:
  `toString` in class `Object`
Returns:
  WikiText.