summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/WeblogSelect.java
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2011-08-31 22:26:55 +0200
committerDavid A. Madore <david+git@madore.org>2011-08-31 22:26:55 +0200
commit057a46982292c765e664f886097fdaf33ed22a62 (patch)
treef9ba446ae36f4e13f4b579b293ace2004a0dbf29 /org/madore/damlengine/WeblogSelect.java
parent3d44424a1738ce3f70c82780f4441e077c1194a3 (diff)
downloaddamlengine-057a46982292c765e664f886097fdaf33ed22a62.tar.gz
damlengine-057a46982292c765e664f886097fdaf33ed22a62.tar.bz2
damlengine-057a46982292c765e664f886097fdaf33ed22a62.zip
Wrap it all in a single command handler.
Diffstat (limited to 'org/madore/damlengine/WeblogSelect.java')
-rw-r--r--org/madore/damlengine/WeblogSelect.java32
1 files changed, 21 insertions, 11 deletions
diff --git a/org/madore/damlengine/WeblogSelect.java b/org/madore/damlengine/WeblogSelect.java
index cb263e6..1593d72 100644
--- a/org/madore/damlengine/WeblogSelect.java
+++ b/org/madore/damlengine/WeblogSelect.java
@@ -2,6 +2,7 @@ package org.madore.damlengine;
import java.util.HashSet;
import java.util.ArrayList;
+import java.io.OutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -12,21 +13,30 @@ public final class WeblogSelect {
throw new AssertionError("WeblogSelect cannot be instantiated");
}
- public static void main(String[] args)
+ public static void fullProcess(Context.WeblogSelectionContext wsc,
+ OutputStream out)
throws Exception {
- String year = "2011";
- String month = "08";
-
final Connection conn = WeblogDatabaseConnection.getConnection();
- final PreparedStatement selSt
- = conn.prepareStatement("SELECT id , content FROM entries WHERE edate LIKE ? ORDER BY id DESC");
- selSt.setString(1,year+"-"+month+"-__");
+ String templateResourceName;
+ final PreparedStatement selSt;
+ if ( wsc instanceof Context.WeblogMonthSelectionContext ) {
+ templateResourceName = "weblog-month-template.daml";
+ selSt = conn.prepareStatement("SELECT id , content FROM entries WHERE edate LIKE ? ORDER BY id DESC");
+ selSt.setString(1,((Context.WeblogMonthSelectionContext)wsc).year+"-"+((Context.WeblogMonthSelectionContext)wsc).month+"-__");
+ } else if ( wsc instanceof Context.WeblogCategorySelectionContext ) {
+ templateResourceName = "weblog-cat-template.daml";
+ selSt = conn.prepareStatement("SELECT entries.id , entries.content FROM entries , incat WHERE entries.id=incat.id AND incat.code=? ORDER BY entries.id DESC");
+ selSt.setString(1,((Context.WeblogCategorySelectionContext)wsc).code);
+ } else if ( wsc instanceof Context.WeblogRecentSelectionContext ) {
+ templateResourceName = "weblog-recent-template.daml";
+ selSt = conn.prepareStatement("SELECT id , content FROM entries ORDER BY id DESC LIMIT ?");
+ selSt.setInt(1,((Context.WeblogRecentSelectionContext)wsc).count);
+ } else
+ throw new IllegalArgumentException("don't know how to perform this selection");
final ResultSet selRes = selSt.executeQuery();
- final Context.WeblogSelectionContext wsc
- = new Context.WeblogMonthSelectionContext(year,month);
wsc.sel = new HashSet<Integer>();
wsc.xmlData = new ArrayList<String>();
while ( selRes.next() ) {
@@ -36,8 +46,8 @@ public final class WeblogSelect {
wsc.xmlData.add(content);
}
- DamlEngine.fullProcess(DamlEngine.class.getResourceAsStream("weblog-month-template.daml"),
- System.out, wsc);
+ DamlEngine.fullProcess(DamlEngine.class.getResourceAsStream(templateResourceName),
+ out, wsc);
}