diff options
author | Michael Bien <[email protected]> | 2010-08-23 19:35:37 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-08-23 19:35:37 +0200 |
commit | dbb10aea19c9d8647a326074361b0acfb4354178 (patch) | |
tree | 46f7da6892998fcf156bd521588b63db92839778 | |
parent | 307b85dc58eaed06e74472ce0f5d0d2026193053 (diff) |
preparations for blog feed aggregation; more freemarker data etc.
-rw-r--r-- | nb-configuration.xml | 3 | ||||
-rw-r--r-- | nbactions-planet.xml | 40 | ||||
-rw-r--r-- | src/main/java/com/jogamp/hungryharry/Config.java | 3 | ||||
-rw-r--r-- | src/main/java/com/jogamp/hungryharry/FeedAggregator.java | 38 |
4 files changed, 74 insertions, 10 deletions
diff --git a/nb-configuration.xml b/nb-configuration.xml index 3486bc9..620063c 100644 --- a/nb-configuration.xml +++ b/nb-configuration.xml @@ -15,4 +15,7 @@ Any value defined here will override the pom.xml file value but is only applicab --> <netbeans.compile.on.save>all</netbeans.compile.on.save> </properties> + <config-data xmlns="http://www.netbeans.org/ns/maven-config-data/1"> + <configurations/> + </config-data> </project-shared-configuration> diff --git a/nbactions-planet.xml b/nbactions-planet.xml new file mode 100644 index 0000000..36b76e9 --- /dev/null +++ b/nbactions-planet.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8"?> +<actions> + <action> + <actionName>run</actionName> + <goals> + <goal>process-classes</goal> + <goal>org.codehaus.mojo:exec-maven-plugin:1.1.1:exec</goal> + </goals> + <properties> + <exec.classpathScope>runtime</exec.classpathScope> + <exec.args>-classpath %classpath com.jogamp.hungryharry.FeedAggregator /home/mbien/NetBeansProjects/JOGAMP/planet2/config/planet-config.xml</exec.args> + <exec.executable>java</exec.executable> + </properties> + </action> + <action> + <actionName>debug</actionName> + <goals> + <goal>process-classes</goal> + <goal>org.codehaus.mojo:exec-maven-plugin:1.1.1:exec</goal> + </goals> + <properties> + <exec.classpathScope>runtime</exec.classpathScope> + <exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath com.jogamp.hungryharry.FeedAggregator /home/mbien/NetBeansProjects/JOGAMP/planet2/config/planet-config.xml</exec.args> + <jpda.listen>true</jpda.listen> + <exec.executable>java</exec.executable> + </properties> + </action> + <action> + <actionName>profile</actionName> + <goals> + <goal>process-classes</goal> + <goal>org.codehaus.mojo:exec-maven-plugin:1.1.1:exec</goal> + </goals> + <properties> + <exec.args>${profiler.args} -classpath %classpath com.jogamp.hungryharry.FeedAggregator /home/mbien/NetBeansProjects/JOGAMP/planet2/config/planet-config.xml</exec.args> + <profiler.action>profile</profiler.action> + <exec.executable>${profiler.java}</exec.executable> + </properties> + </action> +</actions> diff --git a/src/main/java/com/jogamp/hungryharry/Config.java b/src/main/java/com/jogamp/hungryharry/Config.java index b80a093..93708aa 100644 --- a/src/main/java/com/jogamp/hungryharry/Config.java +++ b/src/main/java/com/jogamp/hungryharry/Config.java @@ -3,6 +3,7 @@ */ package com.jogamp.hungryharry; +import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; @@ -29,7 +30,7 @@ public class Config { public Config() { feed = null; - template = null; + template = new ArrayList<Template>(); planet = null; } diff --git a/src/main/java/com/jogamp/hungryharry/FeedAggregator.java b/src/main/java/com/jogamp/hungryharry/FeedAggregator.java index 0d076d0..6488368 100644 --- a/src/main/java/com/jogamp/hungryharry/FeedAggregator.java +++ b/src/main/java/com/jogamp/hungryharry/FeedAggregator.java @@ -5,6 +5,7 @@ package com.jogamp.hungryharry; import com.jogamp.hungryharry.Config.Feed; import com.jogamp.hungryharry.Config.Planet; +import com.sun.syndication.feed.synd.SyndContent; import com.sun.syndication.io.SyndFeedOutput; import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.fetcher.FetcherException; @@ -71,7 +72,8 @@ public class FeedAggregator { } List<Config.Feed> feeds = config.feed; - List<SyndEntry> entries = downloadFeeds(feeds); + List<SyndFeed> syndFeeds = new ArrayList<SyndFeed>(); + List<SyndEntry> entries = downloadFeeds(feeds, syndFeeds); Planet planet = config.planet; new File(planet.outputFolder).mkdirs(); @@ -86,6 +88,24 @@ public class FeedAggregator { if(n++ >= planet.maxEntries) { break; } + Map<String, Object> map = new HashMap<String, Object>(); + map.put("title", entry.getTitle()); + map.put("link", entry.getLink()); + map.put("published", entry.getPublishedDate()); + map.put("updated", entry.getUpdatedDate()); + map.put("description", entry.getDescription()); + + StringBuilder sb = new StringBuilder(); + List contents = entry.getContents(); + for (Object content : contents) { + sb.append(((SyndContent)content).getValue()); + } + if(sb.length() == 0) { + map.put("content", entry.getDescription().getValue()); + }else{ + map.put("content", sb); + } + String link = entry.getLink(); for (Config.Template template : config.template) { if(link.contains(template.keyword)) { @@ -93,7 +113,6 @@ public class FeedAggregator { matcher.find(); String playercode = template.text.replaceAll("#id#", matcher.group(1)); - Map<String, Object> map = new HashMap<String, Object>(); map.put("player", playercode); String filteredDescription = entry.getDescription().getValue(); @@ -103,24 +122,24 @@ public class FeedAggregator { filter.find(); filteredDescription = filter.group(1); } - map.put("description", filteredDescription); + map.put("filteredDescription", filteredDescription); - aggregatedEntries.add(map); break; } } + aggregatedEntries.add(map); } - generatePage(aggregatedEntries, planet); + generatePage(syndFeeds, aggregatedEntries, planet); } - private void generatePage(List<Map<String, Object>> entries, Planet planet) { + private void generatePage(List<SyndFeed> syndFeeds, List<Map<String, Object>> entries, Planet planet) { Map<String, Object> root = new HashMap<String, Object>(); root.put("entries", entries); root.put("planet", planet); - root.put("feeds", planet.feeds); - + root.put("feedlinks", planet.feeds); + root.put("feeds", syndFeeds); try { String templateFolder = cutoffTail(planet.templatePath, '/'); String templateName = planet.templatePath.substring(templateFolder.length()); @@ -168,7 +187,7 @@ public class FeedAggregator { } } - private List<SyndEntry> downloadFeeds(List<Feed> feeds) throws IllegalArgumentException { + private List<SyndEntry> downloadFeeds(List<Feed> feeds, List<SyndFeed> list) throws IllegalArgumentException { FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance(); FeedFetcher feedFetcher = new HttpURLFeedFetcher(feedInfoCache); @@ -178,6 +197,7 @@ public class FeedAggregator { LOG.info("downloading "+feed); try { SyndFeed inFeed = feedFetcher.retrieveFeed(new URL(feed.url)); + list.add(inFeed); entries.addAll(inFeed.getEntries()); } catch (IOException ex) { LOG.log(WARNING, "skipping feed", ex); |