public class TextContent extends Content implements ITextContent, ITextConstruct
Content
for entries containing text.IContent.Type
ITextConstruct.Type
Modifier and Type | Field and Description |
---|---|
static ElementKey<java.lang.String,TextContent> |
CONSTRUCT
The key for TextContent used as a construct.
|
static ElementKey<java.lang.String,XmlBlob> |
DIV
The key for xhtml:div.
|
static ElementKey<java.lang.String,TextContent> |
KEY
The key for atom:content when it contains TextContent.
|
static java.lang.String |
KIND
The kind name for adaptation.
|
Modifier | Constructor and Description |
---|---|
|
TextContent()
Constructs a new plain text instance using the default key.
|
protected |
TextContent(ElementKey<?,?> key)
Constructs a new instance using the specified key.
|
protected |
TextContent(ElementKey<?,?> key,
Content content)
Constructs a new instance from a more generic
Content type. |
Modifier and Type | Method and Description |
---|---|
static TextContent |
create(int type,
java.lang.String textOrHtml,
XmlBlob xhtml)
Creates a text content.
|
ITextConstruct |
getContent()
Returns the
ITextConstruct that contains the text content. |
java.lang.String |
getHtml()
Backwards-compatibility method, exactly the same as
getText() . |
java.lang.String |
getPlainText()
Returns a plain-text representation of this text content.
|
java.lang.String |
getText()
Returns the text content of this element, if this is a plain text or html
text content.
|
int |
getType()
Returns the type of this content, either
Content.Type#TEXT ,
Content.Type#HTML , or Content.Type#XHTML . |
XmlBlob |
getXhtml()
Returns the XHTML content of this text content, or
null if no such
element exists. |
static TextContent |
html(java.lang.String html)
Construct a new html text content with the given html.
|
boolean |
isEmpty()
Returns
true if there is no content element for this text content. |
static TextContent |
plainText(java.lang.String text)
Construct a new plain text content with the given text.
|
static void |
registerMetadata(MetadataRegistry registry)
Registers the metadata for this element.
|
Element |
resolve(ElementMetadata<?,?> metadata,
ValidationContext vc)
Resolve this element's state against the metadata.
|
void |
setHtml(java.lang.String html)
Specifies the text of this element, turning this into an html text content
element if it wasn't already.
|
void |
setText(java.lang.String text)
Specifies the text of this element, turning this into a plain-text
content element if it wasn't already.
|
void |
setXhtml(XmlBlob div)
Specifies the XHTML content of this element, turning this into an xhtml
text content element if it wasn't already.
|
static TextContent |
xhtml(XmlBlob div)
Construct a new Xhtml text content from the given div.
|
getLang, getMimeType, getSrc, narrow, setLang
adapt, adapt, addElement, addElement, addElement, clear, createElement, createElement, eq, equals, getAttributeCount, getAttributeIterator, getAttributeIterator, getAttributeValue, getAttributeValue, getDefaultKey, getElement, getElement, getElementCount, getElementId, getElementIterator, getElementIterator, getElementKey, getElements, getElements, getElementSet, getElementSet, getElementValue, getElementValue, getTextValue, getTextValue, hasAttribute, hasAttribute, hasElement, hasElement, hashCode, hasTextValue, isLocked, lock, removeAttribute, removeAttribute, removeAttributeValue, removeAttributeValue, removeElement, removeElement, removeElement, removeElement, replaceElement, resolve, sameClassAs, setAttributeValue, setAttributeValue, setElement, setElement, setElement, setTextValue, toString, validate, visit
public static final java.lang.String KIND
public static final ElementKey<java.lang.String,TextContent> CONSTRUCT
public static final ElementKey<java.lang.String,TextContent> KEY
public static final ElementKey<java.lang.String,XmlBlob> DIV
public TextContent()
protected TextContent(ElementKey<?,?> key)
key
- the element key for this elementprotected TextContent(ElementKey<?,?> key, Content content)
Content
type.key
- the element key to use for this instancecontent
- generic contentpublic static void registerMetadata(MetadataRegistry registry)
public static TextContent create(int type, java.lang.String textOrHtml, XmlBlob xhtml)
type
- the type of the new text construct (TEXT, HTML, or XHTML)textOrHtml
- the contents to put in this text construct, if the type is
TEXT or HTML.
If type is XHTML, set this parameter to null
.xhtml
- the contents to put in this text construct, if the type is
XHTML.
If type is TEXT or HTML, set this parameter to null
.TextConstruct
of the appropriate type.public static TextContent plainText(java.lang.String text)
public static TextContent html(java.lang.String html)
public static TextContent xhtml(XmlBlob div)
public int getType()
Content.Type#TEXT
,
Content.Type#HTML
, or Content.Type#XHTML
. If the value
of the Content.TYPE
attribute is unknown, plain text
Content.Type#TEXT
will be returned.public boolean isEmpty()
true
if there is no content element for this text content.public java.lang.String getPlainText()
getPlainText
in interface ITextConstruct
public java.lang.String getText()
getPlainText()
instead.public java.lang.String getHtml()
getText()
.public XmlBlob getXhtml()
null
if no such
element exists.public void setText(java.lang.String text)
public void setHtml(java.lang.String html)
public void setXhtml(XmlBlob div)
public Element resolve(ElementMetadata<?,?> metadata, ValidationContext vc)
public ITextConstruct getContent()
ITextContent
ITextConstruct
that contains the text content.getContent
in interface ITextContent