Package io.john.amiscaray.stir.domain
Class HTMLDocument
java.lang.Object
io.john.amiscaray.stir.domain.HTMLDocument
public class HTMLDocument extends Object
A pojo representing an HTML document
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHTMLDocument.ColorThemestatic classHTMLDocument.HTMLDocumentBuilder -
Field Summary
Fields Modifier and Type Field Description private List<AbstractUIElement>elementsThe elements within the body of the documentprivate List<Script>footerScriptsThe scripts in the bottom of the bodyprivate StringformatThe template for the documentprivate Map<String,Object>formatArgsThe custom templating keywords/arguments for interpolation into the document format.private FormatProcessorformatProcessorprivate List<Script>headerScriptsThe scripts in the head of the documentprivate booleanisFormatForBodyWhether the supplied template should only be for the Document's body.private StringlanguageThe language of the pageprivate List<LinkedStyle>linkedStylesThe styles linked to the documentprivate List<Meta>metaTagsThe meta tags of the documentprivate StylestyleA style tag in the header of the documentprivate StringtitleThe title of the page -
Constructor Summary
Constructors Constructor Description HTMLDocument(List<AbstractUIElement> elements, List<LinkedStyle> linkedStyles, Style style, List<Script> headerScripts, List<Script> footerScripts, List<Meta> metaTags, boolean withBootStrap, boolean withBootStrapPopper, boolean withWaterCSS, HTMLDocument.ColorTheme waterCSSTheme, String title, String language, String format, Map<String,Object> formatArgs, boolean isFormatForBody) -
Method Summary
Modifier and Type Method Description static HTMLDocument.HTMLDocumentBuilderbuilder()private static List<AbstractUIElement>filterForAttributes(String attributeName, java.util.function.Predicate<String> predicate, List<AbstractUIElement> elements)Filters elements that have some attribute and whose attribute value satisfies some predicateprivate static List<AbstractUIElement>findAllOfClass(String clazz, List<AbstractUIElement> elements)Filters a list of elements with a CSS classprivate static List<AbstractUIElement>findAllOfID(String id, List<AbstractUIElement> elements)Filters all elements with an IDprivate static List<AbstractUIElement>findAllOfTagName(String tagName, List<AbstractUIElement> elements)Filters all elements of a tag nameStringgenerateDocumentString()Generates the HTML markup of the documentstatic List<AbstractUIElement>getAllDescendents(AbstractUIElement ancestor)Recursively finds all the descendents of an elementstatic List<AbstractUIElement>getAllDirectDescendents(AbstractUIElement ancestor)Gets all direct descendents of an HTML elementList<AbstractUIElement>getElements()List<Script>getFooterScripts()StringgetFormat()Map<String,Object>getFormatArgs()List<Script>getHeaderScripts()StringgetLanguage()List<LinkedStyle>getLinkedStyles()List<Meta>getMetaTags()StylegetStyle()StringgetTitle()private static booleanisCssSelectorOperator(String token)Whether a token is a CSS operator (i.e.static List<AbstractUIElement>processAttributeSelector(String query, List<AbstractUIElement> elements)Processes a CSS attribute selectorprivate static List<AbstractUIElement>processQuery(String query, List<AbstractUIElement> elements)Processes a CSS query/subquery for the query selector methodprivate static List<AbstractUIElement>processToken(String query, List<AbstractUIElement> elements)Processes extracted tokens (space separated) within a CSS queryList<AbstractUIElement>querySelector(String query)Retrieves a list of elements added to the document that match with the given CSS query.private static List<AbstractUIElement>querySelector(String query, List<AbstractUIElement> elements)Query selector applied to a specific set of elements
-
Field Details
-
elements
The elements within the body of the document -
linkedStyles
The styles linked to the document -
style
A style tag in the header of the document -
headerScripts
The scripts in the head of the document -
metaTags
The meta tags of the document -
title
The title of the page -
formatProcessor
-
language
The language of the page -
format
The template for the document -
formatArgs
The custom templating keywords/arguments for interpolation into the document format. See the README for more info -
isFormatForBody
private boolean isFormatForBodyWhether the supplied template should only be for the Document's body. If false, the template will apply for the whole document
-
-
Constructor Details
-
HTMLDocument
public HTMLDocument(List<AbstractUIElement> elements, List<LinkedStyle> linkedStyles, Style style, List<Script> headerScripts, List<Script> footerScripts, List<Meta> metaTags, boolean withBootStrap, boolean withBootStrapPopper, boolean withWaterCSS, HTMLDocument.ColorTheme waterCSSTheme, String title, String language, String format, Map<String,Object> formatArgs, boolean isFormatForBody)
-
-
Method Details
-
builder
-
generateDocumentString
Generates the HTML markup of the document- Returns:
- The HTML string
-
querySelector
Retrieves a list of elements added to the document that match with the given CSS query. Note that this implementation does not currently support pseudo-elements nor pseudo-classes.- Parameters:
query- The CSS selector to select elements with- Returns:
- All elements that match that query
-
querySelector
private static List<AbstractUIElement> querySelector(String query, List<AbstractUIElement> elements)Query selector applied to a specific set of elements- Parameters:
query- The CSS selector to select elements withelements- The elements to test- Returns:
- All elements that match that query
-
processQuery
private static List<AbstractUIElement> processQuery(String query, List<AbstractUIElement> elements)Processes a CSS query/subquery for the query selector method- Parameters:
query- The CSS queryelements- The elements to test- Returns:
- All elements that match that query
-
processToken
private static List<AbstractUIElement> processToken(String query, List<AbstractUIElement> elements)Processes extracted tokens (space separated) within a CSS query- Parameters:
query- The CSS queryelements- The elements to test- Returns:
- All elements that match that query
-
findAllOfTagName
private static List<AbstractUIElement> findAllOfTagName(String tagName, List<AbstractUIElement> elements)Filters all elements of a tag name- Parameters:
tagName- The tag nameelements- The elements to filter- Returns:
- The filtered elements
-
findAllOfID
Filters all elements with an ID- Parameters:
id- The ID of the elementelements- The elements to filter- Returns:
- The filtered elements
-
findAllOfClass
private static List<AbstractUIElement> findAllOfClass(String clazz, List<AbstractUIElement> elements)Filters a list of elements with a CSS class- Parameters:
clazz- The CSS classelements- The elements to filter through- Returns:
- The filtered elements
-
getAllDirectDescendents
Gets all direct descendents of an HTML element- Parameters:
ancestor- The element to get the children of- Returns:
- The direct descendents of the element
-
getAllDescendents
Recursively finds all the descendents of an element- Parameters:
ancestor- The element to find the descendents of- Returns:
- The descendents
-
processAttributeSelector
public static List<AbstractUIElement> processAttributeSelector(String query, List<AbstractUIElement> elements)Processes a CSS attribute selector- Parameters:
query- The CSS queryelements- The elements to filter through- Returns:
- The filtered elements
-
isCssSelectorOperator
Whether a token is a CSS operator (i.e. >, +, ~)- Parameters:
token- The token to test- Returns:
- The boolean result
-
filterForAttributes
private static List<AbstractUIElement> filterForAttributes(String attributeName, java.util.function.Predicate<String> predicate, List<AbstractUIElement> elements)Filters elements that have some attribute and whose attribute value satisfies some predicate- Parameters:
attributeName- The name of the attributepredicate- The predicate to test on the attribute valueelements- The elements to filter through- Returns:
- The filtered elements
-
getElements
-
getLinkedStyles
-
getStyle
-
getHeaderScripts
-
getMetaTags
-
getTitle
-
getLanguage
-
getFormat
-
getFormatArgs
-