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. |
Source.SourceHandler
ExtensionPoint.CumulativeBlobHandler, ExtensionPoint.ExtensionHandler
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
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.
|
addHtmlLink, addLink, addLink, 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, setUpdated
addExtension, addRepeatingExtension, generateCumulativeXmlBlob, getExtension, getExtensions, getRepeatingExtension, getRepeatingExtensions, getXmlBlob, hasExtension, hasRepeatingExtension, parseCumulativeXmlBlob, removeExtension, removeExtension, removeRepeatingExtension, setExtension, setXmlBlob, visit
disableStrictValidation, enableStrictValidation, getExtensionLocalName, getExtensionNamespace, isImmutable, isStrictValidation, setImmutable
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getGenerator, getLogo, getSubtitle, setGenerator, setLogo
addLink, getAuthors, getCategories, getId, getLink, getLinks, getTitle, getUpdated, removeLinks, removeLinks, setId, setUpdated
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.Adaptor
declareExtensions
in class ExtensionPoint
extProfile
- 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 IAtom
public boolean getCanPost()
getCanPost
in interface IFeed
public void setCanPost(boolean v)
setCanPost
in interface IFeed
public void setVersionId(java.lang.String v)
null
the last modified date is used to generate the etag.setVersionId
in interface IAtom
public java.lang.String getVersionId()
getVersionId
in interface IAtom
public 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 IFeed
public void setTotalResults(int v)
Query.UNDEFINED
indicates the total size is undefined.setTotalResults
in interface IFeed
public int getStartIndex()
Query.UNDEFINED
indicates the start index is undefined.getStartIndex
in interface IFeed
public void setStartIndex(int v)
Query.UNDEFINED
indicates the start index is undefined.setStartIndex
in interface IFeed
public int getItemsPerPage()
Query.UNDEFINED
indicates the page item count is
undefined.getItemsPerPage
in interface IFeed
public void setItemsPerPage(int v)
Query.UNDEFINED
indicates the page item count is
undefined.setItemsPerPage
in interface IFeed
public java.util.List<E> getEntries()
getEntries
in interface IFeed
public void setEntries(java.util.List<E> entryList)
public void addAdaptor(Kind.Adaptor adaptor)
Kind.Adaptable
Kind.Adaptor
with this Adaptable
instance.addAdaptor
in interface Kind.Adaptable
public java.util.Collection<Kind.Adaptor> getAdaptors()
Kind.Adaptable
Kind.Adaptor
instances associated with the
this Adaptable
instance.getAdaptors
in interface Kind.Adaptable
public <A extends Kind.Adaptor> A getAdaptor(java.lang.Class<A> adaptorClass)
Kind.Adaptable
Kind.Adaptor
instance associated with this
Adaptable
instance of the specified type, or {code null}
if none is available..getAdaptor
in interface Kind.Adaptable
public E createEntry()
createEntry
in interface IFeed
public Link getEntryPostLink()
getEntryPostLink
in interface IFeed
public Link getSelfLink()
getSelfLink
in interface IAtom
public Link getNextLink()
getNextLink
in interface IFeed
null
for none.public Link getPreviousLink()
getPreviousLink
in interface IFeed
null
for none.public Link getFeedBatchLink()
getFeedBatchLink
in interface IFeed
null
for none.public F getSelf() throws java.io.IOException, ServiceException
java.io.IOException
ServiceException
public <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.public void generate(XmlWriter w, ExtensionProfile p) throws java.io.IOException
Extension
generate
in interface Extension
generate
in class AbstractExtension
w
- XML writerp
- extension profilejava.io.IOException
public void generateAtom(XmlWriter w, ExtensionProfile extProfile) throws java.io.IOException
generateAtom
in class Source
w
- Output writer.extProfile
- Extension profile.java.io.IOException
public 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.IOException
public 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.IOException
public void generateRss(XmlWriter w, ExtensionProfile extProfile) throws java.io.IOException
w
- Output writer.extProfile
- Extension profile.java.io.IOException
public 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.IOException
ParseException
ServiceException
public static <F extends BaseFeed> F readFeed(ParseSource source, java.lang.Class<F> feedClass, ExtensionProfile extProfile) throws java.io.IOException, ParseException, ServiceException
java.io.IOException
ParseException
ServiceException
public void parseAtom(ExtensionProfile extProfile, java.io.InputStream input) throws java.io.IOException, ParseException
parseAtom
in class Source
extProfile
- Extension profile.input
- XML input stream.java.io.IOException
ParseException
public void parseAtom(ExtensionProfile extProfile, java.io.Reader reader) throws java.io.IOException, ParseException
parseAtom
in class Source
extProfile
- Extension profile.reader
- XML Reader. The caller is responsible for ensuring that
the character encoding is correct.java.io.IOException
ParseException
public void parseAtom(ExtensionProfile extProfile, XmlEventSource source) throws java.io.IOException, ParseException
extProfile
- Extension profile.source
- XML source.java.io.IOException
ParseException
public XmlParser.ElementHandler getHandler(ExtensionProfile p, java.lang.String namespace, java.lang.String localName, org.xml.sax.Attributes attrs) throws ParseException
AbstractExtension
AttributesHandler
to handle
parsing the extension.getHandler
in interface Extension
getHandler
in class ExtensionPoint
p
- 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.AdaptorException
public <T extends BaseEntry> java.util.List<T> getEntries(java.lang.Class<T> returnClass)