public class

Feed

extends Source
implements IFeed
java.lang.Object
   ↳ com.google.gdata.model.Element
     ↳ com.google.gdata.model.atom.Source
       ↳ com.google.gdata.model.atom.Feed
Known Direct Subclasses

Class Overview

The Feed class is a base class that represents a generic GData feed object, based primarily on the data model for an <atom:feed> element. It is extended to represent OpenSearch RSS channel elements and other gdata standard elements.

The Feed Class contains all the necessary parsing and generation code for feed data, but can be subclassed to create subtypes that contain convenience APIs for accessing additional elements and entries.

An instance can be initialized by directly initializing its component elements.

Here is the Relax-NG schema that represents an Atom 1.0 feed:

 AtomFeed =
  element atom:feed {
    atomCommonAttributes,
    (atomAuthor*
     atomCategory*
     atomContributor*
     atomGenerator?
     atomIcon?
     atomId
     atomLink*
     atomLogo?
     atomRights?
     atomSubtitle?
     atomTitle
     atomUpdated
     extensionElement*),
     atomEntry*
   }
 

Because the Feed schema differs from the Source schema only by the presence of the entries, the Feed class derives its base property model from the Source class.

Summary

Nested Classes
class Feed.FeedState The FeedState class provides a simple structure that encapsulates the attributes of an Atom feed that should be shared with a shallow copy if the feed is adapted to a more specific Feed subtypes. 
Fields
public static final ElementKey<Integer, Element> ITEMS_PER_PAGE The opensearch:itemsPerPage element.
public static final ElementKey<Void, Feed> KEY The key for this element.
public static final ElementKey<Integer, Element> START_INDEX The opensearch:startIndex element.
public static final ElementKey<Integer, Element> TOTAL_RESULTS The opensearch:totalResults element.
public static final AttributeKey<URI> XML_BASE The xml:base attribute.
protected final Feed.FeedState feedState Basic state for this feed.
[Expand]
Inherited Fields
From class com.google.gdata.model.atom.Source
From class com.google.gdata.model.Element
Public Constructors
Feed()
Constructs a new Feed instance, using default metadata.
Protected Constructors
Feed(ElementKey<?, ? extends Feed> key)
Creates a new feed instance using the specified metadata.
Feed(ElementKey<?, ? extends Feed> key, Feed source)
Copy constructor that initializes a new Feed instance to have identical contents to another instance, using a shared reference to the same Feed.FeedState.
Public Methods
void addEntry(Entry entry)
Adds an entry to this feed.
void clearEntries()
Clears the list of entries on this feed.
Entry createEntry()
Creates a new entry for the feed.
<E extends Entry> E createEntry(ElementKey<?, E> entryKey)
Creates a new entry for the feed.
boolean getCanPost()
Gets the property that indicates if it is possible to post new entries to the feed.
<T extends Entry> List<T> getEntries(Class<T> returnClass)
Gets a list of entries of a particular kind.
List<? extends Entry> getEntries()
Returns the list of entries in this feed
Link getEntryPostLink()
Returns the entry post link for the feed.
String getEtag()
Returns the ETAG value for this feed.
Link getFeedBatchLink()
Returns the link that provides the URI that can be used to batch operations to query, insert, update and delete entries on this feed.
int getItemsPerPage()
Gets the number of items that will be returned per page for paged feeds.
String getKind()
Returns the KIND value for this feed.
Link getNextLink()
Returns the link that provides the URI of next page in a paged feed.
Link getPreviousLink()
Returns the link that provides the URI of previous page in a paged feed.
String getSelectedFields()
Returns the FIELDS value for this feed.
Feed getSelf()
Returns the current representation of the feed by requesting it from the associated service using the feed's self link.
Link getSelfLink()
Returns the self link for the feed.
Service getService()
Returns that GData Service instance tassociated with this feed.
int getStartIndex()
Gets the starting index of the contained entries for paged feeds.
int getTotalResults()
Gets the total number of results associated with this feed.
String getVersionId()
Returns the resource version id for this feed.
URI getXmlBase()
Returns the current xml:base attribute for this feed.
<T extends Entry> T insert(T newEntry)
Inserts a new Entry into the feed, if the feed is currently associated with a Service.
static void registerMetadata(MetadataRegistry registry)
Registers the metadata for this element.
boolean removeEntry(Entry entry)
Removes a single entry from this feed.
void removeLinks()
Removes all links.
Element resolve(ElementMetadata<?, ?> metadata, ValidationContext vc)
Resolve this element's state against the metadata.
void setCanPost(boolean v)
Sets the property that indicates if it is possible to post new entries to the feed.
void setEntries(Collection<? extends Entry> entries)
Sets the entries in this feed to the given entries.
void setEtag(String v)
Sets the ETAG value for this feed.
void setItemsPerPage(int v)
Sets the number of items that will be returned per page for paged feeds.
void setKind(String v)
Sets the KIND value for this feed.
void setSelectedFields(String v)
Sets theFIELDS value for this feed.
void setService(Service v)
Sets that GData Service instance associated with this feed.
void setStartIndex(int v)
Sets the starting index of the contained entries for paged feeds.
void setTotalResults(int v)
Sets the total number of results associated with this feed.
void setVersionId(String v)
Set the resource version id for this feed.
void setXmlBase(URI v)
Sets the current xml:base attribute for this feed.
Protected Methods
<T extends Entry> List<T> getEntries(ElementKey<?, T> key)
Returns a list of entries matching the given entry key.
Element narrow(ElementMetadata<?, ?> meta, ValidationContext vc)
Narrows this feed using categories with an appropriate kind value.
[Expand]
Inherited Methods
From class com.google.gdata.model.atom.Source
From class com.google.gdata.model.Element
From class java.lang.Object
From interface com.google.gdata.data.IAtom
From interface com.google.gdata.data.IFeed

