Package io.john.amiscaray.stir.util
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 Summary
Fields Modifier and Type Field Description private static boolean
cacheDisabled
An option to disable caching globallyprivate static int
indentationSize
The indentation size (in spaces) for the documentprivate static ElementProcessor
instance
-
Constructor Summary
Constructors Modifier Constructor Description private
ElementProcessor()
-
Method Summary
Modifier and Type Method Description private void
buildElementClosingTag(StringBuilder builder, String tagName)
Generates the closing tag of an elementprivate void
buildElementOpeningTag(StringBuilder builder, AbstractUIElement obj, HTMLElement elMeta, String tagName)
Builds the opening tag for an HTML element, putting it in the StringBuilder passed to the methodprivate void
buildLabel(StringBuilder builder, Field label, Object parent)
Builds a label for the HTML element<T> Table
collectionToTableElement(Collection<T> collection, Class<T> clazz)
Deprecated.String
encode(String dirty)
Encodes a string to escape % characters used for string formats and HTML entitiesString
encodeForEntitiesOnly(String dirty)
Encodes a string for HTML elementsString
encodeForStringFormats(String dirty)
Encodes a string for % characters used for string formatesField[]
getAllFields(Class<?> type)
Retrieves the fields of a given class along with its superclasses up to (but not including) CacheableElement or Objectprivate String
getInnerTableMarkup(Collection<?> collection, Class<?> type)
The markup of the entries within a table represented by a collectionstatic ElementProcessor
getInstance()
String
getMarkup(AbstractUIElement obj)
Generates markup for an HTML elementString
getMarkup(Table table)
Generates markup for a Table elementString
getMarkup(Collection<?> collection, Class<?> type)
Deprecated.String
getMarkupForElementList(List<? extends AbstractUIElement> elements, int indentationLevel)
Generates the HTML markup of a list of elementsString
getMarkupFromCache(CacheableElement element)
Retrieves the HTML content of an element using its cacheString
getTagName(Class<?> clazz)
Gets the HTML tag for some class representing an HTML elementString
processStyle(CssRule rule)
Generates CSS content from a CssRule objectString
unescapeStringFormats(String encoded)
Unescapes the % characters in a String
-
Field Details
-
instance
-
indentationSize
private static int indentationSizeThe indentation size (in spaces) for the document -
cacheDisabled
private static boolean cacheDisabledAn option to disable caching globally
-
-
Constructor Details
-
ElementProcessor
private ElementProcessor()
-
-
Method Details
-
getInstance
-
getTagName
Gets the HTML tag for some class representing an HTML element- Parameters:
clazz
- The given class- Returns:
- The HTML tag for the class
-
getAllFields
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 elementsindentationLevel
- 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 IllegalAccessExceptionBuilds 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 elementobj
- The object to build the opening tag forelMeta
- The HTMLElement meta for the elementtagName
- The tag name of the element- Throws:
IllegalAccessException
- From the Java reflection API
-
buildElementClosingTag
Generates the closing tag of an element- Parameters:
builder
- The StringBuilder for the HTML content of the elementtagName
- The tag name of the element
-
buildLabel
private void buildLabel(StringBuilder builder, Field label, Object parent) throws IllegalAccessExceptionBuilds a label for the HTML element- Parameters:
builder
- The StringBuilder for the HTML content to be generatedlabel
- The label field of the objectparent
- The object containing the label field- Throws:
IllegalAccessException
- From the Java Reflection API
-
getMarkupFromCache
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
The markup of the entries within a table represented by a collection- Parameters:
collection
- The table entriestype
- The type of the entries of the collection- Returns:
- The markup of the table entries
-
getMarkup
Deprecated.Retrieves the markup of a collection as a table- Parameters:
collection
- The table entriestype
- The type of the entries of the collection- Returns:
- The markup of the table entries
-
getMarkup
Generates markup for a Table element- Parameters:
table
- The table element- Returns:
- The markup of the table element
-
getMarkup
Generates markup for an HTML element- Parameters:
obj
- The element to generate markup for- Returns:
- The HTML string of the element
-
processStyle
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.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 tableclazz
- The type of the elements of the collection- Returns:
- A new table instance
-
encodeForEntitiesOnly
Encodes a string for HTML elements- Parameters:
dirty
- The string to encode- Returns:
- The HTML entity encoded string
-
encode
Encodes a string to escape % characters used for string formats and HTML entities- Parameters:
dirty
- The string to encode- Returns:
- The encoded string
-
encodeForStringFormats
Encodes a string for % characters used for string formates- Parameters:
dirty
- The string to encode- Returns:
- The encoded string
-
unescapeStringFormats
Unescapes the % characters in a String- Parameters:
encoded
- The encoded string- Returns:
- The unescaped string
-