com.xpn.xwiki.content
Class Link
java.lang.Object
com.xpn.xwiki.content.Link
- All Implemented Interfaces:
- Cloneable
public class Link
- extends Object
- implements Cloneable
Represents the parsed data of a wiki link. The XWiki link format is as follows:
(alias[|>])(link)(@interWikiAlias)(|target)
, where:
alias
: An optional string which will be displayed to the user as the link
name when rendered. Example: "My Page".
link
: The full link reference using the following syntax:
(virtualWikiAlias:)(space.)(reference)(?queryString)(#anchor)
, where:
virtualWikiAlias
: An optional string containing the name of a virtual
wiki. The link will point to a page inside that virtual wiki. Example: "mywiki".
space
: An optional Wiki Space name. Example: "Main".
reference
: The link reference. This can be either a URI in the form
protocol:path
(example: "http://xwiki.org", "mailto:john@smith.com) or
a wiki page name (example: "WebHome").
queryString
: An optional query string for specifying parameters that
will be used in the rendered URL. Example: "mydata1=5&mydata2=Hello".
anchor
: An optional anchor name pointing to an anchor defined in the
referenced link. Note that in XWiki anchors are automatically created for titles.
Example: "TableOfContentAnchor".
Either the link
or the alias
must be specified.
interWikiAlias
: An optional
Inter Wiki alias as defined in the
InterWiki Map. Example: "wikipedia"
target
: An optional string corresponding to the HTML target
attribute for a a
element. This element is used when rendering the link. It
defaults to opening the link in the current page. Example: "_self", "_blank"
Examples of valid wiki links:
- Hello World
- Hello World>HelloWorld
- Hello World>HelloWorld>_blank
- Hello World>http://myserver.com/HelloWorld
- Hello World>HelloWorld#Anchor
- http://myserver.com
- Hello World@Wikipedia
- mywiki:HelloWorld
- Hello World?param1=1¶m2=2
- Version:
- $Id: 69aeaf2776bf3dd35a485b896bf87f088ab4dfdc $
Constructor Summary |
Link()
|
Link
public Link()
setAlias
public void setAlias(String alias)
- Parameters:
alias
- see getAlias()
getAlias
public String getAlias()
- Returns:
- the string which will be displayed to the user when the link is rendered or null
if no alias has been specified (in that case the page name or the URI will be
displayed. Example: "My Page"
setTarget
public void setTarget(String target)
- Parameters:
target
- see getTarget()
getTarget
public String getTarget()
- Returns:
- the browser window in which the link should be opened into or null if not defined.
This element corresponds to the HTML
target
attribute for the
a
element. It is used when rendering the link and defauts to opening
the link in the current page. Example: "_self", "_blank".
setVirtualWikiAlias
public void setVirtualWikiAlias(String virtualWikiAlias)
- Parameters:
virtualWikiAlias
- see getVirtualWikiAlias()
getVirtualWikiAlias
public String getVirtualWikiAlias()
- Returns:
- the name of the virtual wiki to which the link is pointing to or null if the link
is pointing to the current wiki. Example: "mywiki"
setSpace
public void setSpace(String space)
- Parameters:
space
- see getSpace()
getSpace
public String getSpace()
- Returns:
- the wiki Space name in which the link points to or null if not defined (in that case
the link points to the current space). Example: "Main"
setInterWikiAlias
public void setInterWikiAlias(String interWikiAlias)
- Parameters:
interWikiAlias
- see getInterWikiAlias()
getInterWikiAlias
public String getInterWikiAlias()
- Returns:
- the Inter Wiki alias to which
the link is pointing to or null if not defined. Mappings between Inter Wiki aliases
and actual locations are defined in the Inter Wiki Map. Example: "wikipedia"
setAnchor
public void setAnchor(String anchor)
- Parameters:
anchor
- see getAnchor()
getAnchor
public String getAnchor()
- Returns:
- the anchor name pointing to an anchor defined in the referenced link or null if no
anchor has been specified (in which case the link points to the top of the page).
Note that in XWiki anchors are automatically created for titles.
Example: "TableOfContentAnchor"
setQueryString
public void setQueryString(String queryString)
- Parameters:
queryString
- see getQueryString()
getQueryString
public String getQueryString()
- Returns:
- the query string for specifying parameters that will be used in the rendered URL or
null if no query string has been specified. Example: "mydata1=5&mydata2=Hello"
setPage
public void setPage(String page)
- Parameters:
page
- see getPage()
getPage
public String getPage()
- Returns:
- the Wiki page pointed to by this link or null if the link is pointing to an external
URI. Example: "WebHome".
setURI
public void setURI(URI uri)
- Parameters:
uri
- see getURI()
getURI
public URI getURI()
- Returns:
- the URI this link is pointing to. Valid URIs are mailto links
(Example: "mailto:john@smith.com") or URL (Example: "http://www.xwiki.org").
isUsingPipeDelimiter
public boolean isUsingPipeDelimiter()
- Returns:
- true if the link is using the Pipe symbol ("|") as its separator between alias,
target and link name, or false if it's using the greater than symbol (">")
setUsePipeDelimiterSymbol
public void setUsePipeDelimiterSymbol(boolean isUsingPipeDelimiter)
- Parameters:
isUsingPipeDelimiter
- see isUsingPipeDelimiter()
toString
public String toString()
- Overrides:
toString
in class Object
isExternal
public boolean isExternal()
- Returns:
- true if the link is external (ie it's not a link on the current local wiki) or false
otherwise
getNormalizedLink
public Link getNormalizedLink(String currentSpace)
- Perform a series of normalization steps on the link. The steps are:
- if the link is not a URI and it doesn't have a page defined then make it point to
WebHome
- if the link is internal and doesn't have a space defined, fill it in with the current
document's space name
- Parameters:
currentSpace
- the space to use when no space has been defined in the link
- Returns:
- the normalized link
Copyright © 2004-2013 XWiki. All Rights Reserved.