Class Text<T extends Text<T>>
- Direct Known Subclasses:
RawHtml
This class provides a way to represent plain text content within HTML documents.
Unlike typical HTML elements, text nodes don't have opening/closing tags and render
as raw text content. This class extends Element but overrides the
rendering behavior to output only the text content without any HTML markup.
Text elements automatically exclude ID attributes as they are not HTML elements.
Features:
- Represents plain text content within HTML structure
- Renders as raw text without HTML tags
- Automatically excludes ID attributes
- Trims whitespace-only content during rendering
- Used internally by many other elements for text content
- Supports dynamic text updates
Usage:
// Create text node
Text text = new Text("Hello, World!");
// Add text to a paragraph
P paragraph = new P();
paragraph.addElement(new Text("This is plain text."));
// Update text content dynamically
Text dynamic = new Text();
dynamic.setText("Initial text");
// Later...
dynamic.setText("Updated text");
// Mix text with other elements
Div div = new Div();
div.addElement(new Text("Click "));
div.addElement(new A("here", "#"));
div.addElement(new Text(" for more info."));
// Renders as: Click <a href="#">here</a> for more info.
- Since:
- 2007
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class com.oorian.html.Element
addAttribute, addAttribute, addAttribute, addAttribute, addElement, addLineBreak, addLineOfText, addLineOfText, addLineOfText, addParagraph, addParagraph, addSpacer, addText, addText, addText, addText, assignId, containsElement, containsElement, create, dispatchEvent, dispatchEvent, dispatchEvent, dispatchEvent, equals, excludeId, executeJs, executeJs, executeJs, getAccept, getAllElements, getAncestor, getAttribute, getAttributes, getComponent, getDir, getElement, getElementById, getElementCount, getElementCount, getElements, getElements, getElementsByComponentName, getElementsByTagName, getHtml, getId, getInnerHtml, getInnerHtml, getIs, getItemId, getItemProp, getItemRef, getItemType, getLang, getNextSibling, getPage, getParent, getPart, getPrevSibling, getSlot, getTagName, getTextContent, getUrl, hasAttribute, hasElements, hidden, initialize, insertElement, isChildOf, isClosedTag, isCreated, isDescendantOf, isDescendantOf, isInitialized, isItemScope, isTranslate, onCallback, onCreated, onElementAdded, onElementRemoved, onHashChange, onHidden, onInitialized, onJsReturn, onPageLoaded, onPageUnloaded, onRefresh, onRemovedFromPage, onShown, onUpdated, onUserEvent, prewrite, recreate, refresh, refresh, registerAddition, registerListener, registerListener, registerListener, registerListener, registerListener, registerListener, registerListener, registerSubtraction, registerUpdate, removeAllElements, removeAttribute, removeAttribute, removeElement, removeElement, removeFromParent, requestCallback, requestCallback, requestCallback, requestCallback, resetId, scrollTo, scrollToBottom, scrollToTop, self, sendCommand, sendUpdate, setAccept, setComponent, setDir, setDir, setElement, setId, setIs, setItemId, setItemProp, setItemRef, setItemScope, setItemType, setLang, setOnError, setOnLoad, setPage, setParent, setPart, setSlot, setTagName, setText, setText, setText, setTranslate, shown, toString, unregisterListener, update, updateAttributes
-
Constructor Details
-
Text
public Text()Constructs an empty Text element.Creates a new text node with no initial content. Text can be set later using the
setText(String)method. The element is configured to exclude ID attributes as text nodes are not HTML elements. -
Text
Constructs a Text element with the specified content.Creates a new text node containing the provided text content. The element is configured to exclude ID attributes as text nodes are not HTML elements.
- Parameters:
text- the text content for this text node
-
-
Method Details
-
setText
Sets the text content of this text node.Replaces any existing content with the specified text. This method also removes any child elements that may have been added, ensuring that only the text content is rendered.
-
getText
Gets the text content of this text node.Returns the current text content stored in this text node.
- Returns:
- the text content, or null if no text has been set
-
getHtml
Appends the HTML-escaped text content to the provided StringBuilder.Overrides the default HTML rendering to output only the text content without any HTML tags or attributes. The text content is HTML-escaped to prevent XSS (Cross-Site Scripting) attacks by converting special characters (
<,>,&,",') to their HTML entity equivalents. Empty or whitespace-only text is not appended to the output.Note: If you need to output raw, unescaped HTML content, use the
RawHtmlclass instead.
-