Package org.xwiki.validator.framework
Class AbstractHTML5Validator
- java.lang.Object
-
- org.xwiki.validator.framework.AbstractXMLValidator
-
- org.xwiki.validator.framework.AbstractHTML5Validator
-
- All Implemented Interfaces:
Validator
- Direct Known Subclasses:
HTML5DutchWebGuidelinesValidator
,XWikiValidator
public abstract class AbstractHTML5Validator extends AbstractXMLValidator
- Version:
- $Id: f793bcbaf878627f99677b711238127429532ca2 $
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
ATTR_ACCESSKEY
Accesskey attribute.protected static String
ATTR_ALT
Type attribute.protected static String
ATTR_BLUR
Blur attribute.protected static String
ATTR_CHANGE
Change attribute.protected static String
ATTR_CHARSET
Charset attribute.protected static String
ATTR_CLICK
Click attribute.protected static String
ATTR_CONTENT
Content attribute.protected static String
ATTR_FOCUS
Focus attribute.protected static String
ATTR_HREF
Href attribute.protected static String
ATTR_ID
ID attribute.protected static String
ATTR_LOAD
Load attribute.protected static String
ATTR_MOUSEOVER
Mouseover attribute.protected static String
ATTR_ROLE
Role attribute.protected static String
ATTR_SCOPE
Scope attribute.protected static String
ATTR_SELECT
Select attribute.protected static String
ATTR_SRC
Source attribute.protected static String
ATTR_SUBMIT
Submmit attribute.protected static String
ATTR_TITLE
Title attribute.protected static String
ATTR_TYPE
Type attribute.protected static String
ATTR_UNLOAD
Unload attribute.protected static String
BUTTON
Button.protected static String
ELEM_AREA
Area element.protected static String
ELEM_BODY
Body element.protected static String
ELEM_BOLD
Bold element.protected static String
ELEM_BR
Line break element.protected static String
ELEM_FIELDSET
Fieldset element.protected static String
ELEM_FORM
Form element.protected static String
ELEM_FRAME
Frame element.protected static String
ELEM_FRAMESET
Frameset element.protected static String
ELEM_H1
Heading 1 element.protected static String
ELEM_HTML
HTML element.protected static String
ELEM_IFRAME
Iframe element.protected static String
ELEM_IMG
Image element.protected static String
ELEM_INPUT
Input element.protected static String
ELEM_ITALIC
Italics element.protected static String
ELEM_LINK
Link element.protected static String
ELEM_META
Fieldset element.protected static String
ELEM_SUBMIT
Submit element.protected static String
ELEM_TABLE
Table element.protected static String
ELEM_TH
Table Header element.protected static String
HIDDEN
hidden.protected org.jsoup.nodes.Document
html5Document
Document parsed with JSoup.protected static String
IMAGE
Image.protected static String
MAILTO
mailto.protected static String
RESET
Reset.protected static String
STYLE
Style.protected static String
SUBMIT
Submit.-
Fields inherited from class org.xwiki.validator.framework.AbstractXMLValidator
document, documentBuilder, errorHandler
-
-
Constructor Summary
Constructors Constructor Description AbstractHTML5Validator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
assertFalse(ValidationError.Type errorType, String message, boolean condition)
Asserts that a condition is false.protected void
assertTrue(ValidationError.Type errorType, String message, boolean condition)
Asserts that a condition is true.boolean
containsElement(String tagName)
Check if the html5Document contains the given element.static List<String>
getAttributeNames(org.jsoup.nodes.Element element)
Get the names of all the attribute of an element.static String
getAttributeValue(org.jsoup.nodes.Element element, String attributeName)
AbstractDOMValidator Get the value of an element attribute.static List<String>
getAttributeValues(org.jsoup.select.Elements elements, String attributeName)
Retrieve a list of values of an attribute for a list of elements.org.jsoup.select.Elements
getChildren(org.jsoup.nodes.Element element, String tagName)
Get children of a given type.List<String>
getChildrenTagNames(org.jsoup.nodes.Element element)
Get the names of all the children elements of an element.org.jsoup.nodes.Element
getElement(String tagName)
org.jsoup.select.Elements
getElements(String tagName)
Get a list of elements matching a given tag name in the html5Document.org.jsoup.select.Elements
getElements(Collection<String> tagNames)
Get all the elements matching one of the given tags.org.jsoup.nodes.Document
getHTML5Document()
static boolean
hasAttribute(org.jsoup.nodes.Element element, String attributeName)
Check if an element has the given attribute.boolean
hasChildElement(org.jsoup.nodes.Element element, String tagName)
Check if an element has an child element with the given tag name.void
setDocument(InputStream document)
Set document to validate.void
setHTML5Document(InputStream document)
Set document to validate.List<ValidationError>
validate()
Run validation.-
Methods inherited from class org.xwiki.validator.framework.AbstractXMLValidator
addError, clear, createXMLErrorHandler, getDocument, getErrorHandler, getErrors, setValidateXML, validate
-
-
-
-
Field Detail
-
SUBMIT
protected static final String SUBMIT
Submit.- See Also:
- Constant Field Values
-
STYLE
protected static final String STYLE
Style.- See Also:
- Constant Field Values
-
IMAGE
protected static final String IMAGE
Image.- See Also:
- Constant Field Values
-
RESET
protected static final String RESET
Reset.- See Also:
- Constant Field Values
-
BUTTON
protected static final String BUTTON
Button.- See Also:
- Constant Field Values
-
MAILTO
protected static final String MAILTO
mailto.- See Also:
- Constant Field Values
-
HIDDEN
protected static final String HIDDEN
hidden.- See Also:
- Constant Field Values
-
ELEM_HTML
protected static final String ELEM_HTML
HTML element.- See Also:
- Constant Field Values
-
ELEM_BODY
protected static final String ELEM_BODY
Body element.- See Also:
- Constant Field Values
-
ELEM_H1
protected static final String ELEM_H1
Heading 1 element.- See Also:
- Constant Field Values
-
ELEM_BR
protected static final String ELEM_BR
Line break element.- See Also:
- Constant Field Values
-
ELEM_BOLD
protected static final String ELEM_BOLD
Bold element.- See Also:
- Constant Field Values
-
ELEM_ITALIC
protected static final String ELEM_ITALIC
Italics element.- See Also:
- Constant Field Values
-
ELEM_SUBMIT
protected static final String ELEM_SUBMIT
Submit element.- See Also:
- Constant Field Values
-
ELEM_FRAMESET
protected static final String ELEM_FRAMESET
Frameset element.- See Also:
- Constant Field Values
-
ELEM_FRAME
protected static final String ELEM_FRAME
Frame element.- See Also:
- Constant Field Values
-
ELEM_IFRAME
protected static final String ELEM_IFRAME
Iframe element.- See Also:
- Constant Field Values
-
ELEM_LINK
protected static final String ELEM_LINK
Link element.- See Also:
- Constant Field Values
-
ELEM_INPUT
protected static final String ELEM_INPUT
Input element.- See Also:
- Constant Field Values
-
ELEM_IMG
protected static final String ELEM_IMG
Image element.- See Also:
- Constant Field Values
-
ELEM_AREA
protected static final String ELEM_AREA
Area element.- See Also:
- Constant Field Values
-
ELEM_TABLE
protected static final String ELEM_TABLE
Table element.- See Also:
- Constant Field Values
-
ELEM_TH
protected static final String ELEM_TH
Table Header element.- See Also:
- Constant Field Values
-
ELEM_FORM
protected static final String ELEM_FORM
Form element.- See Also:
- Constant Field Values
-
ELEM_FIELDSET
protected static final String ELEM_FIELDSET
Fieldset element.- See Also:
- Constant Field Values
-
ELEM_META
protected static final String ELEM_META
Fieldset element.- See Also:
- Constant Field Values
-
ATTR_TYPE
protected static final String ATTR_TYPE
Type attribute.- See Also:
- Constant Field Values
-
ATTR_ALT
protected static final String ATTR_ALT
Type attribute.- See Also:
- Constant Field Values
-
ATTR_HREF
protected static final String ATTR_HREF
Href attribute.- See Also:
- Constant Field Values
-
ATTR_TITLE
protected static final String ATTR_TITLE
Title attribute.- See Also:
- Constant Field Values
-
ATTR_ROLE
protected static final String ATTR_ROLE
Role attribute.- See Also:
- Constant Field Values
-
ATTR_BLUR
protected static final String ATTR_BLUR
Blur attribute.- See Also:
- Constant Field Values
-
ATTR_CHANGE
protected static final String ATTR_CHANGE
Change attribute.- See Also:
- Constant Field Values
-
ATTR_CLICK
protected static final String ATTR_CLICK
Click attribute.- See Also:
- Constant Field Values
-
ATTR_FOCUS
protected static final String ATTR_FOCUS
Focus attribute.- See Also:
- Constant Field Values
-
ATTR_LOAD
protected static final String ATTR_LOAD
Load attribute.- See Also:
- Constant Field Values
-
ATTR_MOUSEOVER
protected static final String ATTR_MOUSEOVER
Mouseover attribute.- See Also:
- Constant Field Values
-
ATTR_SELECT
protected static final String ATTR_SELECT
Select attribute.- See Also:
- Constant Field Values
-
ATTR_SUBMIT
protected static final String ATTR_SUBMIT
Submmit attribute.- See Also:
- Constant Field Values
-
ATTR_UNLOAD
protected static final String ATTR_UNLOAD
Unload attribute.- See Also:
- Constant Field Values
-
ATTR_ACCESSKEY
protected static final String ATTR_ACCESSKEY
Accesskey attribute.- See Also:
- Constant Field Values
-
ATTR_SCOPE
protected static final String ATTR_SCOPE
Scope attribute.- See Also:
- Constant Field Values
-
ATTR_ID
protected static final String ATTR_ID
ID attribute.- See Also:
- Constant Field Values
-
ATTR_CONTENT
protected static final String ATTR_CONTENT
Content attribute.- See Also:
- Constant Field Values
-
ATTR_CHARSET
protected static final String ATTR_CHARSET
Charset attribute.- See Also:
- Constant Field Values
-
ATTR_SRC
protected static final String ATTR_SRC
Source attribute.- See Also:
- Constant Field Values
-
html5Document
protected org.jsoup.nodes.Document html5Document
Document parsed with JSoup.
-
-
Method Detail
-
setDocument
public void setDocument(InputStream document)
Description copied from interface:Validator
Set document to validate.- Specified by:
setDocument
in interfaceValidator
- Overrides:
setDocument
in classAbstractXMLValidator
- Parameters:
document
- document to validate
-
setHTML5Document
public void setHTML5Document(InputStream document)
Set document to validate.- Parameters:
document
- document to validate
-
getHTML5Document
public org.jsoup.nodes.Document getHTML5Document()
- Returns:
- the parsed html5 document
-
validate
public List<ValidationError> validate()
Description copied from interface:Validator
Run validation.- Specified by:
validate
in interfaceValidator
- Overrides:
validate
in classAbstractXMLValidator
- Returns:
- a list of validation errors
-
assertFalse
protected void assertFalse(ValidationError.Type errorType, String message, boolean condition)
Asserts that a condition is false. If it isn't it puts an error message in the validation results.- Parameters:
errorType
- type of the errormessage
- the message to addcondition
- condition to be checked
-
assertTrue
protected void assertTrue(ValidationError.Type errorType, String message, boolean condition)
Asserts that a condition is true. If it isn't it puts an error message in the validation results.- Parameters:
errorType
- type of the errormessage
- the message to addcondition
- condition to be checked
-
containsElement
public boolean containsElement(String tagName)
Check if the html5Document contains the given element.- Parameters:
tagName
- element to search- Returns:
- true if the html5Document contains the element, false otherwise
-
getElements
public org.jsoup.select.Elements getElements(String tagName)
Get a list of elements matching a given tag name in the html5Document.- Parameters:
tagName
- tag name to search for- Returns:
- the list of matching elements
-
getElements
public org.jsoup.select.Elements getElements(Collection<String> tagNames)
Get all the elements matching one of the given tags.- Parameters:
tagNames
- tag names to match- Returns:
- the list of matching tags
-
hasChildElement
public boolean hasChildElement(org.jsoup.nodes.Element element, String tagName)
Check if an element has an child element with the given tag name.- Parameters:
element
- element to analyzetagName
- tag name to search for- Returns:
- true if the element has an child element with the given tag name
-
getChildren
public org.jsoup.select.Elements getChildren(org.jsoup.nodes.Element element, String tagName)
Get children of a given type.- Parameters:
element
- element to search intagName
- name of the tags to match- Returns:
- a list of matching tags
-
getChildrenTagNames
public List<String> getChildrenTagNames(org.jsoup.nodes.Element element)
Get the names of all the children elements of an element.- Parameters:
element
- parent element- Returns:
- the names of all the children elements of an element.
-
hasAttribute
public static boolean hasAttribute(org.jsoup.nodes.Element element, String attributeName)
Check if an element has the given attribute.- Parameters:
element
- element to analyzeattributeName
- name of the attribute to search- Returns:
- true if the element has the given attribute, false otherwise
-
getAttributeNames
public static List<String> getAttributeNames(org.jsoup.nodes.Element element)
Get the names of all the attribute of an element.- Parameters:
element
- element to analyze- Returns:
- the names of all the attribute of the given element
-
getAttributeValue
public static String getAttributeValue(org.jsoup.nodes.Element element, String attributeName)
AbstractDOMValidator Get the value of an element attribute.- Parameters:
element
- element to analyzeattributeName
- name of the attribute to search- Returns:
- the value of the given attribute
-
getAttributeValues
public static List<String> getAttributeValues(org.jsoup.select.Elements elements, String attributeName)
Retrieve a list of values of an attribute for a list of elements.- Parameters:
elements
- the list of elements to get the attribute fromattributeName
- name of the attribute to retrieve the value from- Returns:
- the list of values of the given attribute for all the elements in the given element list
-
getElement
public org.jsoup.nodes.Element getElement(String tagName)
- Parameters:
tagName
- name of the tag to match- Returns:
- The first element found for the given tag name in the XHTML html5Document.
-
-