Class CmsLinkProcessor

java.lang.Object
org.htmlparser.visitors.NodeVisitor
org.opencms.util.CmsHtmlParser
org.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
  • Field Details

  • Constructor Details

    • CmsLinkProcessor

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

      Parameters:
      cms - the current users OpenCms context
      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 Details

    • escapeLink

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

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

      public static String unescapeLink(String source)
      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

      public String processLinks(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 String replaceLinks(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:
    • processAreaTag

      protected void processAreaTag(org.htmlparser.Tag tag)
      Process an area tag.

      Parameters:
      tag - the tag to process
    • processEmbedTag

      protected void processEmbedTag(org.htmlparser.Tag tag)
      Process an embed tag.

      Parameters:
      tag - the tag to process
    • processImageTag

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

      Parameters:
      tag - the tag to process
    • processLink

      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.

      Parameters:
      tag - the tag to process
      attr - the attribute
      type - the link type
    • processLinkTag

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

      Parameters:
      tag - the tag to process
    • processObjectTag

      protected void processObjectTag(org.htmlparser.tags.ObjectTag tag)
      Process an object tag.

      Parameters:
      tag - the tag to process
    • setAltAttributeFromTitle

      protected void setAltAttributeFromTitle(org.htmlparser.Tag tag, String internalUri)
      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 for
      internalUri - the internal URI to get the title from