Package org.opencms.staticexport
Class CmsLinkProcessor
java.lang.Object
org.htmlparser.visitors.NodeVisitor
org.opencms.util.CmsHtmlParser
org.opencms.staticexport.CmsLinkProcessor
- All Implemented Interfaces:
I_CmsHtmlNodeVisitor
Implements the HTML parser node visitor pattern to
exchange all links on the page.
- Since:
- 6.0.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Constant for the attribute name.static final String
Constant for the attribute name.static final String
Constant for the attribute name.static final String
HTML end.static final String
HTML start.static final String
Constant for the tag name.static final String
Constant for the tag name.static final String
Constant for the tag name.static final String
Constant for the tag name.Fields inherited from class org.opencms.util.CmsHtmlParser
m_echo, m_noAutoCloseTags, m_result, TAG_ARRAY, TAG_LIST
-
Constructor Summary
ConstructorDescriptionCmsLinkProcessor
(CmsObject cms, CmsLinkTable linkTable, String encoding, String relativePath) Creates a new link processor. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
escapeLink
(String source) Escapes all&
, e.g.Returns the link table this link processor was initialized with.protected void
processAreaTag
(org.htmlparser.Tag tag) Process an area tag.protected void
processEmbedTag
(org.htmlparser.Tag tag) Process an embed tag.protected void
processImageTag
(org.htmlparser.tags.ImageTag tag) Process an image tag.protected void
processLink
(org.htmlparser.Tag tag, String attr, CmsRelationType type) Process a tag having a link in the given attribute, considering the link as the given type.processLinks
(String content) Starts link processing for the given content in processing mode.protected void
processLinkTag
(org.htmlparser.tags.LinkTag tag) Process a link tag.protected void
processObjectTag
(org.htmlparser.tags.ObjectTag tag) Process an object tag.replaceLinks
(String content) Starts link processing for the given content in replacement mode.protected void
setAltAttributeFromTitle
(org.htmlparser.Tag tag, String internalUri) Ensures that the given tag has the "alt" attribute set.static String
unescapeLink
(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, configureNoAutoCorrectionTags, getConfiguration, getNoAutoCloseTags, getResult, getTagHtml, process, setConfiguration, setNoAutoCloseTags, visitEndTag, visitRemarkNode, visitStringNode
Methods inherited from class org.htmlparser.visitors.NodeVisitor
beginParsing, finishedParsing, shouldRecurseChildren, shouldRecurseSelf
-
Field Details
-
ATTRIBUTE_HREF
Constant for the attribute name.- See Also:
-
ATTRIBUTE_SRC
Constant for the attribute name.- See Also:
-
ATTRIBUTE_VALUE
Constant for the attribute name.- See Also:
-
HTML_END
HTML end.- See Also:
-
HTML_START
HTML start.- See Also:
-
TAG_AREA
Constant for the tag name.- See Also:
-
TAG_EMBED
Constant for the tag name.- See Also:
-
TAG_IFRAME
Constant for the tag name.- See Also:
-
TAG_PARAM
Constant for the tag name.- See Also:
-
-
Constructor Details
-
CmsLinkProcessor
public CmsLinkProcessor(CmsObject cms, CmsLinkTable linkTable, String encoding, String relativePath) Creates a new link processor.- Parameters:
cms
- the current users OpenCms contextlinkTable
- the link table to useencoding
- the encoding to use for parsing the HTML contentrelativePath
- additional path for links with relative path (only used in "replace" mode)
-
-
Method Details
-
escapeLink
Escapes all&
, e.g. replaces them with a&
.- Parameters:
source
- the String to escape- Returns:
- the escaped String
-
unescapeLink
Unescapes all&
, that is replaces them with a&
.- Parameters:
source
- the String to unescape- Returns:
- the unescaped String
-
getLinkTable
Returns the link table this link processor was initialized with.- Returns:
- the link table this link processor was initialized with
-
processLinks
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
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
Visitor method to process a tag (start).- Specified by:
visitTag
in interfaceI_CmsHtmlNodeVisitor
- Overrides:
visitTag
in classCmsHtmlParser
- Parameters:
tag
- the tag to process- See Also:
-
processAreaTag
Process an area tag.- Parameters:
tag
- the tag to process
-
processEmbedTag
Process an embed tag.- Parameters:
tag
- the tag to process
-
processImageTag
Process an image tag.- Parameters:
tag
- the tag to process
-
processLink
Process a tag having a link in the given attribute, considering the link as the given type.- Parameters:
tag
- the tag to processattr
- the attributetype
- the link type
-
processLinkTag
Process a link tag.- Parameters:
tag
- the tag to process
-
processObjectTag
Process an object tag.- Parameters:
tag
- the tag to process
-
setAltAttributeFromTitle
Ensures that the given tag has the "alt" attribute set.if not set, it will be set from the title of the given resource.
- Parameters:
tag
- the tag to set the alt attribute forinternalUri
- the internal URI to get the title from
-