summaryrefslogtreecommitdiffstats
path: root/org
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
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')
-rw-r--r--org/madore/damlengine/Context.java4
-rw-r--r--org/madore/damlengine/TodoAttr.java1
-rw-r--r--org/madore/damlengine/TodoElement.java4
-rw-r--r--org/madore/damlengine/TodoWXrefAttr.java55
-rw-r--r--org/madore/damlengine/TodoWeblogSelectionElement.java72
-rw-r--r--org/madore/damlengine/WeblogSelect.java4
-rw-r--r--org/madore/damlengine/weblog-cat-template.daml4
-rw-r--r--org/madore/damlengine/weblog-month-template.daml12
-rw-r--r--org/madore/damlengine/weblog-recent-template.daml9
9 files changed, 161 insertions, 4 deletions
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<Integer> sel;
+ public TreeSet<Integer> sel;
public ArrayList<String> 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<String,Factory>();
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<Integer>();
+ wsc.sel = new TreeSet<Integer>();
wsc.xmlData = new ArrayList<String>();
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 &mdash; <span xml:lang="fr">Commentaires
récents</span></a></p>
+<p>Entries with category <q><d:weblog-selection-cat-code /></q>
+/ <span xml:lang="fr">Entrées de la
+catégorie <q><d:weblog-selection-cat-code /></q></span>:</p>
+
<d:weblog-select />
</d:body>
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 &mdash; <span xml:lang="fr">Commentaires
récents</span></a></p>
+<p>Entries of month
+<d:weblog-selection-month-year />-<d:weblog-selection-month-month />
+/ <span xml:lang="fr">Entrées du mois
+<d:weblog-selection-month-year />-<d:weblog-selection-month-month /></span>:</p>
+
<d:weblog-select />
+<p><a d:wxref="##weblog-selection-older">Continue to older
+entries.</a>
+/ <span xml:lang="fr"><a d:wxref="##weblog-selection-older">Continuer
+à lire les entrées plus anciennes.</a></span></p>
+
+<hr />
+
<p>Entries by month / <span xml:lang="fr">Entrées par mois</span>:</p>
<table border="1">
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</span></a></p>
<d:weblog-select />
+<p>Only the <d:weblog-selection-recent-count /> most recent entries
+were included above. <a d:wxref="##weblog-selection-older">Continue
+to older entries.</a></p>
+
+<p xml:lang="fr">Seules les <d:weblog-selection-recent-count /> plus
+récentes entrées ont été incluses
+ici. <a d:wxref="##weblog-selection-older">Continuer à lire les
+entrées plus anciennes.</a></p>
+
</d:body>
</d:daml>