org.opencms.staticexport
Class CmsLinkProcessor

java.lang.Object
  extended byorg.htmlparser.visitors.NodeVisitor
      extended byorg.opencms.util.CmsHtmlParser
          extended byorg.opencms.staticexport.CmsLinkProcessor
All Implemented Interfaces:
I_CmsHtmlNodeVisitor

public class CmsLinkProcessor
extends CmsHtmlParser

Implements the HTML parser node visitor pattern to exchange all links on the page.

Since:
6.0.0
Version:
$Revision: 1.47 $
Author:
Alexander Kandzior

Field Summary
static java.lang.String HTML_END
          HTML end.
static java.lang.String HTML_START
          HTML start.
 
Fields inherited from class org.opencms.util.CmsHtmlParser
m_echo, m_result, TAG_ARRAY, TAG_LIST
 
Constructor Summary
CmsLinkProcessor(CmsObject cms, CmsLinkTable linkTable, java.lang.String encoding, java.lang.String relativePath)
          Creates a new link processor.
 
Method Summary
static java.lang.String escapeLink(java.lang.String source)
          Escapes all &, e.g. replaces them with a &.
 CmsLinkTable getLinkTable()
          Returns the link table this link processor was initialized with.
protected  void processImageTag(org.htmlparser.tags.ImageTag tag)
          Process an image tag.
 java.lang.String processLinks(java.lang.String content)
          Starts link processing for the given content in processing mode.
protected  void processLinkTag(org.htmlparser.tags.LinkTag tag)
          Process a link tag.
 java.lang.String replaceLinks(java.lang.String content)
          Starts link processing for the given content in replacement mode.
static java.lang.String unescapeLink(java.lang.String source)
          Unescapes all &, that is replaces them with a &.
 void visitTag(org.htmlparser.Tag tag)
          Visitor method to process a tag (start).
 
Methods inherited from class org.opencms.util.CmsHtmlParser
collapse, getConfiguration, getNoAutoCloseTags, getResult, getTagHtml, process, setConfiguration, setNoAutoCloseTags, visitEndTag, visitRemarkNode, visitStringNode
 
Methods inherited from class org.htmlparser.visitors.NodeVisitor
beginParsing, finishedParsing, shouldRecurseChildren, shouldRecurseSelf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTML_END

public static final java.lang.String HTML_END
HTML end.

See Also:
Constant Field Values

HTML_START

public static final java.lang.String HTML_START
HTML start.

See Also:
Constant Field Values
Constructor Detail

CmsLinkProcessor

public CmsLinkProcessor(CmsObject cms,
                        CmsLinkTable linkTable,
                        java.lang.String encoding,
                        java.lang.String relativePath)
Creates a new link processor.

Parameters:
cms - the cms object
linkTable - the link table to use
encoding - the encoding to use for parsing the HTML content
relativePath - additional path for links with relative path (only used in "replace" mode)
Method Detail

escapeLink

public static java.lang.String escapeLink(java.lang.String source)
Escapes all &, e.g. replaces them with a &.

Parameters:
source - the String to escape
Returns:
the escaped String

unescapeLink

public static java.lang.String unescapeLink(java.lang.String source)
Unescapes all &, that is replaces them with a &.

Parameters:
source - the String to unescape
Returns:
the unescaped String

getLinkTable

public CmsLinkTable getLinkTable()
Returns the link table this link processor was initialized with.

Returns:
the link table this link processor was initialized with

processLinks

public java.lang.String processLinks(java.lang.String content)
                              throws org.htmlparser.util.ParserException
Starts link processing for the given content in processing mode.

Macros are replaced by links.

Parameters:
content - the content to process
Returns:
the processed content with replaced macros
Throws:
org.htmlparser.util.ParserException - if something goes wrong

replaceLinks

public java.lang.String replaceLinks(java.lang.String content)
                              throws org.htmlparser.util.ParserException
Starts link processing for the given content in replacement mode.

Links are replaced by macros.

Parameters:
content - the content to process
Returns:
the processed content with replaced links
Throws:
org.htmlparser.util.ParserException - if something goes wrong

visitTag

public void visitTag(org.htmlparser.Tag tag)
Visitor method to process a tag (start).

Specified by:
visitTag in interface I_CmsHtmlNodeVisitor
Overrides:
visitTag in class CmsHtmlParser
Parameters:
tag - the tag to process
See Also:
I_CmsHtmlNodeVisitor.visitTag(org.htmlparser.Tag)

processImageTag

protected void processImageTag(org.htmlparser.tags.ImageTag tag)
Process an image tag.

Parameters:
tag - the tag to process

processLinkTag

protected void processLinkTag(org.htmlparser.tags.LinkTag tag)
Process a link tag.

Parameters:
tag - the tag to process