Package com.storedobject.common
Class HTMLText
java.lang.Object
com.storedobject.common.HTMLText
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.storedobject.common.StyledBuilder
StyledBuilder.Style -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleanA flag indicating whether top-level HTML elements such as html, body, and `head are allowed while building HTML content.protected final StringBuilderAStringBuilderinstance that serves as the primary container for constructing and managing the internal content of this HTMLText object.Fields inherited from interface com.storedobject.common.StyledBuilder
EMPTY_STRINGS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAppend an object.append(Object object, StyledBuilder.Style... styles) Append an object with the given style.Append an object with the given color.Append an object with the given style.appendHTML(String html) Appends the provided HTML string to the current content.clear()Clear the content.Clear the content.drawLine()Append a line using the tag.static StringEncode an object as an HTML string.getText()Get the current text of the HTML.static booleanWhether top-level HTML elements are allowed or not.booleanisEmpty()Check if the content is empty or not.booleanCheck if the last add was a new line or not.newLine()Adds a new line.newLine(boolean force) Adds a new line.static voidIf this method is invoked ever, top-leve HTML elements will be allowed while building the HTML content.voidSet text.space(int count) Add spaces.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.storedobject.common.StyledBuilder
setValue, setValue, setValue, update
-
Field Details
-
ALLOW_TOP_LEVEL
public static boolean ALLOW_TOP_LEVELA flag indicating whether top-level HTML elements such as html, body, and `head are allowed while building HTML content. When set to `true`, top-level elements can be included in the content, which may introduce unexpected modifications to the surrounding HTML structure. By default, this is set to `false` to ensure that only valid inner HTML content is added without altering the top-level structure. -
value
AStringBuilderinstance that serves as the primary container for constructing and managing the internal content of this HTMLText object. This field is used to build and store the current state of the HTML content being generated.- The
valueis marked asprotectedto allow access within the class, subclasses, and classes in the same package. - The
finalmodifier ensures that the reference to theStringBuildercannot be changed once it has been initialized, maintaining data consistency.
- The
-
-
Constructor Details
-
HTMLText
public HTMLText()Constructor. -
HTMLText
-
HTMLText
Constructor.- Parameters:
object- Object to be added.style- Styles to be set.
-
HTMLText
-
-
Method Details
-
toString
-
getText
-
setText
-
encode
-
newLine
Description copied from interface:StyledBuilderAdds a new line.- Specified by:
newLinein interfaceStyledBuilder- Parameters:
force- If true, a new line is added anyway. Otherwise, no new line should be added ifStyledBuilder.isNewLine()returns false.- Returns:
- Self-reference is returned.
-
newLine
Description copied from interface:StyledBuilderAdds a new line. (Default implementation doesn't force a new line).- Specified by:
newLinein interfaceStyledBuilder- Returns:
- Self-reference is returned.
-
drawLine
-
append
Description copied from interface:StyledBuilderAppend an object with the given color.- Specified by:
appendin interfaceStyledBuilder- Parameters:
object- Object to append.color- Color to be set. (Default implementation ignores this).- Returns:
- Self-reference is returned.
-
append
Description copied from interface:StyledBuilderAppend an object with the given style.- Specified by:
appendin interfaceStyledBuilder- Parameters:
object- Object to append.style- Styles to be set. (Default implementation ignores this).- Returns:
- Self-reference is returned.
-
append
Description copied from interface:StyledBuilderAppend an object with the given style. Default implementation ignores styles.- Specified by:
appendin interfaceStyledBuilder- Parameters:
object- Object to append.styles- Styles to be set.- Returns:
- Self-reference is returned.
-
appendHTML
Appends the provided HTML string to the current content. If the HTML string contains top-level elements such as HTML, BODY, HEAD, SCRIPT, or STYLE, an exception will be thrown unless top-level HTML elements are explicitly allowed.- Parameters:
html- The HTML string to be appended.- Returns:
- The current instance of HTMLText for method chaining.
- Throws:
SORuntimeException- If the HTML contains top-level elements or prohibited tags and top-level HTML is not allowed.
-
clearContent
Description copied from interface:StyledBuilderClear the content.- Specified by:
clearContentin interfaceStyledBuilder- Returns:
- Self-reference is returned.
-
clear
-
isEmpty
public boolean isEmpty()Description copied from interface:StyledBuilderCheck if the content is empty or not.- Specified by:
isEmptyin interfaceStyledBuilder- Returns:
- True or false.
-
isNewLine
public boolean isNewLine()Description copied from interface:StyledBuilderCheck if the last add was a new line or not.- Specified by:
isNewLinein interfaceStyledBuilder- Returns:
- True/false
-
space
Add spaces.- Parameters:
count- Number of spaces to be added.- Returns:
- Self-reference is returned.
-
append
Description copied from interface:StyledBuilderAppend an object.- Specified by:
appendin interfaceStyledBuilder- Parameters:
object- Object to append.- Returns:
- Self-reference is returned.
-
setAllowTopLevelHTML
public static void setAllowTopLevelHTML()If this method is invoked ever, top-leve HTML elements will be allowed while building the HTML content. This could cause unexpected changes to the existing HTML on the page. -
isAllowTopLevelHTML
public static boolean isAllowTopLevelHTML()Whether top-level HTML elements are allowed or not.- Returns:
- True/false.
-