From db0a709f2743d9502fb601bed4a1f115d3856c61 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sun, 28 Aug 2011 15:55:47 +0200 Subject: Prepare for weblog selection (and mess everything up). --- org/madore/damlengine/Context.java | 23 +++++++++++++++++++ org/madore/damlengine/DamlEngine.java | 39 ++++++++++++++++++++++++--------- org/madore/damlengine/TodoWrefAttr.java | 10 +++++++-- 3 files changed, 60 insertions(+), 12 deletions(-) (limited to 'org/madore/damlengine') diff --git a/org/madore/damlengine/Context.java b/org/madore/damlengine/Context.java index 5ae7285..d001389 100644 --- a/org/madore/damlengine/Context.java +++ b/org/madore/damlengine/Context.java @@ -25,6 +25,29 @@ public class Context implements Cloneable { public GeneralContext gc; + public static abstract class WeblogSelectionContext { + } + + public static class WeblogMonthSelectionContext + extends WeblogSelectionContext { + public String year; + public String month; + public WeblogMonthSelectionContext(String year, String month) { + this.year = year; + this.month = month; + } + } + + public static class WeblogCategorySelectionContext + extends WeblogSelectionContext { + public String code; + public WeblogCategorySelectionContext(String code) { + this.code = code; + } + } + + public WeblogSelectionContext wsc; + public static class EntryContext { public String year; public String month; diff --git a/org/madore/damlengine/DamlEngine.java b/org/madore/damlengine/DamlEngine.java index 0837bd3..f055de1 100644 --- a/org/madore/damlengine/DamlEngine.java +++ b/org/madore/damlengine/DamlEngine.java @@ -1,5 +1,6 @@ package org.madore.damlengine; +import java.io.OutputStream; import java.io.OutputStreamWriter; import javax.xml.XMLConstants; import javax.xml.namespace.NamespaceContext; @@ -55,14 +56,21 @@ public final class DamlEngine { } } - public static void processDocument(Document doc) { + public static void processDocument(Document doc, + Context.WeblogSelectionContext wsc) { TodoDeque todoDeque = new TodoDeque(); Context ctx = new Context(doc); + ctx.wsc = wsc; todoDeque.registerAtEnd(new RootTodo(ctx)); todoDeque.dispatchLoop(); } - public static void main(String[] args) + public static void processDocument(Document doc) { + processDocument(doc, null); + } + + public static void fullProcess(String fname, OutputStream out, + Context.WeblogSelectionContext wsc) throws Exception { final Resolver resolver = new Resolver(); @@ -72,19 +80,30 @@ public final class DamlEngine { final DocumentBuilder db = dbf.newDocumentBuilder(); db.setEntityResolver(resolver); + Document doc = db.parse(fname); + processDocument(doc, wsc); + doc.normalizeDocument(); + Unparser unparser + = new Unparser(doc, new OutputStreamWriter(out, "UTF-8"), + "html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\""); + unparser.unparse(); + + } + + public static void fullProcess(String fname, OutputStream out) + throws Exception { + fullProcess(fname, out, null); + } + + public static void main(String[] args) + throws Exception { + if ( args.length == 0 ) { System.err.println("expecting filename as argument"); } for (String fname : args) { - Document doc = db.parse(fname); - processDocument(doc); - doc.normalizeDocument(); - Unparser unparser - = new Unparser(doc, new OutputStreamWriter(System.out, - "UTF-8"), - "html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\""); - unparser.unparse(); + fullProcess (fname, System.out); } } diff --git a/org/madore/damlengine/TodoWrefAttr.java b/org/madore/damlengine/TodoWrefAttr.java index 7f31250..60fec1d 100644 --- a/org/madore/damlengine/TodoWrefAttr.java +++ b/org/madore/damlengine/TodoWrefAttr.java @@ -33,8 +33,14 @@ public class TodoWrefAttr extends TodoAttr { String wrefNumberStr = wrefMatcher.group(4); String wrefSupplementStr = wrefMatcher.group(5); String targetFile = ""; - if ( true ) - targetFile = wrefYearStr + "-" + wrefMonthStr + ".html"; + if ( ctx.wsc != null + && ctx.wsc instanceof Context.WeblogMonthSelectionContext + && wrefYearStr.equals(((Context.WeblogMonthSelectionContext)ctx.wsc).year) + && wrefMonthStr.equals(((Context.WeblogMonthSelectionContext)ctx.wsc).month) ) + targetFile = ""; + else + targetFile = ((ctx.gc.uriToTop==null)?"":(ctx.gc.uriToTop+"weblog/")) + + wrefYearStr + "-" + wrefMonthStr + ".html"; String targetFragment = "d." + wrefYearStr + "-" + wrefMonthStr + "-" + wrefDayStr + "." + wrefNumberStr + wrefSupplementStr; String target = targetFile + "#" + targetFragment; -- cgit v1.2.3