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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classHolds information about external link domain whitelists. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringContext attribute used to mark when we are in the link processing stage (expanding macros into links).static final StringConstant for the attribute name.static final StringConstant for the attribute name.static final StringConstant for the attribute name.static final StringHTML end.static final StringHTML start.static final StringConstant for the tag name.static final StringConstant for the tag name.static final StringConstant for the tag name.static final StringConstant for the tag name.Fields inherited from class org.opencms.util.CmsHtmlParser
m_echo, m_noAutoCloseTags, m_result, TAG_ARRAY, TAG_LIST -
Constructor Summary
ConstructorsConstructorDescriptionCmsLinkProcessor(CmsObject cms, CmsLinkTable linkTable, String encoding, String relativePath) Creates a new link processor. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringescapeLink(String source) Escapes allinvalid input: '&', e.g.Gets the list of site roots of sites in OpenCms which should be considered as internal, in the sense of not having to mark the corresponding link tags with the external link marker.Returns the link table this link processor was initialized with.protected voidprocessAreaTag(org.htmlparser.Tag tag) Process an area tag.protected voidprocessEmbedTag(org.htmlparser.Tag tag) Process an embed tag.protected voidprocessImageTag(org.htmlparser.tags.ImageTag tag) Process an image tag.protected voidprocessLink(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 voidprocessLinkTag(org.htmlparser.tags.LinkTag tag) Process a link tag.protected voidprocessObjectTag(org.htmlparser.tags.ObjectTag tag) Process an object tag.replaceLinks(String content) Starts link processing for the given content in replacement mode.protected voidsetAltAttributeFromTitle(org.htmlparser.Tag tag, String internalUri) Ensures that the given tag has the "alt" attribute set.static booleanshouldMarkAsExternal(CmsObject cms, CmsADEConfigData sitemapConfig, CmsLink link) Checks if the link should be marked as external.static StringunescapeLink(String source) Unescapes all&, that is replaces them with ainvalid input: '&'.voidvisitTag(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, visitStringNodeMethods inherited from class org.htmlparser.visitors.NodeVisitor
beginParsing, finishedParsing, shouldRecurseChildren, shouldRecurseSelf
-
Field Details
-
ATTR_IS_PROCESSING_LINKS
Context attribute used to mark when we are in the link processing stage (expanding macros into links).- See Also:
-
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 allinvalid input: '&', e.g. replaces them with a&.- Parameters:
source- the String to escape- Returns:
- the escaped String
-
getExternalLinkWhitelistInfo
public static CmsLinkProcessor.ExternalLinkWhitelistInfo getExternalLinkWhitelistInfo(CmsObject cms) Gets the list of site roots of sites in OpenCms which should be considered as internal, in the sense of not having to mark the corresponding link tags with the external link marker.- Parameters:
cms- the current CMS context- Returns:
- the external link whitelist site roots
-
shouldMarkAsExternal
public static boolean shouldMarkAsExternal(CmsObject cms, CmsADEConfigData sitemapConfig, CmsLink link) Checks if the link should be marked as external.- Parameters:
cms- the current CMS contextsitemapConfig- the current sitemap configurationlink- the link to check- Returns:
- true if the link should be be marked as external
-
unescapeLink
Unescapes all&, that is replaces them with ainvalid input: '&'.- 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:
visitTagin interfaceI_CmsHtmlNodeVisitor- Overrides:
visitTagin 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
-