Updated rome-fetcher to use generics
Removed warnings
This commit is contained in:
parent
12fa5bbab6
commit
0dde9fdb9e
10 changed files with 64 additions and 37 deletions
|
@ -34,13 +34,13 @@ import org.rometools.fetcher.FetcherListener;
|
|||
import com.sun.syndication.feed.synd.SyndFeed;
|
||||
|
||||
public abstract class AbstractFeedFetcher implements FeedFetcher {
|
||||
private final Set fetcherEventListeners;
|
||||
private final Set<FetcherListener> fetcherEventListeners;
|
||||
private String userAgent;
|
||||
private boolean usingDeltaEncoding;
|
||||
private boolean preserveWireFeed;
|
||||
|
||||
public AbstractFeedFetcher() {
|
||||
fetcherEventListeners = Collections.synchronizedSet(new HashSet());
|
||||
fetcherEventListeners = Collections.synchronizedSet(new HashSet<FetcherListener>());
|
||||
|
||||
final Properties props = new Properties(System.getProperties());
|
||||
final String resourceName = "fetcher.properties";
|
||||
|
@ -114,9 +114,9 @@ public abstract class AbstractFeedFetcher implements FeedFetcher {
|
|||
protected void fireEvent(final String eventType, final String urlStr, final SyndFeed feed) {
|
||||
final FetcherEvent fetcherEvent = new FetcherEvent(this, urlStr, eventType, feed);
|
||||
synchronized (fetcherEventListeners) {
|
||||
final Iterator iter = fetcherEventListeners.iterator();
|
||||
final Iterator<FetcherListener> iter = fetcherEventListeners.iterator();
|
||||
while (iter.hasNext()) {
|
||||
final FetcherListener fetcherEventListener = (FetcherListener) iter.next();
|
||||
final FetcherListener fetcherEventListener = iter.next();
|
||||
fetcherEventListener.fetcherEvent(fetcherEvent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,14 +12,12 @@ public class AbstractFeedFetcherBeanInfo extends SimpleBeanInfo {
|
|||
@Override
|
||||
public EventSetDescriptor[] getEventSetDescriptors() {
|
||||
try {
|
||||
final Class 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 removeMethod = clz.getMethod("removeFetcherEventListener", new Class[] { FetcherListener.class });
|
||||
final Method listenerMethod = FetcherListener.class.getMethod("fetcherEvent", new Class[] { FetcherEvent.class });
|
||||
|
||||
final EventSetDescriptor est = new EventSetDescriptor("fetcherEvent", clz, new Method[] { listenerMethod }, addMethod, removeMethod);
|
||||
final EventSetDescriptor[] results = new EventSetDescriptor[] { est };
|
||||
|
||||
return results;
|
||||
} catch (final Exception e) {
|
||||
// IntrospectionException, SecurityException and/or NoSuchMethodException can be thrown here
|
||||
|
@ -27,4 +25,5 @@ public class AbstractFeedFetcherBeanInfo extends SimpleBeanInfo {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,20 +39,33 @@ public class DiskFeedInfoCache implements FeedFetcherCache {
|
|||
public SyndFeedInfo getFeedInfo(final URL url) {
|
||||
SyndFeedInfo info = null;
|
||||
final String fileName = cachePath + File.separator + "feed_" + replaceNonAlphanumeric(url.toString(), '_').trim();
|
||||
FileInputStream fis;
|
||||
FileInputStream fis = null;
|
||||
ObjectInputStream ois = null;
|
||||
try {
|
||||
fis = new FileInputStream(fileName);
|
||||
final ObjectInputStream ois = new ObjectInputStream(fis);
|
||||
ois = new ObjectInputStream(fis);
|
||||
info = (SyndFeedInfo) ois.readObject();
|
||||
fis.close();
|
||||
} catch (final FileNotFoundException fnfe) {
|
||||
} catch (final FileNotFoundException e) {
|
||||
// That's OK, we'l return null
|
||||
} catch (final ClassNotFoundException cnfe) {
|
||||
} catch (final ClassNotFoundException e) {
|
||||
// Error writing to cache is fatal
|
||||
throw new RuntimeException("Attempting to read from cache", cnfe);
|
||||
} catch (final IOException fnfe) {
|
||||
throw new RuntimeException("Attempting to read from cache", e);
|
||||
} catch (final IOException e) {
|
||||
// Error writing to cache is fatal
|
||||
throw new RuntimeException("Attempting to read from cache", fnfe);
|
||||
throw new RuntimeException("Attempting to read from cache", e);
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (final IOException e) {
|
||||
}
|
||||
}
|
||||
if (ois != null) {
|
||||
try {
|
||||
ois.close();
|
||||
} catch (final IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
@ -110,12 +123,12 @@ public class DiskFeedInfoCache implements FeedFetcherCache {
|
|||
public SyndFeedInfo remove(final URL url) {
|
||||
SyndFeedInfo info = null;
|
||||
final String fileName = cachePath + File.separator + "feed_" + replaceNonAlphanumeric(url.toString(), '_').trim();
|
||||
FileInputStream fis;
|
||||
FileInputStream fis = null;
|
||||
ObjectInputStream ois = null;
|
||||
try {
|
||||
fis = new FileInputStream(fileName);
|
||||
final ObjectInputStream ois = new ObjectInputStream(fis);
|
||||
ois = new ObjectInputStream(fis);
|
||||
info = (SyndFeedInfo) ois.readObject();
|
||||
fis.close();
|
||||
|
||||
final File file = new File(fileName);
|
||||
if (file.exists()) {
|
||||
|
@ -129,6 +142,19 @@ public class DiskFeedInfoCache implements FeedFetcherCache {
|
|||
} catch (final IOException fnfe) {
|
||||
// Error writing to cahce is fatal
|
||||
throw new RuntimeException("Attempting to read from cache", fnfe);
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (final IOException e) {
|
||||
}
|
||||
}
|
||||
if (ois != null) {
|
||||
try {
|
||||
ois.close();
|
||||
} catch (final IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public class HashMapFeedInfoCache implements FeedFetcherCache, Serializable {
|
|||
|
||||
static HashMapFeedInfoCache _instance;
|
||||
|
||||
private Map infoCache;
|
||||
private Map<String, SyndFeedInfo> infoCache;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -68,8 +68,8 @@ public class HashMapFeedInfoCache implements FeedFetcherCache, Serializable {
|
|||
return _instance;
|
||||
}
|
||||
|
||||
protected Map createInfoCache() {
|
||||
return Collections.synchronizedMap(new HashMap());
|
||||
protected Map<String, SyndFeedInfo> createInfoCache() {
|
||||
return Collections.synchronizedMap(new HashMap<String, SyndFeedInfo>());
|
||||
}
|
||||
|
||||
protected Object get(final Object key) {
|
||||
|
@ -84,7 +84,7 @@ public class HashMapFeedInfoCache implements FeedFetcherCache, Serializable {
|
|||
return (SyndFeedInfo) get(feedUrl.toString());
|
||||
}
|
||||
|
||||
protected void put(final Object key, final Object value) {
|
||||
protected void put(final String key, final SyndFeedInfo value) {
|
||||
getInfoCache().put(key, value);
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ public class HashMapFeedInfoCache implements FeedFetcherCache, Serializable {
|
|||
put(feedUrl.toString(), syndFeedInfo);
|
||||
}
|
||||
|
||||
protected synchronized final Map getInfoCache() {
|
||||
protected synchronized final Map<String, SyndFeedInfo> getInfoCache() {
|
||||
return infoCache;
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ public class HashMapFeedInfoCache implements FeedFetcherCache, Serializable {
|
|||
*
|
||||
* @param map the map to use as the info cache.
|
||||
*/
|
||||
protected synchronized final void setInfoCache(final Map map) {
|
||||
protected synchronized final void setInfoCache(final Map<String, SyndFeedInfo> map) {
|
||||
infoCache = map;
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ public class HashMapFeedInfoCache implements FeedFetcherCache, Serializable {
|
|||
return null;
|
||||
}
|
||||
|
||||
return (SyndFeedInfo) infoCache.remove(url.toString());
|
||||
return infoCache.remove(url.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,13 +42,13 @@ import com.sun.syndication.io.XmlReader;
|
|||
* @author Nick Lothian
|
||||
*/
|
||||
public class HttpClientFeedFetcher extends AbstractFeedFetcher {
|
||||
|
||||
private CredentialSupplier credentialSupplier;
|
||||
private FeedFetcherCache feedInfoCache;
|
||||
private volatile HttpClientMethodCallbackIntf httpClientMethodCallback;
|
||||
private volatile HttpClientParams httpClientParams;
|
||||
|
||||
public HttpClientFeedFetcher() {
|
||||
super();
|
||||
setHttpClientParams(new HttpClientParams());
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,9 @@ import java.util.Map;
|
|||
*
|
||||
*/
|
||||
public class LinkedHashMapFeedInfoCache extends HashMapFeedInfoCache {
|
||||
private final class CacheImpl extends LinkedHashMap {
|
||||
|
||||
private final class CacheImpl extends LinkedHashMap<String, SyndFeedInfo> {
|
||||
|
||||
private static final long serialVersionUID = -6977191330127794920L;
|
||||
|
||||
public CacheImpl() {
|
||||
|
@ -26,19 +28,18 @@ public class LinkedHashMapFeedInfoCache extends HashMapFeedInfoCache {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean removeEldestEntry(final Map.Entry eldest) {
|
||||
protected boolean removeEldestEntry(final Map.Entry<String, SyndFeedInfo> eldest) {
|
||||
return size() > getMaxEntries();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final int DEFAULT_MAX_ENTRIES = 20;
|
||||
|
||||
private static final long serialVersionUID = 1694228973357997417L;
|
||||
private static final LinkedHashMapFeedInfoCache _instance = new LinkedHashMapFeedInfoCache();
|
||||
|
||||
private int maxEntries = DEFAULT_MAX_ENTRIES;
|
||||
|
||||
private final static LinkedHashMapFeedInfoCache _instance = new LinkedHashMapFeedInfoCache();
|
||||
|
||||
/**
|
||||
* Get the global instance of the cache
|
||||
*
|
||||
|
@ -64,7 +65,7 @@ public class LinkedHashMapFeedInfoCache extends HashMapFeedInfoCache {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Map createInfoCache() {
|
||||
protected Map<String, SyndFeedInfo> createInfoCache() {
|
||||
return Collections.synchronizedMap(new CacheImpl());
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.rometools.fetcher.impl.FeedFetcherCache;
|
|||
import org.rometools.fetcher.impl.HashMapFeedInfoCache;
|
||||
import org.rometools.fetcher.impl.HttpURLFeedFetcher;
|
||||
|
||||
import com.sun.syndication.feed.synd.SyndEntry;
|
||||
import com.sun.syndication.feed.synd.SyndFeed;
|
||||
import com.sun.syndication.feed.synd.SyndFeedImpl;
|
||||
import com.sun.syndication.io.SyndFeedOutput;
|
||||
|
@ -59,7 +60,7 @@ public class FeedAggregator {
|
|||
feed.setAuthor("anonymous");
|
||||
feed.setLink("http://www.anonymous.com");
|
||||
|
||||
final List entries = new ArrayList();
|
||||
final List<SyndEntry> entries = new ArrayList<SyndEntry>();
|
||||
feed.setEntries(entries);
|
||||
|
||||
final FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance();
|
||||
|
|
|
@ -61,7 +61,7 @@ public class FeedReader {
|
|||
// and the server supports conditional gets, we will get a "Feed
|
||||
// Unchanged" event after the Feed Polled event
|
||||
System.err.println("Polling " + feedUrl + " again to test conditional get support.");
|
||||
final SyndFeed feed2 = fetcher.retrieveFeed(feedUrl);
|
||||
fetcher.retrieveFeed(feedUrl);
|
||||
System.err.println("If a \"Feed Unchanged\" event fired then the server supports conditional gets.");
|
||||
|
||||
ok = true;
|
||||
|
|
|
@ -236,7 +236,7 @@ public abstract class AbstractJettyTest extends TestCase {
|
|||
public void testErrorHandling() {
|
||||
final FeedFetcher feedFetcher = getFeedFetcher();
|
||||
try {
|
||||
final SyndFeed feed = feedFetcher.retrieveFeed(new URL("http://localhost:" + testPort + "/rome/FetcherTestServlet?error=404"));
|
||||
feedFetcher.retrieveFeed(new URL("http://localhost:" + testPort + "/rome/FetcherTestServlet?error=404"));
|
||||
fail("4xx error handling did not work correctly");
|
||||
} catch (final FetcherException e) {
|
||||
// expect this exception
|
||||
|
@ -247,7 +247,7 @@ public abstract class AbstractJettyTest extends TestCase {
|
|||
}
|
||||
|
||||
try {
|
||||
final SyndFeed feed = feedFetcher.retrieveFeed(new URL("http://localhost:" + testPort + "/rome/FetcherTestServlet?error=500"));
|
||||
feedFetcher.retrieveFeed(new URL("http://localhost:" + testPort + "/rome/FetcherTestServlet?error=500"));
|
||||
fail("5xx error handling did not work correctly");
|
||||
} catch (final FetcherException e) {
|
||||
// expect this exception
|
||||
|
|
|
@ -177,7 +177,7 @@ public class FetcherTestServlet extends HttpServlet {
|
|||
feed.setLink("http://rome.dev.java.net");
|
||||
feed.setDescription("This tests using rfc3229 delta encoding.");
|
||||
|
||||
final List entries = new ArrayList();
|
||||
final List<SyndEntry> entries = new ArrayList<SyndEntry>();
|
||||
SyndEntry entry;
|
||||
SyndContent description;
|
||||
|
||||
|
|
Loading…
Reference in a new issue