Formatted and cleaned up sources

This commit is contained in:
Patrick Gotthard 2014-05-13 19:28:22 +02:00
parent eb42124975
commit d23d1c2d3c
18 changed files with 145 additions and 113 deletions

View file

@ -25,13 +25,15 @@ import com.sun.syndication.io.FeedException;
public interface FeedFetcher { public interface FeedFetcher {
/** /**
* <p> * <p>
* The default user agent. It is not marked final so buggy java compiler will not write this string into all classes that reference it. * The default user agent. It is not marked final so buggy java compiler will not write this
* string into all classes that reference it.
* </p> * </p>
* *
* <p> * <p>
* http://tinyurl.com/64t5n points to https://rome.dev.java.net Some servers ban user agents with "Java" in the name. * http://tinyurl.com/64t5n points to https://rome.dev.java.net Some servers ban user agents
* with "Java" in the name.
* </p> * </p>
* *
*/ */
public static String DEFAULT_USER_AGENT = "Rome Client (http://tinyurl.com/64t5n)"; public static String DEFAULT_USER_AGENT = "Rome Client (http://tinyurl.com/64t5n)";
@ -49,15 +51,16 @@ public interface FeedFetcher {
* <p> * <p>
* Turn on or off rfc3229 delta encoding * Turn on or off rfc3229 delta encoding
* </p> * </p>
* *
* <p> * <p>
* See http://www.ietf.org/rfc/rfc3229.txt and http://bobwyman.pubsub.com/main/2004/09/using_rfc3229_w.html * See http://www.ietf.org/rfc/rfc3229.txt and
* http://bobwyman.pubsub.com/main/2004/09/using_rfc3229_w.html
* </p> * </p>
* *
* <p> * <p>
* NOTE: This is experimental and feedback is welcome! * NOTE: This is experimental and feedback is welcome!
* </p> * </p>
* *
* @param useDeltaEncoding * @param useDeltaEncoding
*/ */
public abstract void setUsingDeltaEncoding(boolean useDeltaEncoding); public abstract void setUsingDeltaEncoding(boolean useDeltaEncoding);
@ -66,7 +69,7 @@ public interface FeedFetcher {
* <p> * <p>
* Is this fetcher using rfc3229 delta encoding? * Is this fetcher using rfc3229 delta encoding?
* </p> * </p>
* *
* @return * @return
*/ */
public abstract boolean isUsingDeltaEncoding(); public abstract boolean isUsingDeltaEncoding();
@ -75,11 +78,12 @@ public interface FeedFetcher {
* <p> * <p>
* Add a FetcherListener. * Add a FetcherListener.
* </p> * </p>
* *
* <p> * <p>
* The FetcherListener will receive an FetcherEvent when a Fetcher event (feed polled, retrieved, etc) occurs * The FetcherListener will receive an FetcherEvent when a Fetcher event (feed polled,
* retrieved, etc) occurs
* </p> * </p>
* *
* @param listener The FetcherListener to recieve the event * @param listener The FetcherListener to recieve the event
*/ */
public abstract void addFetcherEventListener(FetcherListener listener); public abstract void addFetcherEventListener(FetcherListener listener);
@ -88,14 +92,14 @@ public interface FeedFetcher {
* <p> * <p>
* Remove a FetcherListener * Remove a FetcherListener
* </p> * </p>
* *
* @param listener The FetcherListener to remove * @param listener The FetcherListener to remove
*/ */
public abstract void removeFetcherEventListener(FetcherListener listener); public abstract void removeFetcherEventListener(FetcherListener listener);
/** /**
* Retrieve a feed over HTTP * Retrieve a feed over HTTP
* *
* @param feedUrl A non-null URL of a RSS/Atom feed to retrieve * @param feedUrl A non-null URL of a RSS/Atom feed to retrieve
* @return A {@link com.sun.syndication.feed.synd.SyndFeed} object * @return A {@link com.sun.syndication.feed.synd.SyndFeed} object
* @throws IllegalArgumentException if the URL is null; * @throws IllegalArgumentException if the URL is null;
@ -108,8 +112,9 @@ public interface FeedFetcher {
public SyndFeed retrieveFeed(String userAgent, URL url) throws IllegalArgumentException, IOException, FeedException, FetcherException; public SyndFeed retrieveFeed(String userAgent, URL url) throws IllegalArgumentException, IOException, FeedException, FetcherException;
/** /**
* If set to true, the WireFeed will be made accessible from the SyndFeed object returned from the Fetcher via the originalWireFeed() method. Each Entry in * If set to true, the WireFeed will be made accessible from the SyndFeed object returned from
* the feed will have the corresponding wireEntry property set. * the Fetcher via the originalWireFeed() method. Each Entry in the feed will have the
* corresponding wireEntry property set.
*/ */
void setPreserveWireFeed(boolean preserveWireFeed); void setPreserveWireFeed(boolean preserveWireFeed);
} }

View file

@ -5,9 +5,10 @@ import java.util.EventObject;
import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeed;
/** /**
* Implementation note: FetcherEvent is not thread safe. Make sure that they are only ever accessed by one thread. If necessary, make all getters and setters * Implementation note: FetcherEvent is not thread safe. Make sure that they are only ever accessed
* synchronized, or alternatively make all fields final. * by one thread. If necessary, make all getters and setters synchronized, or alternatively make all
* * fields final.
*
* @author nl * @author nl
*/ */
public class FetcherEvent extends EventObject { public class FetcherEvent extends EventObject {
@ -39,7 +40,7 @@ public class FetcherEvent extends EventObject {
/** /**
* @return Returns the feed. * @return Returns the feed.
* *
* <p> * <p>
* The feed will only be set if the eventType is EVENT_TYPE_FEED_RETRIEVED * The feed will only be set if the eventType is EVENT_TYPE_FEED_RETRIEVED
* </p> * </p>
@ -50,7 +51,7 @@ public class FetcherEvent extends EventObject {
/** /**
* @param feed The feed to set. * @param feed The feed to set.
* *
* <p> * <p>
* The feed will only be set if the eventType is EVENT_TYPE_FEED_RETRIEVED * The feed will only be set if the eventType is EVENT_TYPE_FEED_RETRIEVED
* </p> * </p>

View file

@ -18,7 +18,7 @@ package com.rometools.fetcher;
/** /**
* @author Nick Lothian * @author Nick Lothian
* *
*/ */
public class FetcherException extends Exception { public class FetcherException extends Exception {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View file

@ -8,7 +8,7 @@ public interface FetcherListener extends EventListener {
* <p> * <p>
* Called when a fetcher event occurs * Called when a fetcher event occurs
* </p> * </p>
* *
* @param event the event that fired * @param event the event that fired
*/ */
public void fetcherEvent(FetcherEvent event); public void fetcherEvent(FetcherEvent event);

View file

@ -25,13 +25,13 @@ import java.util.HashSet;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rometools.fetcher.FeedFetcher; import com.rometools.fetcher.FeedFetcher;
import com.rometools.fetcher.FetcherEvent; import com.rometools.fetcher.FetcherEvent;
import com.rometools.fetcher.FetcherException; import com.rometools.fetcher.FetcherException;
import com.rometools.fetcher.FetcherListener; import com.rometools.fetcher.FetcherListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeed;
public abstract class AbstractFeedFetcher implements FeedFetcher { public abstract class AbstractFeedFetcher implements FeedFetcher {
@ -189,7 +189,8 @@ public abstract class AbstractFeedFetcher implements FeedFetcher {
* </p> * </p>
* *
* <p> * <p>
* The returned feed will have the same data as the newFeed parameter, with the entries from originalFeed appended to the end of its entries. * The returned feed will have the same data as the newFeed parameter, with the entries from
* originalFeed appended to the end of its entries.
* </p> * </p>
* *
* @param originalFeed * @param originalFeed

View file

@ -12,7 +12,9 @@ public class AbstractFeedFetcherBeanInfo extends SimpleBeanInfo {
@Override @Override
public EventSetDescriptor[] getEventSetDescriptors() { public EventSetDescriptor[] getEventSetDescriptors() {
try { try {
final Class<AbstractFeedFetcher> clz = AbstractFeedFetcher.class; // get the class object which we'll describe final Class<AbstractFeedFetcher> clz = AbstractFeedFetcher.class; // get the class
// object which we'll
// describe
final Method addMethod = clz.getMethod("addFetcherEventListener", new Class[] { FetcherListener.class }); final Method addMethod = clz.getMethod("addFetcherEventListener", new Class[] { FetcherListener.class });
final Method removeMethod = clz.getMethod("removeFetcherEventListener", new Class[] { FetcherListener.class }); final Method removeMethod = clz.getMethod("removeFetcherEventListener", new Class[] { FetcherListener.class });
final Method listenerMethod = FetcherListener.class.getMethod("fetcherEvent", new Class[] { FetcherEvent.class }); final Method listenerMethod = FetcherListener.class.getMethod("fetcherEvent", new Class[] { FetcherEvent.class });
@ -20,7 +22,8 @@ public class AbstractFeedFetcherBeanInfo extends SimpleBeanInfo {
final EventSetDescriptor[] results = new EventSetDescriptor[] { est }; final EventSetDescriptor[] results = new EventSetDescriptor[] { est };
return results; return results;
} catch (final Exception e) { } catch (final Exception e) {
// IntrospectionException, SecurityException and/or NoSuchMethodException can be thrown here // IntrospectionException, SecurityException and/or NoSuchMethodException can be thrown
// here
// the best we can do is to convert them to runtime exceptions // the best we can do is to convert them to runtime exceptions
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View file

@ -20,17 +20,17 @@ import java.net.URL;
/** /**
* <p> * <p>
* An interface to allow caching of feed details. Implementing this allows the {@link com.rometools.fetcher.io.HttpURLFeedFetcher} class to enable conditional * An interface to allow caching of feed details. Implementing this allows the
* gets * {@link com.rometools.fetcher.io.HttpURLFeedFetcher} class to enable conditional gets
* </p> * </p>
* *
* @author Nick Lothian * @author Nick Lothian
* *
*/ */
public interface FeedFetcherCache { public interface FeedFetcherCache {
/** /**
* Get a SyndFeedInfo object from the cache. * Get a SyndFeedInfo object from the cache.
* *
* @param feedUrl The url of the feed * @param feedUrl The url of the feed
* @return A SyndFeedInfo or null if it is not in the cache * @return A SyndFeedInfo or null if it is not in the cache
*/ */
@ -38,7 +38,7 @@ public interface FeedFetcherCache {
/** /**
* Add a SyndFeedInfo object to the cache * Add a SyndFeedInfo object to the cache
* *
* @param feedUrl The url of the feed * @param feedUrl The url of the feed
* @param syndFeedInfo A SyndFeedInfo for the feed * @param syndFeedInfo A SyndFeedInfo for the feed
*/ */
@ -51,7 +51,7 @@ public interface FeedFetcherCache {
/** /**
* Removes the SyndFeedInfo identified by the url from the cache. * Removes the SyndFeedInfo identified by the url from the cache.
* *
* @return The removed SyndFeedInfo * @return The removed SyndFeedInfo
*/ */
public SyndFeedInfo remove(URL feedUrl); public SyndFeedInfo remove(URL feedUrl);

View file

@ -24,16 +24,18 @@ import java.util.Map;
/** /**
* <p> * <p>
* A very simple implementation of the {@link com.rometools.fetcher.impl.FeedFetcherCache} interface. * A very simple implementation of the {@link com.rometools.fetcher.impl.FeedFetcherCache}
* interface.
* </p> * </p>
* *
* <p> * <p>
* This implementation uses a HashMap to cache retrieved feeds. This implementation is most suitible for sort term (client aggregator?) use, as the memory usage * This implementation uses a HashMap to cache retrieved feeds. This implementation is most suitible
* will increase over time as the number of feeds in the cache increases. * for sort term (client aggregator?) use, as the memory usage will increase over time as the number
* of feeds in the cache increases.
* </p> * </p>
* *
* @author Nick Lothian * @author Nick Lothian
* *
*/ */
public class HashMapFeedInfoCache implements FeedFetcherCache, Serializable { public class HashMapFeedInfoCache implements FeedFetcherCache, Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -46,11 +48,12 @@ public class HashMapFeedInfoCache implements FeedFetcherCache, Serializable {
* <p> * <p>
* Constructor for HashMapFeedInfoCache * Constructor for HashMapFeedInfoCache
* </p> * </p>
* *
* <p> * <p>
* Only use this if you want multiple instances of the cache. Usually getInstance() is more appropriate. * Only use this if you want multiple instances of the cache. Usually getInstance() is more
* appropriate.
* </p> * </p>
* *
*/ */
public HashMapFeedInfoCache() { public HashMapFeedInfoCache() {
setInfoCache(createInfoCache()); setInfoCache(createInfoCache());
@ -58,7 +61,7 @@ public class HashMapFeedInfoCache implements FeedFetcherCache, Serializable {
/** /**
* Get the global instance of the cache * Get the global instance of the cache
* *
* @return an implementation of FeedFetcherCache * @return an implementation of FeedFetcherCache
*/ */
public static synchronized FeedFetcherCache getInstance() { public static synchronized FeedFetcherCache getInstance() {
@ -101,8 +104,9 @@ public class HashMapFeedInfoCache implements FeedFetcherCache, Serializable {
} }
/** /**
* The API of this class indicates that map must thread safe. In other words, be sure to wrap it in a synchronized map unless you know what you are doing. * The API of this class indicates that map must thread safe. In other words, be sure to wrap it
* * in a synchronized map unless you know what you are doing.
*
* @param map the map to use as the info cache. * @param map the map to use as the info cache.
*/ */
protected synchronized final void setInfoCache(final Map<String, SyndFeedInfo> map) { protected synchronized final void setInfoCache(final Map<String, SyndFeedInfo> map) {

View file

@ -31,9 +31,9 @@ import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.auth.AuthScope; import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpClientParams; import org.apache.commons.httpclient.params.HttpClientParams;
import com.rometools.fetcher.FetcherEvent; import com.rometools.fetcher.FetcherEvent;
import com.rometools.fetcher.FetcherException; import com.rometools.fetcher.FetcherException;
import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.FeedException; import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.SyndFeedInput; import com.sun.syndication.io.SyndFeedInput;
@ -67,8 +67,9 @@ public class HttpClientFeedFetcher extends AbstractFeedFetcher {
} }
/** /**
* @param timeout Sets the connect timeout for the HttpClient but using the URLConnection method name. Uses the HttpClientParams method * @param timeout Sets the connect timeout for the HttpClient but using the URLConnection method
* setConnectionManagerTimeout instead of setConnectTimeout * name. Uses the HttpClientParams method setConnectionManagerTimeout instead of
* setConnectTimeout
* *
*/ */
public synchronized void setConnectTimeout(final int timeout) { public synchronized void setConnectTimeout(final int timeout) {
@ -76,8 +77,9 @@ public class HttpClientFeedFetcher extends AbstractFeedFetcher {
} }
/** /**
* @return The currently used connect timeout for the HttpClient but using the URLConnection method name. Uses the HttpClientParams method * @return The currently used connect timeout for the HttpClient but using the URLConnection
* getConnectionManagerTimeout instead of getConnectTimeout * method name. Uses the HttpClientParams method getConnectionManagerTimeout instead of
* getConnectTimeout
* *
*/ */
public int getConnectTimeout() { public int getConnectTimeout() {
@ -135,14 +137,16 @@ public class HttpClientFeedFetcher extends AbstractFeedFetcher {
} }
/** /**
* @return The currently used read timeout for the URLConnection, 0 is unlimited, i.e. no timeout * @return The currently used read timeout for the URLConnection, 0 is unlimited, i.e. no
* timeout
*/ */
public synchronized void setReadTimeout(final int timeout) { public synchronized void setReadTimeout(final int timeout) {
httpClientParams.setSoTimeout(timeout); httpClientParams.setSoTimeout(timeout);
} }
/** /**
* @return timeout the read timeout for the URLConnection to a specified timeout, in milliseconds. * @return timeout the read timeout for the URLConnection to a specified timeout, in
* milliseconds.
*/ */
public int getReadTimeout() { public int getReadTimeout() {
return getHttpClientParams().getSoTimeout(); return getHttpClientParams().getSoTimeout();
@ -284,7 +288,8 @@ public class HttpClientFeedFetcher extends AbstractFeedFetcher {
final FeedFetcherCache cache = getFeedInfoCache(); final FeedFetcherCache cache = getFeedInfoCache();
if (cache != null && statusCode == 226) { if (cache != null && statusCode == 226) {
// client is setup to use http delta encoding and the server supports it and has returned a delta encoded response // client is setup to use http delta encoding and the server supports it and has
// returned a delta encoded response
// This response only includes new items // This response only includes new items
final SyndFeedInfo cachedInfo = cache.getFeedInfo(feedUrl); final SyndFeedInfo cachedInfo = cache.getFeedInfo(feedUrl);
@ -360,8 +365,9 @@ public class HttpClientFeedFetcher extends AbstractFeedFetcher {
public interface HttpClientMethodCallbackIntf { public interface HttpClientMethodCallbackIntf {
/** /**
* Allows access to the underlying HttpClient HttpMethod object. Note that in most cases, method.setRequestHeader(String, String) is what you want to do * Allows access to the underlying HttpClient HttpMethod object. Note that in most cases,
* (rather than method.addRequestHeader(String, String)) * method.setRequestHeader(String, String) is what you want to do (rather than
* method.addRequestHeader(String, String))
* *
* @param method * @param method
*/ */

View file

@ -26,7 +26,6 @@ import java.util.zip.GZIPInputStream;
import com.rometools.fetcher.FetcherEvent; import com.rometools.fetcher.FetcherEvent;
import com.rometools.fetcher.FetcherException; import com.rometools.fetcher.FetcherException;
import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.FeedException; import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.SyndFeedInput; import com.sun.syndication.io.SyndFeedInput;
@ -36,18 +35,20 @@ import com.sun.syndication.io.XmlReader;
* <p> * <p>
* Class to retrieve syndication files via HTTP. * Class to retrieve syndication files via HTTP.
* </p> * </p>
* *
* <p> * <p>
* If passed a {@link com.rometools.fetcher.impl.FeedFetcherCache} in the constructor it will use conditional gets to only retrieve modified content. * If passed a {@link com.rometools.fetcher.impl.FeedFetcherCache} in the constructor it will use
* conditional gets to only retrieve modified content.
* </p> * </p>
* *
* <p> * <p>
* The class uses the Accept-Encoding: gzip header to retrieve gzipped feeds where supported by the server. * The class uses the Accept-Encoding: gzip header to retrieve gzipped feeds where supported by the
* server.
* </p> * </p>
* *
* <p> * <p>
* Simple usage: * Simple usage:
* *
* <pre> * <pre>
* // create the cache * // create the cache
* FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getFeedInfoCache(); * FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getFeedInfoCache();
@ -56,14 +57,15 @@ import com.sun.syndication.io.XmlReader;
* // retrieve the resource if it has changed * // retrieve the resource if it has changed
* SyndFeed feed = new HttpURLFeedFetcher(feedInfoCache).retrieveFeed(feedUrl); * SyndFeed feed = new HttpURLFeedFetcher(feedInfoCache).retrieveFeed(feedUrl);
* </pre> * </pre>
* *
* </p> * </p>
* *
* @see <a * @see <a
* href="http://fishbowl.pastiche.org/2002/10/21/http_conditional_get_for_rss_hackers">http://fishbowl.pastiche.org/2002/10/21/http_conditional_get_for_rss_hackers</a> * href="http://fishbowl.pastiche.org/2002/10/21/http_conditional_get_for_rss_hackers">http://fishbowl.pastiche.org/2002/10/21/http_conditional_get_for_rss_hackers</a>
* @see <a * @see <a
* href="http://diveintomark.org/archives/2003/07/21/atom_aggregator_behavior_http_level">http://diveintomark.org/archives/2003/07/21/atom_aggregator_behavior_http_level</a> * href="http://diveintomark.org/archives/2003/07/21/atom_aggregator_behavior_http_level">http://diveintomark.org/archives/2003/07/21/atom_aggregator_behavior_http_level</a>
* @see <a href="http://bobwyman.pubsub.com/main/2004/09/using_rfc3229_w.html">http://bobwyman.pubsub.com/main/2004/09/using_rfc3229_w.html</a> * @see <a
* href="http://bobwyman.pubsub.com/main/2004/09/using_rfc3229_w.html">http://bobwyman.pubsub.com/main/2004/09/using_rfc3229_w.html</a>
* @author Nick Lothian * @author Nick Lothian
*/ */
public class HttpURLFeedFetcher extends AbstractFeedFetcher { public class HttpURLFeedFetcher extends AbstractFeedFetcher {
@ -76,7 +78,7 @@ public class HttpURLFeedFetcher extends AbstractFeedFetcher {
/** /**
* Constructor to use HttpURLFeedFetcher without caching of feeds * Constructor to use HttpURLFeedFetcher without caching of feeds
* *
*/ */
public HttpURLFeedFetcher() { public HttpURLFeedFetcher() {
super(); super();
@ -84,7 +86,7 @@ public class HttpURLFeedFetcher extends AbstractFeedFetcher {
/** /**
* Constructor to enable HttpURLFeedFetcher to cache feeds * Constructor to enable HttpURLFeedFetcher to cache feeds
* *
* @param feedCache - an instance of the FeedFetcherCache interface * @param feedCache - an instance of the FeedFetcherCache interface
*/ */
public HttpURLFeedFetcher(final FeedFetcherCache feedInfoCache) { public HttpURLFeedFetcher(final FeedFetcherCache feedInfoCache) {
@ -99,7 +101,7 @@ public class HttpURLFeedFetcher extends AbstractFeedFetcher {
/** /**
* Retrieve a feed over HTTP * Retrieve a feed over HTTP
* *
* @param feedUrl A non-null URL of a RSS/Atom feed to retrieve * @param feedUrl A non-null URL of a RSS/Atom feed to retrieve
* @return A {@link com.sun.syndication.feed.synd.SyndFeed} object * @return A {@link com.sun.syndication.feed.synd.SyndFeed} object
* @throws IllegalArgumentException if the URL is null; * @throws IllegalArgumentException if the URL is null;
@ -121,7 +123,8 @@ public class HttpURLFeedFetcher extends AbstractFeedFetcher {
if (connectTimeout >= 0) { if (connectTimeout >= 0) {
httpConnection.setConnectTimeout(connectTimeout); httpConnection.setConnectTimeout(connectTimeout);
} }
// httpConnection.setInstanceFollowRedirects(true); // this is true by default, but can be changed on a claswide basis // httpConnection.setInstanceFollowRedirects(true); // this is true by default, but can be
// changed on a claswide basis
final FeedFetcherCache cache = getFeedInfoCache(); final FeedFetcherCache cache = getFeedInfoCache();
if (cache != null) { if (cache != null) {
@ -217,7 +220,8 @@ public class HttpURLFeedFetcher extends AbstractFeedFetcher {
if (isUsingDeltaEncoding() && imHeader != null && imHeader.indexOf("feed") >= 0) { if (isUsingDeltaEncoding() && imHeader != null && imHeader.indexOf("feed") >= 0) {
final FeedFetcherCache cache = getFeedInfoCache(); final FeedFetcherCache cache = getFeedInfoCache();
if (cache != null && connection.getResponseCode() == 226) { if (cache != null && connection.getResponseCode() == 226) {
// client is setup to use http delta encoding and the server supports it and has returned a delta encoded response // client is setup to use http delta encoding and the server supports it and has
// returned a delta encoded response
// This response only includes new items // This response only includes new items
final SyndFeedInfo cachedInfo = cache.getFeedInfo(orignalUrl); final SyndFeedInfo cachedInfo = cache.getFeedInfo(orignalUrl);
if (cachedInfo != null) { if (cachedInfo != null) {
@ -241,7 +245,7 @@ public class HttpURLFeedFetcher extends AbstractFeedFetcher {
* <p> * <p>
* Set appropriate HTTP headers, including conditional get and gzip encoding headers * Set appropriate HTTP headers, including conditional get and gzip encoding headers
* </p> * </p>
* *
* @param connection A URLConnection * @param connection A URLConnection
* @param syndFeedInfo The SyndFeedInfo for the feed to be retrieved. May be null * @param syndFeedInfo The SyndFeedInfo for the feed to be retrieved. May be null
*/ */
@ -278,7 +282,8 @@ public class HttpURLFeedFetcher extends AbstractFeedFetcher {
is = new BufferedInputStream(inputStream); is = new BufferedInputStream(inputStream);
} }
// InputStreamReader reader = new InputStreamReader(is, ResponseHandler.getCharacterEncoding(connection)); // InputStreamReader reader = new InputStreamReader(is,
// ResponseHandler.getCharacterEncoding(connection));
// SyndFeedInput input = new SyndFeedInput(); // SyndFeedInput input = new SyndFeedInput();
@ -322,5 +327,5 @@ public class HttpURLFeedFetcher extends AbstractFeedFetcher {
*/ */
public synchronized void setConnectTimeout(final int timeout) { public synchronized void setConnectTimeout(final int timeout) {
connectTimeout = timeout; connectTimeout = timeout;
} }
} }

View file

@ -8,14 +8,14 @@ import java.util.Map;
* <p> * <p>
* An implementation of the {@link com.rometools.fetcher.impl.FeedFetcherCache} interface. * An implementation of the {@link com.rometools.fetcher.impl.FeedFetcherCache} interface.
* </p> * </p>
* *
* <p> * <p>
* Unlike the HashMapFeedInfoCache this implementation will not grow unbound * Unlike the HashMapFeedInfoCache this implementation will not grow unbound
* </p> * </p>
* *
* @author Javier Kohen * @author Javier Kohen
* @author Nick Lothian * @author Nick Lothian
* *
*/ */
public class LinkedHashMapFeedInfoCache extends HashMapFeedInfoCache { public class LinkedHashMapFeedInfoCache extends HashMapFeedInfoCache {
@ -42,7 +42,7 @@ public class LinkedHashMapFeedInfoCache extends HashMapFeedInfoCache {
/** /**
* Get the global instance of the cache * Get the global instance of the cache
* *
* @return an implementation of FeedFetcherCache * @return an implementation of FeedFetcherCache
*/ */
public static final FeedFetcherCache getInstance() { public static final FeedFetcherCache getInstance() {
@ -53,11 +53,12 @@ public class LinkedHashMapFeedInfoCache extends HashMapFeedInfoCache {
* <p> * <p>
* Constructor for HashMapFeedInfoCache * Constructor for HashMapFeedInfoCache
* </p> * </p>
* *
* <p> * <p>
* Only use this if you want multiple instances of the cache. Usually {@link #getInstance()} is more appropriate. * Only use this if you want multiple instances of the cache. Usually {@link #getInstance()} is
* more appropriate.
* </p> * </p>
* *
* @see #getInstance() * @see #getInstance()
*/ */
public LinkedHashMapFeedInfoCache() { public LinkedHashMapFeedInfoCache() {

View file

@ -22,7 +22,7 @@ import java.util.regex.Pattern;
/** /**
* Utility class to help deal with HTTP responses * Utility class to help deal with HTTP responses
* *
*/ */
public class ResponseHandler { public class ResponseHandler {
public static final String defaultCharacterEncoding = "ISO-8859-1"; public static final String defaultCharacterEncoding = "ISO-8859-1";
@ -34,12 +34,14 @@ public class ResponseHandler {
} }
/** /**
* *
* <p> * <p>
* Gets the character encoding of a response. (Note that this is different to the content-encoding) * Gets the character encoding of a response. (Note that this is different to the
* content-encoding)
* </p> * </p>
* *
* @param contentTypeHeader the value of the content-type HTTP header eg: text/html; charset=ISO-8859-4 * @param contentTypeHeader the value of the content-type HTTP header eg: text/html;
* charset=ISO-8859-4
* @return the character encoding, eg: ISO-8859-4 * @return the character encoding, eg: ISO-8859-4
*/ */
public static String getCharacterEncoding(final String contentTypeHeader) { public static String getCharacterEncoding(final String contentTypeHeader) {

View file

@ -24,13 +24,14 @@ import com.sun.syndication.feed.synd.SyndFeed;
/** /**
* <p> * <p>
* A class to represent a {@link com.sun.syndication.feed.synd.SyndFeed} and some useful information about it. * A class to represent a {@link com.sun.syndication.feed.synd.SyndFeed} and some useful information
* about it.
* </p> * </p>
* *
* <p> * <p>
* This class is thread safe, as expected by the different feed fetcher implementations. * This class is thread safe, as expected by the different feed fetcher implementations.
* </p> * </p>
* *
* @author Nick Lothian * @author Nick Lothian
*/ */
public class SyndFeedInfo implements Cloneable, Serializable { public class SyndFeedInfo implements Cloneable, Serializable {
@ -50,10 +51,10 @@ public class SyndFeedInfo implements Cloneable, Serializable {
/** /**
* Creates a deep 'bean' clone of the object. * Creates a deep 'bean' clone of the object.
* <p> * <p>
* *
* @return a clone of the object. * @return a clone of the object.
* @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
* *
*/ */
@Override @Override
public Object clone() throws CloneNotSupportedException { public Object clone() throws CloneNotSupportedException {
@ -61,12 +62,13 @@ public class SyndFeedInfo implements Cloneable, Serializable {
} }
/** /**
* Indicates whether some other object is "equal to" this one as defined by the Object equals() method. * Indicates whether some other object is "equal to" this one as defined by the Object equals()
* method.
* <p> * <p>
* *
* @param other he reference object with which to compare. * @param other he reference object with which to compare.
* @return <b>true</b> if 'this' object is equal to the 'other' object. * @return <b>true</b> if 'this' object is equal to the 'other' object.
* *
*/ */
@Override @Override
public boolean equals(final Object other) { public boolean equals(final Object other) {
@ -78,9 +80,9 @@ public class SyndFeedInfo implements Cloneable, Serializable {
* <p> * <p>
* It follows the contract defined by the Object hashCode() method. * It follows the contract defined by the Object hashCode() method.
* <p> * <p>
* *
* @return the hashcode of the bean object. * @return the hashcode of the bean object.
* *
*/ */
@Override @Override
public int hashCode() { public int hashCode() {
@ -90,9 +92,9 @@ public class SyndFeedInfo implements Cloneable, Serializable {
/** /**
* Returns the String representation for the object. * Returns the String representation for the object.
* <p> * <p>
* *
* @return String representation for the object. * @return String representation for the object.
* *
*/ */
@Override @Override
public String toString() { public String toString() {
@ -148,7 +150,8 @@ public class SyndFeedInfo implements Cloneable, Serializable {
} }
/** /**
* @param string A unique ID to identify the feed. Note that if the URL of the feed changes this will remain the same * @param string A unique ID to identify the feed. Note that if the URL of the feed changes this
* will remain the same
*/ */
public synchronized void setId(final String string) { public synchronized void setId(final String string) {
id = string; id = string;

View file

@ -25,7 +25,6 @@ import com.rometools.fetcher.FeedFetcher;
import com.rometools.fetcher.impl.FeedFetcherCache; import com.rometools.fetcher.impl.FeedFetcherCache;
import com.rometools.fetcher.impl.HashMapFeedInfoCache; import com.rometools.fetcher.impl.HashMapFeedInfoCache;
import com.rometools.fetcher.impl.HttpURLFeedFetcher; import com.rometools.fetcher.impl.HttpURLFeedFetcher;
import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndFeedImpl; import com.sun.syndication.feed.synd.SyndFeedImpl;
@ -33,16 +32,17 @@ import com.sun.syndication.io.SyndFeedOutput;
/** /**
* <p> * <p>
* It aggregates a list of RSS/Atom feeds (they can be of different types) into a single feed of the specified type. * It aggregates a list of RSS/Atom feeds (they can be of different types) into a single feed of the
* specified type.
* </p> * </p>
* *
* <p> * <p>
* Converted from the original FeedAggregator sample * Converted from the original FeedAggregator sample
* </p> * </p>
* *
* @author Alejandro Abdelnur * @author Alejandro Abdelnur
* @author Nick Lothian * @author Nick Lothian
* *
*/ */
public class FeedAggregator { public class FeedAggregator {

View file

@ -25,16 +25,15 @@ import com.rometools.fetcher.FetcherListener;
import com.rometools.fetcher.impl.FeedFetcherCache; import com.rometools.fetcher.impl.FeedFetcherCache;
import com.rometools.fetcher.impl.HashMapFeedInfoCache; import com.rometools.fetcher.impl.HashMapFeedInfoCache;
import com.rometools.fetcher.impl.HttpURLFeedFetcher; import com.rometools.fetcher.impl.HttpURLFeedFetcher;
import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeed;
/** /**
* Reads and prints any RSS/Atom feed type. Converted from the original Rome sample FeedReader * Reads and prints any RSS/Atom feed type. Converted from the original Rome sample FeedReader
* <p> * <p>
* *
* @author Alejandro Abdelnur * @author Alejandro Abdelnur
* @author Nick Lothian * @author Nick Lothian
* *
*/ */
public class FeedReader { public class FeedReader {
public static void main(final String[] args) { public static void main(final String[] args) {

View file

@ -29,15 +29,15 @@ import org.mortbay.http.SocketListener;
import org.mortbay.http.UserRealm; import org.mortbay.http.UserRealm;
import org.mortbay.http.handler.SecurityHandler; import org.mortbay.http.handler.SecurityHandler;
import org.mortbay.jetty.servlet.ServletHandler; import org.mortbay.jetty.servlet.ServletHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rometools.fetcher.FeedFetcher; import com.rometools.fetcher.FeedFetcher;
import com.rometools.fetcher.FetcherEvent; import com.rometools.fetcher.FetcherEvent;
import com.rometools.fetcher.FetcherException; import com.rometools.fetcher.FetcherException;
import com.rometools.fetcher.FetcherListener; import com.rometools.fetcher.FetcherListener;
import com.rometools.fetcher.impl.FeedFetcherCache; import com.rometools.fetcher.impl.FeedFetcherCache;
import com.rometools.fetcher.impl.HashMapFeedInfoCache; import com.rometools.fetcher.impl.HashMapFeedInfoCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.sun.syndication.feed.atom.Entry; import com.sun.syndication.feed.atom.Entry;
import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeed;

View file

@ -59,7 +59,8 @@ public class FetcherTestServlet extends HttpServlet {
/** /**
* @throws IOException * @throws IOException
* @throws * @throws
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/ */
@Override @Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {

View file

@ -18,6 +18,7 @@ package com.rometools.test;
import org.apache.commons.httpclient.Credentials; import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.UsernamePasswordCredentials;
import com.rometools.fetcher.FeedFetcher; import com.rometools.fetcher.FeedFetcher;
import com.rometools.fetcher.impl.FeedFetcherCache; import com.rometools.fetcher.impl.FeedFetcherCache;
import com.rometools.fetcher.impl.HttpClientFeedFetcher; import com.rometools.fetcher.impl.HttpClientFeedFetcher;