summaryrefslogtreecommitdiffstats
path: root/src/main/java/com
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-08-23 04:13:08 +0200
committerMichael Bien <[email protected]>2010-08-23 04:13:08 +0200
commit307b85dc58eaed06e74472ce0f5d0d2026193053 (patch)
tree0afa76acffbee2eb81b36d8fa015c4b58ad014e3 /src/main/java/com
parentfa50256fae31ad8499ade311a4bfa4dc446a2ada (diff)
continued with freemarker model.
description filter. updated freemarker dependency.
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/jogamp/hungryharry/Config.java15
-rw-r--r--src/main/java/com/jogamp/hungryharry/FeedAggregator.java52
-rw-r--r--src/main/java/com/jogamp/hungryharry/config.xml8
3 files changed, 53 insertions, 22 deletions
diff --git a/src/main/java/com/jogamp/hungryharry/Config.java b/src/main/java/com/jogamp/hungryharry/Config.java
index 99a8363..b80a093 100644
--- a/src/main/java/com/jogamp/hungryharry/Config.java
+++ b/src/main/java/com/jogamp/hungryharry/Config.java
@@ -45,6 +45,12 @@ public class Config {
name = null;
url = null;
}
+
+ @Override
+ public String toString() {
+ return getClass().getName() + "[" + name + ", " + url+"]";
+ }
+
}
@XmlType
@@ -56,6 +62,9 @@ public class Config {
@XmlAttribute(name="idpattern")
public final String idpattern;
+ @XmlAttribute
+ public final String descriptionfilter;
+
@XmlValue
public final String text;
@@ -63,6 +72,12 @@ public class Config {
keyword = null;
text = null;
idpattern = null;
+ descriptionfilter = null;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getName() + "["+ keyword +"]";
}
}
diff --git a/src/main/java/com/jogamp/hungryharry/FeedAggregator.java b/src/main/java/com/jogamp/hungryharry/FeedAggregator.java
index 2f5ec27..0d076d0 100644
--- a/src/main/java/com/jogamp/hungryharry/FeedAggregator.java
+++ b/src/main/java/com/jogamp/hungryharry/FeedAggregator.java
@@ -12,7 +12,6 @@ import com.sun.syndication.io.FeedException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -24,7 +23,7 @@ import com.sun.syndication.fetcher.impl.FeedFetcherCache;
import com.sun.syndication.fetcher.impl.HashMapFeedInfoCache;
import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher;
import freemarker.template.Configuration;
-import freemarker.template.DefaultObjectWrapper;
+import freemarker.template.ObjectWrapper;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import java.io.File;
@@ -52,7 +51,7 @@ import static java.io.File.*;
*
*/
public class FeedAggregator {
-
+
private static final Logger LOG = Logger.getLogger(FeedAggregator.class.getName());
private final String configFile;
@@ -60,7 +59,7 @@ public class FeedAggregator {
this.configFile = configFile;
}
- private void aggregate() throws MalformedURLException {
+ private void aggregate() {
Config config = null;
try {
@@ -72,15 +71,17 @@ public class FeedAggregator {
}
List<Config.Feed> feeds = config.feed;
- List<SyndEntry> entries = loadFeeds(feeds);
+ List<SyndEntry> entries = downloadFeeds(feeds);
Planet planet = config.planet;
new File(planet.outputFolder).mkdirs();
createAggregatedFeed(planet, entries);
- StringBuilder content = new StringBuilder();
+ List<Map<String, Object>> aggregatedEntries = new ArrayList<Map<String, Object>>(entries.size());
int n = 0;
+
+
for (SyndEntry entry : entries) {
if(n++ >= planet.maxEntries) {
break;
@@ -88,22 +89,35 @@ public class FeedAggregator {
String link = entry.getLink();
for (Config.Template template : config.template) {
if(link.contains(template.keyword)) {
- Pattern pattern = Pattern.compile(template.idpattern);
- Matcher matcher = pattern.matcher(link);
+ Matcher matcher = Pattern.compile(template.idpattern).matcher(link);
matcher.find();
- content.append(template.text.replaceAll("#id#", matcher.group(1)));
+ 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();
+ if(template.descriptionfilter != null) {
+ Pattern descPattern = Pattern.compile(template.descriptionfilter);
+ Matcher filter = descPattern.matcher(filteredDescription);
+ filter.find();
+ filteredDescription = filter.group(1);
+ }
+ map.put("description", filteredDescription);
+
+ aggregatedEntries.add(map);
break;
}
}
}
- generatePage(content.toString(), planet);
+ generatePage(aggregatedEntries, planet);
}
- private void generatePage(String content, Planet planet) {
+ private void generatePage(List<Map<String, Object>> entries, Planet planet) {
Map<String, Object> root = new HashMap<String, Object>();
- root.put("content", content);
+ root.put("entries", entries);
root.put("planet", planet);
root.put("feeds", planet.feeds);
@@ -117,10 +131,11 @@ public class FeedAggregator {
cfg.setDirectoryForTemplateLoading(new File(templateFolder));
// Specify how templates will see the data-model. This is an advanced topic...
// but just use this:
- cfg.setObjectWrapper(new DefaultObjectWrapper());
- Template temp = cfg.getTemplate(templateName);
+ cfg.setObjectWrapper(ObjectWrapper.DEFAULT_WRAPPER);
+
+ Template template = cfg.getTemplate(templateName);
Writer writer = new FileWriter(new File(planet.outputFolder + separator + "planet.html"));
- temp.process(root, writer);
+ template.process(root, writer);
writer.close();
} catch (IOException ex) {
LOG.log(SEVERE, null, ex);
@@ -153,13 +168,14 @@ public class FeedAggregator {
}
}
- private List<SyndEntry> loadFeeds(List<Feed> feeds) throws IllegalArgumentException {
+ private List<SyndEntry> downloadFeeds(List<Feed> feeds) throws IllegalArgumentException {
FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance();
FeedFetcher feedFetcher = new HttpURLFeedFetcher(feedInfoCache);
List<SyndEntry> entries = new ArrayList<SyndEntry>();
for (Config.Feed feed : feeds) {
+ LOG.info("downloading "+feed);
try {
SyndFeed inFeed = feedFetcher.retrieveFeed(new URL(feed.url));
entries.addAll(inFeed.getEntries());
@@ -171,7 +187,7 @@ public class FeedAggregator {
LOG.log(WARNING, "skipping feed", ex);
}
}
-
+
sort(entries, new Comparator<SyndEntry>() {
@Override
public int compare(SyndEntry o1, SyndEntry o2) {
@@ -203,7 +219,7 @@ public class FeedAggregator {
return sb;
}
- public static void main(String... args) throws MalformedURLException {
+ public static void main(String... args) {
if(args.length < 1) {
System.out.println("args must contain a path to the configuration file");
diff --git a/src/main/java/com/jogamp/hungryharry/config.xml b/src/main/java/com/jogamp/hungryharry/config.xml
index f34377e..311c574 100644
--- a/src/main/java/com/jogamp/hungryharry/config.xml
+++ b/src/main/java/com/jogamp/hungryharry/config.xml
@@ -5,11 +5,11 @@
description="JogAmp Aggregated Feeds"
author="Hungry Harry"
maxEntries="6"
- link="/home/mbien/streams/out">
+ link="/home/mbien/NetBeansProjects/JOGAMP/stream">
<feed>atom_0.3</feed>
<feed>rss_2.0</feed>
- <template>/home/mbien/streams/planet-template.html</template>
- <output>/home/mbien/streams/out</output>
+ <template>/home/mbien/NetBeansProjects/JOGAMP/planet2/config/stream-template.html</template>
+ <output>/home/mbien/NetBeansProjects/JOGAMP/stream</output>
</planet>
<!--
<feed name="vimeo" url="http://vimeo.com/tag:jogl/rss"/>
@@ -28,7 +28,7 @@
</object>
]]>
</template>
- <template keyword="youtube" idpattern="http://www.youtube.com/watch\?v=([^&amp;]+)">
+ <template keyword="youtube" idpattern="http://www.youtube.com/watch\?v=([^&amp;]+)" descriptionfilter="&lt;span&gt;(.*)&lt;/span&gt;">
<![CDATA[
<object width="480" height="385">
<param name="movie" value="http://www.youtube.com/v/#id#&hl=en_US&fs=1&rel=0&color1=0x2b405b&color2=0x6b8ab6&hd=1"/>