Fields

public static final ElementKey<Integer, Element> ITEMS_PER_PAGE

The opensearch:itemsPerPage element.

public static final ElementKey<Void, Feed> KEY

The key for this element.

public static final ElementKey<Integer, Element> START_INDEX

The opensearch:startIndex element.

public static final ElementKey<Integer, Element> TOTAL_RESULTS

The opensearch:totalResults element.

public static final AttributeKey<URI> XML_BASE

The xml:base attribute.

protected final Feed.FeedState feedState

Basic state for this feed. May be shared across multiple adapted instances associated with the same logical feed.

Public Constructors

public Feed ()

Constructs a new Feed instance, using default metadata.

Protected Constructors

protected Feed (ElementKey<?, ? extends Feed> key)

Creates a new feed instance using the specified metadata.

Parameters
key The feed key.

protected Feed (ElementKey<?, ? extends Feed> key, Feed source)

Copy constructor that initializes a new Feed instance to have identical contents to another instance, using a shared reference to the same Feed.FeedState. Subclasses of Feed can use this constructor to create adaptor instances of a feed that share state with the original but use a different set of metadata.

Parameters
key
source

Public Methods

public void addEntry (Entry entry)

Adds an entry to this feed.

Parameters
entry

public void clearEntries ()

Clears the list of entries on this feed.

public Entry createEntry ()

Creates a new entry for the feed.

public E createEntry (ElementKey<?, E> entryKey)

Creates a new entry for the feed.

Parameters
entryKey

public boolean getCanPost ()

Gets the property that indicates if it is possible to post new entries to the feed.

public List<T> getEntries (Class<T> returnClass)

Gets a list of entries of a particular kind. Will only return entries that match the expected return class.

Parameters
returnClass

public List<? extends Entry> getEntries ()

Returns the list of entries in this feed

public Link getEntryPostLink ()

Returns the entry post link for the feed.

public String getEtag ()

Returns the ETAG value for this feed. A value of null indicates the value is unknown.

public Link getFeedBatchLink ()

Returns the link that provides the URI that can be used to batch operations to query, insert, update and delete entries on this feed.

Returns
  • Link that provides the URI that can be used to batch operations to query, insert, update and delete entries on this feed or null for none.

public int getItemsPerPage ()

Gets the number of items that will be returned per page for paged feeds. A value of UNDEFINED indicates the page item count is undefined.

public String getKind ()

