Class ElementProcessor

java.lang.Object
io.john.amiscaray.stir.util.ElementProcessor

public class ElementProcessor
extends Object
A class responsible for generating the appropriate HTML markup
  • Field Details

    • instance

      private static ElementProcessor instance
    • indentationSize

      private static int indentationSize
      The indentation size (in spaces) for the document
    • cacheDisabled

      private static boolean cacheDisabled
      An option to disable caching globally
  • Constructor Details

    • ElementProcessor

      private ElementProcessor()
  • Method Details

    • getInstance

      public static ElementProcessor getInstance()
    • getTagName

      public String getTagName​(Class<?> clazz)
      Gets the HTML tag for some class representing an HTML element
      Parameters:
      clazz - The given class
      Returns:
      The HTML tag for the class
    • getAllFields

      public Field[] getAllFields​(Class<?> type)
      Retrieves the fields of a given class along with its superclasses up to (but not including) CacheableElement or Object
      Parameters:
      type - The given class
      Returns:
      The fields that make up the class and its superclasses up to (but not including) CacheableElement or Object
    • getMarkupForElementList

      public String getMarkupForElementList​(List<? extends AbstractUIElement> elements, int indentationLevel)
      Generates the HTML markup of a list of elements
      Parameters:
      elements - The list of elements
      indentationLevel - Base indentation level to use for the elements
      Returns:
      The final HTML markup of the elements
    • buildElementOpeningTag

      private void buildElementOpeningTag​(StringBuilder builder, AbstractUIElement obj, HTMLElement elMeta, String tagName) throws IllegalAccessException
      Builds the opening tag for an HTML element, putting it in the StringBuilder passed to the method
      Parameters:
      builder - The String builder for the entire HTML content of the element
      obj - The object to build the opening tag for
      elMeta - The HTMLElement meta for the element
      tagName - The tag name of the element
      Throws:
      IllegalAccessException - From the Java reflection API
    • buildElementClosingTag

      private void buildElementClosingTag​(StringBuilder builder, String tagName)
      Generates the closing tag of an element
      Parameters:
      builder - The StringBuilder for the HTML content of the element
      tagName - The tag name of the element
    • buildLabel

      private void buildLabel​(StringBuilder builder, Field label, Object parent) throws IllegalAccessException
      Builds a label for the HTML element
      Parameters:
      builder - The StringBuilder for the HTML content to be generated
      label - The label field of the object
      parent - The object containing the label field
      Throws:
      IllegalAccessException - From the Java Reflection API
    • getMarkupFromCache

      public String getMarkupFromCache​(CacheableElement element)
      Retrieves the HTML content of an element using its cache
      Parameters:
      element - The element to get the cached markup from
      Returns:
      The Markup of the element
    • getInnerTableMarkup

      private String getInnerTableMarkup​(Collection<?> collection, Class<?> type)
      The markup of the entries within a table represented by a collection
      Parameters:
      collection - The table entries
      type - The type of the entries of the collection
      Returns:
      The markup of the table entries
    • getMarkup

      @Deprecated public String getMarkup​(Collection<?> collection, Class<?> type)
      Deprecated.
      Retrieves the markup of a collection as a table
      Parameters:
      collection - The table entries
      type - The type of the entries of the collection
      Returns:
      The markup of the table entries
    • getMarkup

      public String getMarkup​(Table table)
      Generates markup for a Table element
      Parameters:
      table - The table element
      Returns:
      The markup of the table element
    • getMarkup

      public String getMarkup​(AbstractUIElement obj)
      Generates markup for an HTML element
      Parameters:
      obj - The element to generate markup for
      Returns:
      The HTML string of the element
    • processStyle

      public String processStyle​(CssRule rule)
      Generates CSS content from a CssRule object
      Parameters:
      rule - The object to generate CSS from
      Returns:
      The CSS content corresponding to the object
    • collectionToTableElement

      @Deprecated public <T> Table collectionToTableElement​(Collection<T> collection, Class<T> clazz)
      Deprecated.
      Converts a Collection to a table Element TODO deprecate this
      Type Parameters:
      T - The type of the elements of the collection
      Parameters:
      collection - The collection to convert to a table
      clazz - The type of the elements of the collection
      Returns:
      A new table instance
    • encodeForEntitiesOnly

      public String encodeForEntitiesOnly​(String dirty)
      Encodes a string for HTML elements
      Parameters:
      dirty - The string to encode
      Returns:
      The HTML entity encoded string
    • encode

      public String encode​(String dirty)
      Encodes a string to escape % characters used for string formats and HTML entities
      Parameters:
      dirty - The string to encode
      Returns:
      The encoded string
    • encodeForStringFormats

      public String encodeForStringFormats​(String dirty)
      Encodes a string for % characters used for string formates
      Parameters:
      dirty - The string to encode
      Returns:
      The encoded string
    • unescapeStringFormats

      public String unescapeStringFormats​(String encoded)
      Unescapes the % characters in a String
      Parameters:
      encoded - The encoded string
      Returns:
      The unescaped string