summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoWXrefAttr.java
blob: dbc5511003768d4df14d40f6ab4750e6a843ae59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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");
    }

}