Class CmsHtmlValidator

java.lang.Object
org.htmlparser.visitors.NodeVisitor
org.opencms.util.CmsHtmlValidator

public class CmsHtmlValidator extends org.htmlparser.visitors.NodeVisitor
Validates HTML.

  • Constructor Details

  • Method Details

    • getMessages

      Returns the validation error messages.

      Returns:
      the error messages
    • getRootElementCount

      public int getRootElementCount()
      Returns the number of root elements.

      Returns:
      the number of root elements
    • isBalanced

      public boolean isBalanced()
      Returns whether the validated HTML is balanced.

      Returns:
      true in case the validated HTML is balanced
    • validate

      public void validate(String html) throws org.htmlparser.util.ParserException
      Validates the given HTML string.

      Parameters:
      html - the HTML to validate
      Throws:
      org.htmlparser.util.ParserException - in case parsing fails
    • visitEndTag

      public void visitEndTag(org.htmlparser.Tag tag)
      Overrides:
      visitEndTag in class org.htmlparser.visitors.NodeVisitor
      See Also:
      • NodeVisitor.visitEndTag(org.htmlparser.Tag)
    • visitTag

      public void visitTag(org.htmlparser.Tag tag)
      Overrides:
      visitTag in class org.htmlparser.visitors.NodeVisitor
      See Also:
      • NodeVisitor.visitTag(org.htmlparser.Tag)
    • configureNoAutoCorrectionTags

      protected org.htmlparser.PrototypicalNodeFactory configureNoAutoCorrectionTags()
      Internally degrades Composite tags that do have children in the DOM tree to simple single tags. This allows to avoid auto correction of unclosed HTML tags.

      Returns:
      A node factory that will not auto correct open tags