com.google.gdata.model.atom
Class TextContent

java.lang.Object
  extended by com.google.gdata.model.Element
      extended by com.google.gdata.model.atom.Content
          extended by com.google.gdata.model.atom.TextContent
All Implemented Interfaces:
IContent, ITextConstruct, ITextContent

public class TextContent
extends Content
implements ITextContent, ITextConstruct

Variant of Content for entries containing text.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.google.gdata.data.IContent
IContent.Type
 
Nested classes/interfaces inherited from interface com.google.gdata.data.ITextConstruct
ITextConstruct.Type
 
Field Summary
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.
 
Fields inherited from class com.google.gdata.model.atom.Content
SRC, TYPE, XML_LANG
 
Constructor Summary
  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.
 
Method Summary
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.
 
Methods inherited from class com.google.gdata.model.atom.Content
getLang, getMimeType, getSrc, narrow, setLang
 
Methods inherited from class com.google.gdata.model.Element
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
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.gdata.data.IContent
getLang
 

Field Detail

KIND

public static final java.lang.String KIND
The kind name for adaptation.

See Also:
Constant Field Values

CONSTRUCT

public static final ElementKey<java.lang.String,TextContent> CONSTRUCT
The key for TextContent used as a construct. This will apply to all uses of TextContent regardless of QName.


KEY

public static final ElementKey<java.lang.String,TextContent> KEY
The key for atom:content when it contains TextContent.


DIV

public static final ElementKey<java.lang.String,XmlBlob> DIV
The key for xhtml:div.

Constructor Detail

TextContent

public TextContent()
Constructs a new plain text instance using the default key.


TextContent

protected TextContent(ElementKey<?,?> key)
Constructs a new instance using the specified key.

Parameters:
key - the element key for this element

TextContent

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
Method Detail

registerMetadata

public static void registerMetadata(MetadataRegistry registry)
Registers the metadata for this element.


create

public static TextContent create(int type,
                                 java.lang.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:
a TextConstruct of the appropriate type.

plainText

public static TextContent plainText(java.lang.String text)
Construct a new plain text content with the given text.


html

public static TextContent html(java.lang.String html)
Construct a new html text content with the given html.


xhtml

public static TextContent xhtml(XmlBlob div)
Construct a new Xhtml text content from the given div.


getType

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 Content.TYPE attribute is unknown, plain text Content.Type#TEXT will be returned.

Specified by:
getType in interface IContent
Specified by:
getType in interface ITextConstruct
Overrides:
getType in class Content
Returns:
the type of content.
See Also:
IContent.Type

isEmpty

public boolean isEmpty()
Returns true if there is no content element for this text content.


getPlainText

public java.lang.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.

Specified by:
getPlainText in interface ITextConstruct

getText

public java.lang.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.


getHtml

public java.lang.String getHtml()
Backwards-compatibility method, exactly the same as getText().


getXhtml

public XmlBlob getXhtml()
Returns the XHTML content of this text content, or null if no such element exists.


setText

public 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.


setHtml

public 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.


setXhtml

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.


resolve

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.

Overrides:
resolve in class Element
vc - validation context
Returns:
the narrowed element if narrowing took place.

getContent

public ITextConstruct getContent()
Description copied from interface: ITextContent
Returns the ITextConstruct that contains the text content.

Specified by:
getContent in interface ITextContent