F - feed type associated with bound subtypeE - entry type associated with bound subtypepublic abstract class BaseFeed<F extends BaseFeed,E extends BaseEntry> extends Source implements Kind.Adaptable, Kind.Adaptor, IFeed
<atom:feed> element. It is extended to represent
OpenSearch RSS channel elements, and also supports generalized
extensibility using a defined ExtensionProfile and/or by stored
extended data as an XmlBlob.
The BaseFeedClass is a generic class that is parameterized by the type of Entry that will be contained within the feed. The base class contains all the necessary parsing and generation code for feed extension data, but can be subclassed to create subtypes that contain convenience APIs for accessing extension elements and entries.
An instance can be initialized by parsing an Atom 1.0 feed from a Reader or by directly initializing its component elements. It can generate an XML representation of the feed to an XmlWriter in either Atom 1.0 or RSS 2.0 format.
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 and parsing/generation implementations from the Source class.
The BaseFeed class implements the Kind.Adaptable interface, meaning
it is possible to create new Kind.Adaptor subtypes that defines
a custom extension model (and associated convenience APIs) for a BaseFeed
subtypes that use Atom/RSS extensions to extend the content model for a
particular type of data.
An Kind.Adaptor subclass of BaseFeed should do the following:
Kind.Term annotation on the class declaration that
defines the Category term value for the GData kind handled by the
adaptor.Class and BaseFeed
parameter as an argument that is used when adapting a generic feed type to
a more specific one.Kind.Adaptor.declareExtensions(ExtensionProfile)
method and use it to declare the extension model for the adapted instance
within the profile passed as a parameter. This is used to auto-extend
an extension profile when kind Category tags are found during parsing of
content.ExtensionPoint methods to
store/retrieve the extension data.
| Modifier and Type | Class and Description |
|---|---|
class |
BaseFeed.FeedHandler
<atom:feed> parser. |
protected static class |
BaseFeed.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 BaseFeed
Kind.Adaptor subtypes. |
Source.SourceHandler, Source.SourceStateExtensionPoint.CumulativeBlobHandler, ExtensionPoint.ExtensionHandlerAbstractExtension.AttributesHandler| Modifier and Type | Field and Description |
|---|---|
protected java.util.List<E> |
entries
Feed entries.
|
protected java.lang.Class<? extends E> |
entryClass
Class used to construct new entry instance, initialized at construction.
|
protected BaseFeed.FeedState |
feedState
Basic state for this feed.
|
xmlBloblocalName, namespace| Modifier | Constructor and Description |
|---|---|
protected |
BaseFeed(java.lang.Class<? extends E> entryClass)
Copy constructor that initializes a new BaseFeed instance to have
identical contents to another instance, using a shared reference to
the same
BaseFeed.FeedState. |
protected |
BaseFeed(java.lang.Class<? extends E> entryClass,
BaseFeed<?,?> sourceFeed)
Copy constructor that initializes a new BaseFeed instance to have
identical contents to another instance, using a shared reference to
the same
BaseFeed.FeedState. |
| Modifier and Type | Method and Description |
|---|---|
void |
addAdaptor(Kind.Adaptor adaptor)
Associates a new
Kind.Adaptor with this Adaptable instance. |
E |
createEntry()
Creates a new entry for the feed.
|
void |
declareExtensions(ExtensionProfile extProfile)
Declares the set of expected Extension types for an ExtensionPoint within
the target extension profile.
|
void |
generate(XmlWriter w,
ExtensionProfile p)
Generates an XML representation for the extension.
|
void |
generateAtom(XmlWriter w,
ExtensionProfile extProfile)
Generates XML in the Atom format.
|
void |
generateFeedEnd(XmlWriter w)
|
void |
generateFeedStart(ExtensionProfile extProfile,
XmlWriter w,
java.util.Collection<XmlNamespace> namespaces)
Generates everything that's in the feed up to and not including the
entries.
|
void |
generateRss(XmlWriter w,
ExtensionProfile extProfile)
Generates XML in the RSS format.
|
BaseFeed<?,?> |
getAdaptedFeed()
Locates and returns the most specific
Kind.Adaptor feed
subtype for this feed. |
<A extends Kind.Adaptor> |
getAdaptor(java.lang.Class<A> adaptorClass)
Returns a
Kind.Adaptor instance associated with this
Adaptable instance of the specified type, or {code null}
if none is available.. |
java.util.Collection<Kind.Adaptor> |
getAdaptors()
Returns the collection of
Kind.Adaptor instances associated with the
this Adaptable instance. |
boolean |
getCanPost()
Gets the property that indicates if it is possible to post new entries
to the feed.
|
java.util.List<E> |
getEntries()
Returns the list of entries in this feed
|
<T extends BaseEntry> |
getEntries(java.lang.Class<T> returnClass)
Gets a list of entries of a particular kind.
|
Link |
getEntryPostLink()
Returns the entry post link for the feed.
|
java.lang.String |
getEtag()
Returns the current entity tag 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.
|
XmlParser.ElementHandler |
getHandler(ExtensionProfile p,
java.lang.String namespace,
java.lang.String localName,
org.xml.sax.Attributes attrs)
The default implementation uses the
AbstractExtension.AttributesHandler to handle
parsing the extension. |
int |
getItemsPerPage()
Gets the number of items that will be returned per page for paged feeds.
|
java.lang.String |
getKind()
Returns the current gd:kind attribute 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.
|
java.lang.String |
getSelectedFields()
Returns the current fields selection for this partial feed.
|
F |
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 associated 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.
|
java.lang.String |
getVersionId()
Returns the entity version for this feed.
|
<T extends E> |
insert(T newEntry)
Inserts a new Entry into the feed, if the feed is currently
associated with a Service.
|
void |
parseAtom(ExtensionProfile extProfile,
java.io.InputStream input)
Parses XML in the Atom format.
|
void |
parseAtom(ExtensionProfile extProfile,
java.io.Reader reader)
Parses XML in the Atom format.
|
void |
parseAtom(ExtensionProfile extProfile,
XmlEventSource source)
Parses XML in the Atom format from a parser-defined content source.
|
static BaseFeed<?,?> |
readFeed(ParseSource source)
Reads a feed representation from the provided
ParseSource. |
static <F extends BaseFeed> |
readFeed(ParseSource source,
java.lang.Class<F> feedClass,
ExtensionProfile extProfile)
This method provides the base implementation of feed reading using either
static or dynamic typing.
|
void |
setCanPost(boolean v)
Sets the property that indicates if it is possible to post new entries
to the feed.
|
void |
setEntries(java.util.List<E> entryList)
Sets the list to use for storing the entry list
|
void |
setEtag(java.lang.String v)
Sets the current entity tag value for this feed.
|
void |
setItemsPerPage(int v)
Sets the number of items that will be returned per page for paged feeds.
|
void |
setKind(java.lang.String v)
Sets the current gd:kind attribute value for this feed.
|
void |
setSelectedFields(java.lang.String fields)
Sets the current fields selection for this partial 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(java.lang.String v)
Sets the entity version for this feed.
|
protected void |
visitChildren(ExtensionVisitor ev)
Called to visit all children of this extension point.
|
addHtmlLink, addLink, addLink, generateInnerAtom, getAuthors, getCategories, getContributors, getGenerator, getHtmlLink, getIcon, getId, getLink, getLinks, getLinks, getLogo, getRights, getSubtitle, getTitle, getUpdated, removeLinks, removeLinks, setGenerator, setGenerator, setIcon, setId, setLogo, setRights, setSubtitle, setTitle, setUpdatedaddExtension, addExtension, addRepeatingExtension, addRepeatingExtension, checkRequiredExtensions, createExtensionInstance, generate, generateCumulativeXmlBlob, generateExtensions, generateStartElement, getExtension, getExtensionDescription, getExtensionHandler, getExtensions, getManifest, getRepeatingExtension, getRepeatingExtensions, getXmlBlob, hasExtension, hasRepeatingExtension, initializeArbitraryXml, parseCumulativeXmlBlob, removeExtension, removeExtension, removeRepeatingExtension, setExtension, setXmlBlob, visit, visitChildconsumeAttributes, disableStrictValidation, enableStrictValidation, eq, generateAttributes, getExtensionLocalName, getExtensionNamespace, isImmutable, isStrictValidation, putAttributes, sameClassAs, setImmutable, throwExceptionForMissingAttribute, throwExceptionIfImmutable, validateclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetGenerator, getLogo, getSubtitle, setGenerator, setLogoaddLink, getAuthors, getCategories, getId, getLink, getLinks, getTitle, getUpdated, removeLinks, removeLinks, setId, setUpdatedprotected BaseFeed.FeedState feedState
protected java.lang.Class<? extends E extends BaseEntry> entryClass
protected BaseFeed(java.lang.Class<? extends E> entryClass)
BaseFeed.FeedState. Kind.Adaptor subclasses
of BaseFeed can use this constructor to create adaptor
instances of an entry that share state with the original.entryClass - Class used to construct new Entry instances for the Feed.protected BaseFeed(java.lang.Class<? extends E> entryClass, BaseFeed<?,?> sourceFeed)
BaseFeed.FeedState. Kind.Adaptor subclasses
of BaseFeed can use this constructor to create adaptor
instances of a feed that share state with the original.public void declareExtensions(ExtensionProfile extProfile)
The implementation of this method for BaseFeed will declare any extensions associated with the contained entry type.
declareExtensions in interface Kind.AdaptordeclareExtensions in class ExtensionPointextProfile - the ExtensionProfile to initialize.ExtensionProfile.addDeclarations(Kind.Adaptor)public Service getService()
Service instance associated with this feed.public void setService(Service v)
Service instance associated with this feed.setService in interface IAtompublic boolean getCanPost()
getCanPost in interface IFeedpublic void setCanPost(boolean v)
setCanPost in interface IFeedpublic void setVersionId(java.lang.String v)
null
the last modified date is used to generate the etag.setVersionId in interface IAtompublic java.lang.String getVersionId()
getVersionId in interface IAtompublic java.lang.String getEtag()
null indicates the value is unknown.public void setEtag(java.lang.String v)
null indicates the value is unknown.public java.lang.String getSelectedFields()
null indicates the feed is not a partial feed.public void setSelectedFields(java.lang.String fields)
null indicates the feed is not a partial feed.public java.lang.String getKind()
null indicates the value is unknown.public void setKind(java.lang.String v)
null indicates the value is unknown.public int getTotalResults()
Query.UNDEFINED indicates the total size is undefined.getTotalResults in interface IFeedpublic void setTotalResults(int v)
Query.UNDEFINED indicates the total size is undefined.setTotalResults in interface IFeedpublic int getStartIndex()
Query.UNDEFINED indicates the start index is undefined.getStartIndex in interface IFeedpublic void setStartIndex(int v)
Query.UNDEFINED indicates the start index is undefined.setStartIndex in interface IFeedpublic int getItemsPerPage()
Query.UNDEFINED indicates the page item count is
undefined.getItemsPerPage in interface IFeedpublic void setItemsPerPage(int v)
Query.UNDEFINED indicates the page item count is
undefined.setItemsPerPage in interface IFeedpublic java.util.List<E> getEntries()
getEntries in interface IFeedpublic void setEntries(java.util.List<E> entryList)
public void addAdaptor(Kind.Adaptor adaptor)
Kind.AdaptableKind.Adaptor with this Adaptable instance.addAdaptor in interface Kind.Adaptablepublic java.util.Collection<Kind.Adaptor> getAdaptors()
Kind.AdaptableKind.Adaptor instances associated with the
this Adaptable instance.getAdaptors in interface Kind.Adaptablepublic <A extends Kind.Adaptor> A getAdaptor(java.lang.Class<A> adaptorClass)
Kind.AdaptableKind.Adaptor instance associated with this
Adaptable instance of the specified type, or {code null}
if none is available..getAdaptor in interface Kind.Adaptablepublic E createEntry()
createEntry in interface IFeedpublic Link getEntryPostLink()
getEntryPostLink in interface IFeedpublic Link getSelfLink()
getSelfLink in interface IAtompublic Link getNextLink()
getNextLink in interface IFeednull for none.public Link getPreviousLink()
getPreviousLink in interface IFeednull for none.public Link getFeedBatchLink()
getFeedBatchLink in interface IFeednull
for none.public F getSelf() throws java.io.IOException, ServiceException
java.io.IOExceptionServiceExceptionpublic <T extends E> T insert(T newEntry) throws ServiceException, java.io.IOException
ServiceException - If there is no associated GData service or the service is
unable to perform the insertion.java.lang.UnsupportedOperationException - If insert is not supported for the target feed.java.io.IOException - If there is an error communicating with the GData service.protected void visitChildren(ExtensionVisitor ev) throws ExtensionVisitor.StoppedException
ExtensionPointvisitChildren in class ExtensionPointev - the extension visitor.ExtensionVisitor.StoppedExceptionpublic void generate(XmlWriter w, ExtensionProfile p) throws java.io.IOException
Extensiongenerate in interface Extensiongenerate in class AbstractExtensionw - XML writerp - extension profilejava.io.IOExceptionpublic void generateAtom(XmlWriter w, ExtensionProfile extProfile) throws java.io.IOException
generateAtom in class Sourcew - Output writer.extProfile - Extension profile.java.io.IOExceptionpublic void generateFeedEnd(XmlWriter w) throws java.io.IOException
generateFeedStart(com.google.gdata.data.ExtensionProfile, com.google.gdata.util.common.xml.XmlWriter, java.util.Collection<com.google.gdata.util.common.xml.XmlNamespace>).w - java.io.IOExceptionpublic void generateFeedStart(ExtensionProfile extProfile, XmlWriter w, java.util.Collection<XmlNamespace> namespaces) throws java.io.IOException
generateFeedStart(), write the
entries, and then call
generateFeedEnd(com.google.gdata.util.common.xml.XmlWriter)
to avoid having to add entries to a list and keep them in memory.extProfile - w - namespaces - extra namespace declarationsjava.io.IOExceptionpublic void generateRss(XmlWriter w, ExtensionProfile extProfile) throws java.io.IOException
w - Output writer.extProfile - Extension profile.java.io.IOExceptionpublic static BaseFeed<?,?> readFeed(ParseSource source) throws java.io.IOException, ParseException, ServiceException
ParseSource.
The return type of the feed will be determined using dynamic adaptation
based upon any Kind category tag found in the input content. If
no kind tag is found a Feed instance will be returned.java.io.IOExceptionParseExceptionServiceExceptionpublic static <F extends BaseFeed> F readFeed(ParseSource source, java.lang.Class<F> feedClass, ExtensionProfile extProfile) throws java.io.IOException, ParseException, ServiceException
java.io.IOExceptionParseExceptionServiceExceptionpublic void parseAtom(ExtensionProfile extProfile, java.io.InputStream input) throws java.io.IOException, ParseException
parseAtom in class SourceextProfile - Extension profile.input - XML input stream.java.io.IOExceptionParseExceptionpublic void parseAtom(ExtensionProfile extProfile, java.io.Reader reader) throws java.io.IOException, ParseException
parseAtom in class SourceextProfile - Extension profile.reader - XML Reader. The caller is responsible for ensuring that
the character encoding is correct.java.io.IOExceptionParseExceptionpublic void parseAtom(ExtensionProfile extProfile, XmlEventSource source) throws java.io.IOException, ParseException
extProfile - Extension profile.source - XML source.java.io.IOExceptionParseExceptionpublic XmlParser.ElementHandler getHandler(ExtensionProfile p, java.lang.String namespace, java.lang.String localName, org.xml.sax.Attributes attrs) throws ParseException
AbstractExtensionAbstractExtension.AttributesHandler to handle
parsing the extension.getHandler in interface ExtensiongetHandler in class ExtensionPointp - extension profilenamespace - extension namespacelocalName - tag name, without the namespace prefixattrs - tag attributesParseException - when an unexpected tag or badly-formatted
XML is detectedpublic BaseFeed<?,?> getAdaptedFeed() throws Kind.AdaptorException
Kind.Adaptor feed
subtype for this feed. If none can be found for the current class,
null will be returned.Kind.AdaptorExceptionpublic <T extends BaseEntry> java.util.List<T> getEntries(java.lang.Class<T> returnClass)