diff options
author | Michael Bien <[email protected]> | 2010-08-29 02:59:54 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-08-29 02:59:54 +0200 |
commit | cbddbba4b05630416897ebdb8c09f844116aa3f8 (patch) | |
tree | c07f061914a1ee88eb4bec4f2130ba9bb5794d0e /src/main/java/com/jogamp/hungryharry | |
parent | 2ed87beb06ac0b62354829daa675a8e23ce0288b (diff) |
a few fixes to allow more feed types + more logging.
Diffstat (limited to 'src/main/java/com/jogamp/hungryharry')
-rw-r--r-- | src/main/java/com/jogamp/hungryharry/FeedAggregator.java | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/src/main/java/com/jogamp/hungryharry/FeedAggregator.java b/src/main/java/com/jogamp/hungryharry/FeedAggregator.java index eeb52f9..974b4bc 100644 --- a/src/main/java/com/jogamp/hungryharry/FeedAggregator.java +++ b/src/main/java/com/jogamp/hungryharry/FeedAggregator.java @@ -15,6 +15,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; +import java.util.Date; import java.util.List; import com.sun.syndication.feed.synd.SyndFeedImpl; @@ -83,18 +84,20 @@ public class FeedAggregator { List<Map<String, Object>> aggregatedEntries = new ArrayList<Map<String, Object>>(entries.size()); int n = 0; + LOG.info(entries.size()+" entries found"); for (SyndEntry entry : entries) { if(n++ >= planet.maxEntries) { break; } + SyndContent description = entry.getDescription(); Map<String, Object> map = new HashMap<String, Object>(); map.put("title", entry.getTitle()); map.put("link", entry.getLink()); map.put("author", entry.getAuthor()); map.put("published", entry.getPublishedDate()); map.put("updated", entry.getUpdatedDate()); - map.put("description", entry.getDescription()); + map.put("description", description); StringBuilder sb = new StringBuilder(); List contents = entry.getContents(); @@ -102,7 +105,7 @@ public class FeedAggregator { sb.append(((SyndContent)content).getValue()); } if(sb.length() == 0) { - map.put("content", entry.getDescription().getValue()); + map.put("content", description.getValue()); }else{ map.put("content", sb); } @@ -116,13 +119,20 @@ public class FeedAggregator { map.put("player", playercode); - String filteredDescription = entry.getDescription().getValue(); - if(template.descriptionfilter != null) { - Pattern descPattern = Pattern.compile(template.descriptionfilter); - Matcher filter = descPattern.matcher(filteredDescription); - filter.find(); - filteredDescription = filter.group(1); + String filteredDescription = null; + //TODO sometimes there is only content + if(description == null) { + filteredDescription = sb.toString(); + }else{ + filteredDescription = description.getValue(); + if(template.descriptionfilter != null) { + Pattern descPattern = Pattern.compile(template.descriptionfilter); + Matcher filter = descPattern.matcher(filteredDescription); + filter.find(); + filteredDescription = filter.group(1); + } } + map.put("filteredDescription", filteredDescription); break; @@ -193,14 +203,17 @@ public class FeedAggregator { FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance(); FeedFetcher feedFetcher = new HttpURLFeedFetcher(feedInfoCache); - List<SyndEntry> entries = new ArrayList<SyndEntry>(); + List<SyndEntry> collectedEntries = new ArrayList<SyndEntry>(); for (Config.Feed feed : feeds) { LOG.info("downloading "+feed); try { SyndFeed inFeed = feedFetcher.retrieveFeed(new URL(feed.url)); list.add(inFeed); - entries.addAll(inFeed.getEntries()); + List entries = inFeed.getEntries(); + + LOG.info("downloaded "+entries.size()+ " entries"); + collectedEntries.addAll(entries); } catch (IOException ex) { LOG.log(WARNING, "skipping feed", ex); } catch (FetcherException ex) { @@ -210,13 +223,13 @@ public class FeedAggregator { } } - sort(entries, new Comparator<SyndEntry>() { + sort(collectedEntries, new Comparator<SyndEntry>() { @Override public int compare(SyndEntry o1, SyndEntry o2) { return o2.getPublishedDate().compareTo(o1.getPublishedDate()); } }); - return entries; + return collectedEntries; } private Config readConfiguration() throws JAXBException, FileNotFoundException { |