From 0d02ad0c80c59dbd080d3653f88f7348523a3e7d Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Fri, 2 Sep 2011 17:30:26 +0200 Subject: Various trickeries to clarify weblog selection and inter-page links. --- .../damlengine/TodoWeblogSelectionElement.java | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 org/madore/damlengine/TodoWeblogSelectionElement.java (limited to 'org/madore/damlengine/TodoWeblogSelectionElement.java') diff --git a/org/madore/damlengine/TodoWeblogSelectionElement.java b/org/madore/damlengine/TodoWeblogSelectionElement.java new file mode 100644 index 0000000..23c88ec --- /dev/null +++ b/org/madore/damlengine/TodoWeblogSelectionElement.java @@ -0,0 +1,72 @@ +package org.madore.damlengine; + +import org.w3c.dom.*; + +public final class TodoWeblogSelectionElement extends TodoDefaultElement { + + public enum Type { + RECENT_COUNT, + MONTH_YEAR, + MONTH_MONTH, + CATEGORY_CODE; + } + + public static class Factory extends TodoElement.Factory { + final Type t; + public Factory(Type t) { + super(); + this.t = t; + } + @Override + public TodoWeblogSelectionElement newItem(Element node, + Context ctx, + TodoItem caller) { + return new TodoWeblogSelectionElement(t, node, ctx, caller); + } + } + + final Type t; + + public TodoWeblogSelectionElement(Type t, + Element node, + Context ctx, + TodoItem caller) { + super(node, ctx, caller); + this.t = t; + } + + @Override + public void handleNodeOnly() { + if ( ctx.wsc == null ) + throw new IllegalStateException("weblog-selection element encountered with no weblog selection state"); + // String lang = LangHelper.getLangRec(node); + String str; + switch ( t ) { + case RECENT_COUNT: + if ( ! ( ctx.wsc instanceof Context.WeblogRecentSelectionContext ) ) + throw new IllegalStateException("weblog-selection-recent-count element encountered while not in weblog recent selection state"); + str = String.format("%d", ((Context.WeblogRecentSelectionContext)(ctx.wsc)).count ); + break; + case MONTH_YEAR: + if ( ! ( ctx.wsc instanceof Context.WeblogMonthSelectionContext ) ) + throw new IllegalStateException("weblog-selection-recent-count element encountered while not in weblog month selection state"); + str = ((Context.WeblogMonthSelectionContext)(ctx.wsc)).year; + break; + case MONTH_MONTH: + if ( ! ( ctx.wsc instanceof Context.WeblogMonthSelectionContext ) ) + throw new IllegalStateException("weblog-selection-recent-count element encountered while not in weblog month selection state"); + str = ((Context.WeblogMonthSelectionContext)(ctx.wsc)).month; + break; + case CATEGORY_CODE: + if ( ! ( ctx.wsc instanceof Context.WeblogCategorySelectionContext ) ) + throw new IllegalStateException("weblog-selection-recent-count element encountered while not in weblog category selection state"); + str = ((Context.WeblogCategorySelectionContext)(ctx.wsc)).code; + break; + default: + throw new AssertionError("unknown type"); + } + Node txt = ctx.doc.createTextNode(str); + node.getParentNode().replaceChild(txt, node); + } + +} -- cgit v1.2.3