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. --- org/madore/damlengine/Context.java | 4 +- org/madore/damlengine/TodoAttr.java | 1 + org/madore/damlengine/TodoElement.java | 4 ++ org/madore/damlengine/TodoWXrefAttr.java | 55 +++++++++++++++++ .../damlengine/TodoWeblogSelectionElement.java | 72 ++++++++++++++++++++++ org/madore/damlengine/WeblogSelect.java | 4 +- org/madore/damlengine/weblog-cat-template.daml | 4 ++ org/madore/damlengine/weblog-month-template.daml | 12 ++++ org/madore/damlengine/weblog-recent-template.daml | 9 +++ 9 files changed, 161 insertions(+), 4 deletions(-) create mode 100644 org/madore/damlengine/TodoWXrefAttr.java create mode 100644 org/madore/damlengine/TodoWeblogSelectionElement.java (limited to 'org/madore') diff --git a/org/madore/damlengine/Context.java b/org/madore/damlengine/Context.java index 6b627a4..15ce76a 100644 --- a/org/madore/damlengine/Context.java +++ b/org/madore/damlengine/Context.java @@ -1,7 +1,7 @@ package org.madore.damlengine; import java.util.ArrayList; -import java.util.Set; +import java.util.TreeSet; import org.w3c.dom.*; public class Context implements Cloneable { @@ -28,7 +28,7 @@ public class Context implements Cloneable { public GeneralContext gc; public static abstract class WeblogSelectionContext { - public Set sel; + public TreeSet sel; public ArrayList xmlData; } diff --git a/org/madore/damlengine/TodoAttr.java b/org/madore/damlengine/TodoAttr.java index 8e672d0..474183b 100644 --- a/org/madore/damlengine/TodoAttr.java +++ b/org/madore/damlengine/TodoAttr.java @@ -19,6 +19,7 @@ public abstract class TodoAttr extends TodoItem { damlAttrFactories = new HashMap(); damlAttrFactories.put("xempty", new TodoXemptyAttr.Factory()); damlAttrFactories.put("wref", new TodoWrefAttr.Factory()); + damlAttrFactories.put("wxref", new TodoWXrefAttr.Factory()); } protected final static Factory xmlnsAttrFactory diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java index 5c90366..7df38c9 100644 --- a/org/madore/damlengine/TodoElement.java +++ b/org/madore/damlengine/TodoElement.java @@ -63,6 +63,10 @@ public abstract class TodoElement extends TodoItem { damlFactories.put("img-a", new TodoImgAElement.Factory()); damlFactories.put("weblog-select", new TodoWeblogSelectElement.Factory()); damlFactories.put("weblog-index-select", new TodoWeblogIndexSelectElement.Factory()); + damlFactories.put("weblog-selection-recent-count", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.RECENT_COUNT)); + damlFactories.put("weblog-selection-month-year", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.MONTH_YEAR)); + damlFactories.put("weblog-selection-month-month", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.MONTH_MONTH)); + damlFactories.put("weblog-selection-cat-code", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.CATEGORY_CODE)); } protected final static Factory killAFactory diff --git a/org/madore/damlengine/TodoWXrefAttr.java b/org/madore/damlengine/TodoWXrefAttr.java new file mode 100644 index 0000000..dbc5511 --- /dev/null +++ b/org/madore/damlengine/TodoWXrefAttr.java @@ -0,0 +1,55 @@ +package org.madore.damlengine; + +import org.w3c.dom.*; + +public class TodoWXrefAttr extends TodoAttr { + + public static class Factory extends TodoAttr.Factory { + @Override + public TodoWXrefAttr newItem(Attr attr, Element owner, + Context ctx, + TodoItem caller) { + return new TodoWXrefAttr(attr, owner, ctx, caller); + } + } + + public TodoWXrefAttr(Attr attr, Element owner, + Context ctx, + TodoItem caller) { + super(attr, owner, ctx, caller); + } + + @Override + public void handle() { + String wxrefStr = attr.getValue(); + if ( wxrefStr.equals("##weblog-selection-older") ) { + if ( ctx.wsc == null ) + throw new IllegalStateException("wxref attribute encountered with no weblog selection state"); + int prev = ctx.wsc.sel.first() - 1; + WeblogSummary sum = WeblogSummary.getSummary(); + if ( sum != null && sum.entries != null + && sum.entries.containsKey(new Integer(prev)) ) { + WeblogSummary.EntrySummary ent + = sum.entries.get(new Integer(prev)); + String target = "#d." + ent.date + "." + + String.format("%04d", ent.id); + this.owner.removeAttributeNode(this.attr); + Attr newAttr + = ctx.doc.createAttributeNS(DamlEngine.DAML_NS, "d:wref"); + newAttr.setValue(target); + this.owner.setAttributeNodeNS(newAttr); + this.ownerDeque.registerAtStart(new TodoWrefAttr(newAttr, this.owner, + this.ctx, this)); + } else { + String target = ((ctx.gc.uriToTop==null)?"":(ctx.gc.uriToTop+"weblog/")) + + "weblog-index.html"; + this.owner.removeAttributeNode(this.attr); + Attr newAttr = ctx.doc.createAttributeNS(null, "href"); + newAttr.setValue(target); + this.owner.setAttributeNodeNS(newAttr); + } + } else + throw new IllegalArgumentException("couldn't understand argument to wxref attribute"); + } + +} 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); + } + +} diff --git a/org/madore/damlengine/WeblogSelect.java b/org/madore/damlengine/WeblogSelect.java index 1593d72..9e1c6a2 100644 --- a/org/madore/damlengine/WeblogSelect.java +++ b/org/madore/damlengine/WeblogSelect.java @@ -1,6 +1,6 @@ package org.madore.damlengine; -import java.util.HashSet; +import java.util.TreeSet; import java.util.ArrayList; import java.io.OutputStream; import java.sql.Connection; @@ -37,7 +37,7 @@ public final class WeblogSelect { throw new IllegalArgumentException("don't know how to perform this selection"); final ResultSet selRes = selSt.executeQuery(); - wsc.sel = new HashSet(); + wsc.sel = new TreeSet(); wsc.xmlData = new ArrayList(); while ( selRes.next() ) { int id = selRes.getInt(1); diff --git a/org/madore/damlengine/weblog-cat-template.daml b/org/madore/damlengine/weblog-cat-template.daml index 261686f..904ef63 100644 --- a/org/madore/damlengine/weblog-cat-template.daml +++ b/org/madore/damlengine/weblog-cat-template.daml @@ -53,6 +53,10 @@ href="http://www.madore.org/cgi-bin/comment.pl/lscomments">Recent comments — Commentaires récents

+

Entries with category +/ Entrées de la +catégorie :

+ diff --git a/org/madore/damlengine/weblog-month-template.daml b/org/madore/damlengine/weblog-month-template.daml index f0cf0b3..f077ae7 100644 --- a/org/madore/damlengine/weblog-month-template.daml +++ b/org/madore/damlengine/weblog-month-template.daml @@ -53,8 +53,20 @@ href="http://www.madore.org/cgi-bin/comment.pl/lscomments">Recent comments — Commentaires récents

+

Entries of month +- +/ Entrées du mois +-:

+ +

Continue to older +entries. +/ Continuer +à lire les entrées plus anciennes.

+ +
+

Entries by month / Entrées par mois:

diff --git a/org/madore/damlengine/weblog-recent-template.daml b/org/madore/damlengine/weblog-recent-template.daml index 261686f..add02e3 100644 --- a/org/madore/damlengine/weblog-recent-template.daml +++ b/org/madore/damlengine/weblog-recent-template.daml @@ -55,6 +55,15 @@ récents

+

Only the most recent entries +were included above. Continue +to older entries.

+ +

Seules les plus +récentes entrées ont été incluses +ici. Continuer à lire les +entrées plus anciennes.

+ -- cgit v1.2.3