yarfraw.io
Class CachedFeedReader

java.lang.Object
  extended by yarfraw.io.FeedReader
      extended by yarfraw.io.CachedFeedReader

public class CachedFeedReader
extends FeedReader

This is a special FeedReader that supports "conditional get".

When a client first asks this reader to read from a remote source, this reader automatically holds a reference to the returned ChannelFeed.
When a client asks this reader to read again from the remote source, this reader first queries the server to check if there's any new changes (by checking its last modified date). If there is new changes, it reads and parse the updated feed and updates the cache ChannelFeed. If there is no new changes since the last read, it returns the cached ChannelFeed since there's no new changes.

Since this reader only need to perform parsing when there's new changes, it will have better performance than the normal FeedReader class.

Note that this class is only useful for reading from a remote source.

for more information about conditional get, see <a href="http://fishbowl.pastiche.org/2002/10/21/http_conditional_get_for_rss_hackers" />

Author:
jliang

Field Summary
protected  File _file
           
protected  FeedFormat _format
           
protected  org.apache.commons.httpclient.methods.GetMethod _getMethod
           
protected  org.apache.commons.httpclient.params.HttpClientParams _httpClientParams
           
protected  org.apache.commons.httpclient.HttpURL _httpUrl
           
 
Constructor Summary
CachedFeedReader(org.apache.commons.httpclient.HttpURL httpUrl)
          Constructs a CachedFeedReader to read from a remote source using Http.
CachedFeedReader(org.apache.commons.httpclient.HttpURL httpUrl, org.apache.commons.httpclient.params.HttpClientParams params)
          Constructs a CachedFeedReader to read from a remote source using Http.
 
Method Summary
 ChannelFeed getCachedChannelFeed()
           
 String getETag()
           
 File getFile()
           
 FeedFormat getFormat()
          The FeedFormat this writer should be using.
if this is not set, the default is RSS 2.0 format.
 org.apache.commons.httpclient.methods.GetMethod getGetMethod()
          The GetMethod object to be used to remote from a remote source.
 org.apache.commons.httpclient.params.HttpClientParams getHttpClientParams()
           
 String getLastModified()
           
protected  InputStream getStream()
           
 boolean isRemoteRead()
          Is the reader reading the feed from a remote http link.
 ChannelFeed readChannel()
          Reads a channel from a local or remote feed.
 ChannelFeed readChannel(ValidationEventHandler validationEventHandler)
          Reads a channel from a local or remote feed with a custom ValidationEventHandler
This method performs conditional get, if the remote is not modified since last request, the cached feed will be returned.
 void setETag(String tag)
          Setter for the "ETag" response header.
 void setFile(File file)
           
 void setFormat(FeedFormat format)
          The FeedFormat this writer should be using.
if this is not set, the default is RSS 2.0 format.
 void setHttpClientParams(org.apache.commons.httpclient.params.HttpClientParams httpClientParams)
           
 void setLastModified(String lastModified)
          Setter for the "Last-Modified" response header.
 
Methods inherited from class yarfraw.io.FeedReader
readChannel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_httpUrl

protected org.apache.commons.httpclient.HttpURL _httpUrl

_httpClientParams

protected org.apache.commons.httpclient.params.HttpClientParams _httpClientParams

_getMethod

protected org.apache.commons.httpclient.methods.GetMethod _getMethod

_file

protected File _file

_format

protected FeedFormat _format
Constructor Detail

CachedFeedReader

public CachedFeedReader(org.apache.commons.httpclient.HttpURL httpUrl,
                        org.apache.commons.httpclient.params.HttpClientParams params)
                 throws YarfrawException,
                        IOException
Constructs a CachedFeedReader to read from a remote source using Http.
Format detection will be automatically performed.

Parameters:
httpUrl - - the HttpURL of the remote source
params - - any HttpClientParams
Throws:
YarfrawException - - if parse failed
IOException - - if format detection failed

CachedFeedReader

public CachedFeedReader(org.apache.commons.httpclient.HttpURL httpUrl)
                 throws YarfrawException,
                        IOException
Constructs a CachedFeedReader to read from a remote source using Http.
Format detection will be automatically performed.

Parameters:
httpUrl - - the HttpURL of the remote source
Throws:
YarfrawException - - if parse failed
IOException - - if format detection failed
Method Detail

readChannel

public ChannelFeed readChannel()
                        throws YarfrawException
Reads a channel from a local or remote feed.
This method performs conditional get, if the remote is not modified since last request, the cached feed will be returned.

Overrides:
readChannel in class FeedReader
Returns:
a ChannelFeed object
Throws:
YarfrawException - if read operation failed.

readChannel

public ChannelFeed readChannel(ValidationEventHandler validationEventHandler)
                        throws YarfrawException
Reads a channel from a local or remote feed with a custom ValidationEventHandler
This method performs conditional get, if the remote is not modified since last request, the cached feed will be returned.

Overrides:
readChannel in class FeedReader
Parameters:
validationEventHandler - a custom ValidationEventHandler
Returns:
a ChannelFeed object
Throws:
YarfrawException - if read operation failed.

getStream

protected InputStream getStream()
                         throws IOException
Throws:
IOException

getLastModified

public String getLastModified()
Returns:
- The value of the "Last-Modified" response header from the last read.

getETag

public String getETag()
Returns:
The value of the "ETag" response header from the last read.

setETag

public void setETag(String tag)
Setter for the "ETag" response header.
This method is used to let the caller set an initial value for this header.
This value will be automatically updated by this class for every readChannel() method call.

Parameters:
tag -

setLastModified

public void setLastModified(String lastModified)
Setter for the "Last-Modified" response header.
This method is used to let the caller set an initial value for this header.
This value will be automatically updated by this class for every readChannel() method call.

Parameters:
tag -

getCachedChannelFeed

public ChannelFeed getCachedChannelFeed()

getHttpClientParams

public org.apache.commons.httpclient.params.HttpClientParams getHttpClientParams()

setHttpClientParams

public void setHttpClientParams(org.apache.commons.httpclient.params.HttpClientParams httpClientParams)

getGetMethod

public org.apache.commons.httpclient.methods.GetMethod getGetMethod()
The GetMethod object to be used to remote from a remote source.

Returns:

isRemoteRead

public boolean isRemoteRead()
Is the reader reading the feed from a remote http link.

Returns:
true if reading remotely
false if reading from local file

getFile

public File getFile()

setFile

public void setFile(File file)

getFormat

public FeedFormat getFormat()
The FeedFormat this writer should be using.
if this is not set, the default is RSS 2.0 format. null format is ignored

rss 2.0 is recommended, use other format if you really need to


setFormat

public void setFormat(FeedFormat format)
The FeedFormat this writer should be using.
if this is not set, the default is RSS 2.0 format. null format is ignored

rss 2.0 is recommended, use other format if you really need to



Copyright © 2008. All Rights Reserved.