diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/jogamp/hungryharry/Config.java | 8 | ||||
-rw-r--r-- | src/main/java/com/jogamp/hungryharry/FeedAggregator.java | 30 | ||||
-rw-r--r-- | src/main/java/com/jogamp/hungryharry/config.xml | 4 |
3 files changed, 37 insertions, 5 deletions
diff --git a/src/main/java/com/jogamp/hungryharry/Config.java b/src/main/java/com/jogamp/hungryharry/Config.java index 93708aa..57f04dc 100644 --- a/src/main/java/com/jogamp/hungryharry/Config.java +++ b/src/main/java/com/jogamp/hungryharry/Config.java @@ -89,6 +89,9 @@ public class Config { public final String title; @XmlAttribute + public final String name; + + @XmlAttribute public final String description; @XmlAttribute @@ -100,6 +103,9 @@ public class Config { @XmlAttribute public final int maxEntries; + @XmlAttribute + public final int maxEntriesPerPage; + @XmlElement(name="feed") public final List<PlanetFeed> feeds; @@ -111,6 +117,7 @@ public class Config { public Planet() { title = null; + name = null; description = null; author = null; link = null; @@ -118,6 +125,7 @@ public class Config { templatePath = null; outputFolder = null; maxEntries = 0; + maxEntriesPerPage = Integer.MAX_VALUE; } public String getLink() { diff --git a/src/main/java/com/jogamp/hungryharry/FeedAggregator.java b/src/main/java/com/jogamp/hungryharry/FeedAggregator.java index 974b4bc..2060e14 100644 --- a/src/main/java/com/jogamp/hungryharry/FeedAggregator.java +++ b/src/main/java/com/jogamp/hungryharry/FeedAggregator.java @@ -15,7 +15,6 @@ 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; @@ -141,16 +140,32 @@ public class FeedAggregator { aggregatedEntries.add(map); } - generatePage(syndFeeds, aggregatedEntries, planet); + + int max = planet.maxEntriesPerPage; + int pages = (int) Math.ceil(aggregatedEntries.size() / (float)max); + System.out.println(pages); + for(int i = 0; i < pages; i++) { + List<Map<String, Object>> subList = aggregatedEntries.subList(i * max, Math.min(i * max + max, aggregatedEntries.size()-1)); + generatePage(i, pages, syndFeeds, subList, planet); + } + } - private void generatePage(List<SyndFeed> syndFeeds, List<Map<String, Object>> entries, Planet planet) { + private void generatePage(int index, int pages, List<SyndFeed> syndFeeds, List<Map<String, Object>> entries, Planet planet) { + + String name = pageName(planet, index, pages); Map<String, Object> root = new HashMap<String, Object>(); root.put("entries", entries); root.put("planet", planet); root.put("feedlinks", planet.feeds); root.put("feeds", syndFeeds); + root.put("page", index+1); + root.put("pages", pages); + root.put("filename", name); + root.put("prev", pageName(planet, index-1, pages)); + root.put("next", pageName(planet, index+1, pages)); + try { String templateFolder = cutoffTail(planet.templatePath, '/'); String templateName = planet.templatePath.substring(templateFolder.length()); @@ -165,7 +180,7 @@ public class FeedAggregator { cfg.setDefaultEncoding("UTF8"); Template template = cfg.getTemplate(templateName); - Writer writer = new FileWriter(new File(planet.outputFolder + separator + "planet.html")); + Writer writer = new FileWriter(new File(planet.outputFolder + separator + name)); template.process(root, writer); writer.close(); } catch (IOException ex) { @@ -175,6 +190,13 @@ public class FeedAggregator { } } + private String pageName(Planet planet, int index, int pages) { + if(index < 0 || index >= pages) { + return null; + } + return planet.name + (index == 0 ? "" : index) + ".html"; + } + private void createAggregatedFeed(Planet planet, List<SyndEntry> entries) { for (Planet.PlanetFeed planetFeed : planet.feeds) { diff --git a/src/main/java/com/jogamp/hungryharry/config.xml b/src/main/java/com/jogamp/hungryharry/config.xml index 311c574..4ea62b2 100644 --- a/src/main/java/com/jogamp/hungryharry/config.xml +++ b/src/main/java/com/jogamp/hungryharry/config.xml @@ -4,7 +4,9 @@ <planet title="JogAmp Streams" description="JogAmp Aggregated Feeds" author="Hungry Harry" - maxEntries="6" + maxEntries="15" + maxEntriesPerPage="5" + name="index" link="/home/mbien/NetBeansProjects/JOGAMP/stream"> <feed>atom_0.3</feed> <feed>rss_2.0</feed> |