Class HTMLDocument

java.lang.Object
io.john.amiscaray.stir.domain.HTMLDocument

public class HTMLDocument
extends Object
A pojo representing an HTML document
  • Field Details

    • elements

      private final List<AbstractUIElement> elements
      The elements within the body of the document
    • linkedStyles

      private final List<LinkedStyle> linkedStyles
      The styles linked to the document
    • style

      private final Style style
      A style tag in the header of the document
    • headerScripts

      private final List<Script> headerScripts
      The scripts in the head of the document
    • footerScripts

      private final List<Script> footerScripts
      The scripts in the bottom of the body
    • metaTags

      private final List<Meta> metaTags
      The meta tags of the document
    • title

      private String title
      The title of the page
    • formatProcessor

      private final FormatProcessor formatProcessor
    • language

      private String language
      The language of the page
    • format

      private String format
      The template for the document
    • formatArgs

      private Map<String,​Object> formatArgs
      The custom templating keywords/arguments for interpolation into the document format. See the README for more info
    • isFormatForBody

      private boolean isFormatForBody
      Whether the supplied template should only be for the Document's body. If false, the template will apply for the whole document
  • Constructor Details

  • Method Details

    • builder

      public static HTMLDocument.HTMLDocumentBuilder builder()
    • generateDocumentString

      public String generateDocumentString()
      Generates the HTML markup of the document
      Returns:
      The HTML string
    • querySelector

      public List<AbstractUIElement> querySelector​(String query)
      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 with
      elements - 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 query
      elements - 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 query
      elements - 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 name
      elements - The elements to filter
      Returns:
      The filtered elements
    • findAllOfID

      private static List<AbstractUIElement> findAllOfID​(String id, List<AbstractUIElement> elements)
      Filters all elements with an ID
      Parameters:
      id - The ID of the element
      elements - 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 class
      elements - The elements to filter through
      Returns:
      The filtered elements
    • getAllDirectDescendents

      public static List<AbstractUIElement> getAllDirectDescendents​(AbstractUIElement ancestor)
      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

      public static List<AbstractUIElement> getAllDescendents​(AbstractUIElement ancestor)
      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)
      Parameters:
      query - The CSS query
      elements - The elements to filter through
      Returns:
      The filtered elements
    • isCssSelectorOperator

      private static boolean isCssSelectorOperator​(String token)
      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 attribute
      predicate - The predicate to test on the attribute value
      elements - The elements to filter through
      Returns:
      The filtered elements
    • getElements

      public List<AbstractUIElement> getElements()
    • getLinkedStyles

      public List<LinkedStyle> getLinkedStyles()
    • getStyle

      public Style getStyle()
    • getHeaderScripts

      public List<Script> getHeaderScripts()
    • getFooterScripts

      public List<Script> getFooterScripts()
    • getMetaTags

      public List<Meta> getMetaTags()
    • getTitle

      public String getTitle()
    • getLanguage

      public String getLanguage()
    • getFormat

      public String getFormat()
    • getFormatArgs

      public Map<String,​Object> getFormatArgs()