summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoWeblogSelectionElement.java
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2011-09-02 17:30:26 +0200
committerDavid A. Madore <david+git@madore.org>2011-09-02 17:30:26 +0200
commit0d02ad0c80c59dbd080d3653f88f7348523a3e7d (patch)
treec01dae7e2496e3bb2a560717753ab1e5ead91dd1 /org/madore/damlengine/TodoWeblogSelectionElement.java
parent729c9ccfb3da245b79d52f5ec2dc9f248537595a (diff)
downloaddamlengine-0d02ad0c80c59dbd080d3653f88f7348523a3e7d.tar.gz
damlengine-0d02ad0c80c59dbd080d3653f88f7348523a3e7d.tar.bz2
damlengine-0d02ad0c80c59dbd080d3653f88f7348523a3e7d.zip
Various trickeries to clarify weblog selection and inter-page links.
Diffstat (limited to 'org/madore/damlengine/TodoWeblogSelectionElement.java')
-rw-r--r--org/madore/damlengine/TodoWeblogSelectionElement.java72
1 files changed, 72 insertions, 0 deletions
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);
+ }
+
+}