From a285090037efb50f19fb3800bf2a015fd53d94c9 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sat, 11 Oct 2014 00:44:10 +0200 Subject: Make it possible to link to previous and next entries from the single page template. --- org/madore/damlengine/TodoWXrefAttr.java | 16 ++++++++++------ org/madore/damlengine/WeblogServlet.java | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'org/madore/damlengine') diff --git a/org/madore/damlengine/TodoWXrefAttr.java b/org/madore/damlengine/TodoWXrefAttr.java index bb1c861..e35d06f 100644 --- a/org/madore/damlengine/TodoWXrefAttr.java +++ b/org/madore/damlengine/TodoWXrefAttr.java @@ -22,15 +22,17 @@ public class TodoWXrefAttr extends TodoAttr { @Override public void handle() { String wxrefStr = attr.getValue(); - if ( wxrefStr.equals("##weblog-selection-older") ) { + if ( wxrefStr.equals("##weblog-selection-older") + || wxrefStr.equals("##weblog-selection-newer") ) { if ( ctx.wsc == null ) throw new IllegalStateException("wxref attribute encountered with no weblog selection state"); - int prev = ctx.wsc.sel.first() - 1; + final int trgt = ctx.wsc.sel.first() + + (wxrefStr.equals("##weblog-selection-older") ? -1 : 1); WeblogSummary sum = WeblogSummary.getSummary(ctx.dc); if ( sum != null && sum.entries != null - && sum.entries.containsKey(new Integer(prev)) ) { + && sum.entries.containsKey(new Integer(trgt)) ) { WeblogSummary.EntrySummary ent - = sum.entries.get(new Integer(prev)); + = sum.entries.get(new Integer(trgt)); String target = "#d." + ent.date + "." + String.format("%04d", ent.id); this.owner.removeAttributeNode(this.attr); @@ -38,8 +40,10 @@ public class TodoWXrefAttr extends TodoAttr { = ctx.doc.createAttributeNS(DamlEngine.DAML_NS, "d:wref"); newAttr.setValue(target); this.owner.setAttributeNodeNS(newAttr); - // Force linking to the month page. - this.owner.setAttributeNS(DamlEngine.DAML_NS, "d:wrefcat", "@month"); + if ( ! this.owner.hasAttributeNS(DamlEngine.DAML_NS, "d:wrefcat") ) { + if ( ctx.wsc instanceof Context.WeblogMonthSelectionContext ) + this.owner.setAttributeNS(DamlEngine.DAML_NS, "d:wrefcat", "@month"); + } this.ownerDeque.registerAtStart(new TodoWrefAttr(newAttr, this.owner, this.ctx, this)); } else { diff --git a/org/madore/damlengine/WeblogServlet.java b/org/madore/damlengine/WeblogServlet.java index 444d1ed..39660e5 100644 --- a/org/madore/damlengine/WeblogServlet.java +++ b/org/madore/damlengine/WeblogServlet.java @@ -34,7 +34,7 @@ import javax.servlet.http.HttpServletResponse; public class WeblogServlet extends HttpServlet { - private static final long serialVersionUID = 2014101004L; + private static final long serialVersionUID = 2014101005L; @Override public void init(ServletConfig cfg) -- cgit v1.2.3