com.xpn.xwiki.content.parsers
Class LinkParser

java.lang.Object
  extended by com.xpn.xwiki.content.parsers.LinkParser
All Implemented Interfaces:
ContentParser

public class LinkParser
extends Object
implements ContentParser

Parses wiki links in the format defined in Link.

Version:
$Id: 7da440efd05192eaeb607f0e4a79c6774944af85 $
See Also:
Link

Constructor Summary
LinkParser()
           
 
Method Summary
 Link parse(String contentToParse)
          Parse the raw content representing a Wiki link (as typed by the user) and transfer it into a structured form as a Link Object.
protected  void parseAlias(StringBuffer content, Link link)
          Find out the alias part of the full link.
protected  String parseElementAfterString(StringBuffer content, String separator)
          Find out the element located to the right of the passed separator.
protected  String parseElementBeforeString(StringBuffer content, String separator)
          Find out the element located to the left of the passed separator.
protected  void parseTarget(StringBuffer content, Link link)
          Find out the target part of the full link.
protected  URI parseURI(StringBuffer content)
          Find out the URI part of the full link.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinkParser

public LinkParser()
Method Detail

parse

public Link parse(String contentToParse)
           throws ContentParserException
Parse the raw content representing a Wiki link (as typed by the user) and transfer it into a structured form as a Link Object.

Parameters:
contentToParse - the raw content to parse. This is the link content without the square brackets.
Returns:
a Link object containing the parsed data
Throws:
ContentParserException - in case of an error while parsing, like a malformed element for example

parseAlias

protected void parseAlias(StringBuffer content,
                          Link link)
Find out the alias part of the full link.

Note: As it's possible to specify a target we need a way to differentiate the following 2 links:

The rule we have chosen is to force targets to start with an underscore character ("_").

Parameters:
content - the string to parse. This parameter will be modified by the method to remove the parsed content.
link - the link on which to set the alias and the delimiter symbol used

parseTarget

protected void parseTarget(StringBuffer content,
                           Link link)
                    throws ContentParserException
Find out the target part of the full link.

Note: The target element must start with an underscore ("_"). See parseAlias(StringBuffer, Link) for more details as to why.

Parameters:
content - the string to parse. This parameter will be modified by the method to remove the parsed content.
link - the link on which to set the target and the delimiter symbol used
Throws:
ContentParserException - if the target does not start with an underscore

parseURI

protected URI parseURI(StringBuffer content)
                throws ContentParserException
Find out the URI part of the full link. Supported URIs are either "mailto:" or any URL in the form "protocol://".

Parameters:
content - the string to parse. This parameter will be modified by the method to remove the parsed content.
Returns:
the parsed URI or null if no URI was specified
Throws:
ContentParserException - if the URI is malformed

parseElementBeforeString

protected String parseElementBeforeString(StringBuffer content,
                                          String separator)
Find out the element located to the left of the passed separator.

Parameters:
content - the string to parse. This parameter will be modified by the method to remove the parsed content.
separator - the separator string to locate the element
Returns:
the parsed element or null if the separator string wasn't found

parseElementAfterString

protected String parseElementAfterString(StringBuffer content,
                                         String separator)
Find out the element located to the right of the passed separator.

Parameters:
content - the string to parse. This parameter will be modified by the method to remove the parsed content.
separator - the separator string to locate the element
Returns:
the parsed element or null if the separator string wasn't found


Copyright © 2004–2014 XWiki. All rights reserved.