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"); } }