Package org.opencms.util
Class CmsHtmlValidator
- java.lang.Object
-
- org.htmlparser.visitors.NodeVisitor
-
- org.opencms.util.CmsHtmlValidator
-
public class CmsHtmlValidator extends org.htmlparser.visitors.NodeVisitor
Validates HTML.
-
-
Constructor Summary
Constructors Constructor Description CmsHtmlValidator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.htmlparser.PrototypicalNodeFactory
configureNoAutoCorrectionTags()
Internally degrades Composite tags that do have children in the DOM tree to simple single tags.java.util.List<CmsMessageContainer>
getMessages()
Returns the validation error messages.int
getRootElementCount()
Returns the number of root elements.boolean
isBalanced()
Returns whether the validated HTML is balanced.void
validate(java.lang.String html)
Validates the given HTML string.void
visitEndTag(org.htmlparser.Tag tag)
void
visitTag(org.htmlparser.Tag tag)
-
-
-
Constructor Detail
-
CmsHtmlValidator
public CmsHtmlValidator()
-
-
Method Detail
-
getMessages
public java.util.List<CmsMessageContainer> 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(java.lang.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 classorg.htmlparser.visitors.NodeVisitor
- See Also:
NodeVisitor.visitEndTag(org.htmlparser.Tag)
-
visitTag
public void visitTag(org.htmlparser.Tag tag)
- Overrides:
visitTag
in classorg.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
-
-