Returns the KIND value for this feed. The kind attribute may be null if this feed does not have a kind.

public Link getNextLink ()

Returns the link that provides the URI of next page in a paged feed.

Returns
  • Link that provides the URI of next page in a paged feed or null for none.

public Link getPreviousLink ()

Returns the link that provides the URI of previous page in a paged feed.

Returns
  • Link that provides the URI of previous page in a paged feed or null for none.

public String getSelectedFields ()

Returns the FIELDS value for this feed. The fields attribute may be null if this feed contains a full representation.

public Feed getSelf ()

Returns the current representation of the feed by requesting it from the associated service using the feed's self link.

Returns
  • the current state of the feed.
Throws
IOException
ServiceException

public Link getSelfLink ()

Returns the self link for the feed.

public Service getService ()

Returns that GData Service instance tassociated with this feed.

public int getStartIndex ()

Gets the starting index of the contained entries for paged feeds. A value of UNDEFINED indicates the start index is undefined.

public int getTotalResults ()

Gets the total number of results associated with this feed. The value may be larger than the number of contained entries for paged feeds. A value of UNDEFINED indicates the total size is undefined.

public String getVersionId ()

Returns the resource version id for this feed. This will be used to generate an etag value on output. This is never set when the Feed has been parsed.

public URI getXmlBase ()

Returns the current xml:base attribute for this feed. The base attribute may be null if this feed does not have an xml:base.

public T insert (T newEntry)

Inserts a new Entry into the feed, if the feed is currently associated with a Service.

Parameters
newEntry
Returns
  • the inserted Entry returned by the Service.
Throws
ServiceException If there is no associated GData service or the service is unable to perform the insertion.
UnsupportedOperationException If insert is not supported for the target feed.
IOException If there is an error communicating with the GData service.

public static void registerMetadata (MetadataRegistry registry)

Registers the metadata for this element.

Parameters
registry

public boolean removeEntry (Entry entry)

Removes a single entry from this feed.

Parameters
entry

public void removeLinks ()

Removes all links.

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

Resolve this element's state against the metadata. Accumulates errors in caller's validation context.

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

public void setCanPost (boolean v)

Sets the property that indicates if it is possible to post new entries to the feed.

Parameters
v

public void setEntries (Collection<? extends Entry> entries)

Sets the entries in this feed to the given entries.

Parameters
entries

public void setEtag (String v)

Sets the ETAG value for this feed. A value of null indicates the value is unknown.

Parameters
v

public void setItemsPerPage (int v)

Sets the number of items that will be returned per page for paged feeds. A value of UNDEFINED indicates the page item count is undefined.

Parameters
v

public void setKind (String v)

Sets the KIND value for this feed. The kind may be set to null to remove the attribute value.

Parameters
v

public void setSelectedFields (String v)

Sets theFIELDS value for this feed. The fields attribute may be set to null to remove the attribute value.

Parameters
v

public void setService (Service v)

Sets that GData Service instance associated with this feed.

Parameters
v

public void setStartIndex (int v)

Sets the starting index of the contained entries for paged feeds. A value of UNDEFINED indicates the start index is undefined.

Parameters
v

public void setTotalResults (int v)

Sets the total number of results associated with this feed. The value may be larger than the number of contained entries for paged feeds. A value of UNDEFINED indicates the total size is undefined.

Parameters
v

public void setVersionId (String v)

Set the resource version id for this feed. This will be used to generate an etag value on output. If null, the updated time will be used instead to generate an etag.

Parameters
v

public void setXmlBase (URI v)

Sets the current xml:base attribute for this feed. The base may be set to null to remove the attribute value.

Parameters
v

Protected Methods

protected List<T> getEntries (ElementKey<?, T> key)

Returns a list of entries matching the given entry key.

Parameters
key

protected Element narrow (ElementMetadata<?, ?> meta, ValidationContext vc)

Narrows this feed using categories with an appropriate kind value. This will loop through the categories, checking if they represent kinds, and adapting the feed to that kind if an appropriate adaptation was found. This will return the most specific subtype of the narrowed type.

Parameters
meta The element metadata to narrow to.
vc Validation context
Returns
  • element narrowed down to the most specific type