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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
package org.madore.damlengine;
import org.w3c.dom.*;
public final class TodoCutHere extends TodoDefaultElement {
public static class Factory extends TodoElement.Factory {
@Override
public TodoCutHere newItem(Element node,
Context ctx,
TodoItem caller) {
return new TodoCutHere(node, ctx, caller);
}
}
public TodoCutHere(Element node,
Context ctx,
TodoItem caller) {
super(node, ctx, caller);
}
@Override
public void handleNodeOnly() {
if ( ctx.ent == null )
throw new IllegalStateException("entry context not defined in cut-here element");
if ( ctx.ent.doSinglePage == null )
throw new IllegalStateException("cut-here element found in non single-page entry");
String lang = LangHelper.getLangRec(node);
String explicitLang = LangHelper.getLangNorec(node);
if ( ctx.wsc == null
|| ctx.wsc instanceof Context.WeblogSingleSelectionContext ) {
Element div = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "div");
div.setAttributeNS(null, "id",
"d." + ctx.ent.date + "." + ctx.ent.number
+ ".CUT");
div.setAttributeNS(null, "class", "cut-anchor");
div.appendChild(ctx.doc.createComment(" EMPTY "));
node.getParentNode().replaceChild(div, node);
} else {
Element p = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "p");
Element a = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "a");
p.appendChild(a);
a.setAttributeNS(null, "href",
((ctx.gc.uriToTop==null)?"":(ctx.gc.uriToTop+"weblog/"))
+ ctx.ent.date + "-" + ctx.ent.doSinglePage + ".html"
+ "#d." + ctx.ent.date + "." + ctx.ent.number
+ ".CUT");
if ( explicitLang != null )
LangHelper.setLangNorec(p, explicitLang);
p.setAttributeNS(null, "class", "cut-link");
if ( lang.equals("en") )
a.appendChild(ctx.doc.createTextNode("[Continue reading\u2026]"));
else if ( lang.equals("fr") )
a.appendChild(ctx.doc.createTextNode("[Lire la suite\u2026]"));
else if ( lang.equals("de") )
a.appendChild(ctx.doc.createTextNode("[Weiter lesen\u2026]"));
else if ( lang.equals("ia") )
a.appendChild(ctx.doc.createTextNode("[Leger ultra\u2026]"));
else
a.appendChild(ctx.doc.createTextNode("[\u2026]"));
node.getParentNode().replaceChild(p, node);
Node killPoint = p;
while ( ! killPoint.isSameNode(ctx.ent.mainDivNode) ) {
Node parent = killPoint.getParentNode();
while ( killPoint.getNextSibling() != null )
parent.removeChild(killPoint.getNextSibling());
// FIXME: deleted node may already have found its way
// in the todo deque, which means it could cause a
// null pointer exception by trying to access its
// parent node. Do something about this!
killPoint = parent;
}
}
}
}
|