From 057a46982292c765e664f886097fdaf33ed22a62 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Wed, 31 Aug 2011 22:26:55 +0200 Subject: Wrap it all in a single command handler. --- org/madore/damlengine/WeblogSelect.java | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'org/madore/damlengine/WeblogSelect.java') 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(); wsc.xmlData = new ArrayList(); 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); } -- cgit v1.2.3