public class

TextContent

extends Content
implements ITextConstruct ITextContent
java.lang.Object
   ↳ com.google.gdata.model.Element
     ↳ com.google.gdata.model.atom.Content
       ↳ com.google.gdata.model.atom.TextContent

Class Overview

Variant of Content for entries containing text.

Summary

Constants
String KIND The kind name for adaptation.
int UNKNOWN_TYPE
Fields
public static final ElementKey<String, TextContent> CONSTRUCT The key for TextContent used as a construct.
public static final ElementKey<String, XmlBlob> DIV The key for xhtml:div.
public static final ElementKey<String, TextContent> KEY The key for atom:content when it contains TextContent.
private static final ImmutableMap<String, Integer> TYPE_MAP
[Expand]
Inherited Fields
From class com.google.gdata.model.atom.Content
From class com.google.gdata.model.Element
Public Constructors
TextContent()
Constructs a new plain text instance using the default key.
Protected Constructors
TextContent(ElementKey<?, ?> key)
Constructs a new instance using the specified key.
TextContent(ElementKey<?, ?> key, Content content)
Constructs a new instance from a more generic Content type.
Public Methods
static TextContent create(int type, String textOrHtml, XmlBlob xhtml)
Creates a text content.
ITextConstruct getContent()
Returns the ITextConstruct that contains the text content.
String getHtml()
Backwards-compatibility method, exactly the same as getText().
String getPlainText()
Returns a plain-text representation of this text content.
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(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(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. In the case of plain text or html content, we resolve a null content body to an empty string.
void setHtml(String html)
Specifies the text of this element, turning this into an html text content element if it wasn't already.
void setText(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.
[Expand]
Inherited Methods
From class com.google.gdata.model.atom.Content
From class com.google.gdata.model.Element
From class java.lang.Object
From interface com.google.gdata.data.IContent
From interface com.google.gdata.data.ITextConstruct
From interface com.google.gdata.data.ITextContent

Constants

public static final String KIND

The kind name for adaptation.

Constant Value: "text"

private static final int UNKNOWN_TYPE

Constant Value: -1 (0xffffffff)

Fields

public static final ElementKey<String, TextContent> CONSTRUCT

The key for TextContent used as a construct. This will apply to all uses of TextContent regardless of QName.

public static final ElementKey<String, XmlBlob> DIV

The key for xhtml:div.

public static final ElementKey<String, TextContent> KEY

The key for atom:content when it contains TextContent.

private static final ImmutableMap<String, Integer> TYPE_MAP

Public Constructors

public TextContent ()

Constructs a new plain text instance using the default key.

Protected Constructors

protected TextContent (ElementKey<?, ?> key)

Constructs a new instance using the specified key.

Parameters
key The element key for this element

protected TextContent (ElementKey<?, ?> key, Content content)

Constructs a new instance from a more generic Content type.

Parameters
key The element key to use for this instance
content Generic content

Public Methods

public static TextContent create (int type, String textOrHtml, XmlBlob xhtml)

Creates a text content. This method is convenient for some service implementations. Note that XHTML is treated somewhat differently from text and HTML, as it is stored as a separate element instead of in the value portion of this element.

Parameters
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.
Returns

public ITextConstruct getContent ()

Returns the ITextConstruct that contains the text content.

public String getHtml ()

Backwards-compatibility method, exactly the same as getText().

public String getPlainText ()

Returns a plain-text representation of this text content. For content that is already plain text, this just returns the text value, but for html and xhtml it first converts the data into a plain text representation before returning it.

public String getText ()

Returns the text content of this element, if this is a plain text or html text content. If this is an XHTML text content this method returns null. If you want a plain-text representation of the XHTML content call getPlainText() instead.

public int getType ()

Returns the type of this content, either Content.Type#TEXT, Content.Type#HTML, or Content.Type#XHTML. If the value of the TYPE attribute is unknown, plain text Content.Type#TEXT will be returned.

Returns
  • the type of content.

public XmlBlob getXhtml ()

Returns the XHTML content of this text content, or null if no such element exists.

public static TextContent html (String html)

Construct a new html text content with the given html.

Parameters
html

public boolean isEmpty ()

Returns true if there is no content element for this text content.

public static TextContent plainText (String text)

Construct a new plain text content with the given text.

Parameters
text

public static void registerMetadata (MetadataRegistry registry)

Registers the metadata for this element.

Parameters
registry

public Element resolve (ElementMetadata<?, ?> metadata, ValidationContext vc)

Resolve this element's state against the metadata. Accumulates errors in caller's validation context. In the case of plain text or html content, we resolve a null content body to an empty string.

Parameters
metadata
vc Validation context
Returns
  • the narrowed element if narrowing took place.

public void setHtml (String html)

Specifies the text of this element, turning this into an html text content element if it wasn't already.

Parameters
html

public void setText (String text)

Specifies the text of this element, turning this into a plain-text content element if it wasn't already.

Parameters
text

public void setXhtml (XmlBlob div)

Specifies the XHTML content of this element, turning this into an xhtml text content element if it wasn't already.

Parameters
div

public static TextContent xhtml (XmlBlob div)

Construct a new Xhtml text content from the given div.

Parameters
div