summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoWXrefAttr.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/TodoWXrefAttr.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/TodoWXrefAttr.java')
-rw-r--r--org/madore/damlengine/TodoWXrefAttr.java55
1 files changed, 55 insertions, 0 deletions
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");
+ }
+
+}