summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoCutHere.java
diff options
context:
space:
mode:
Diffstat (limited to 'org/madore/damlengine/TodoCutHere.java')
-rw-r--r--org/madore/damlengine/TodoCutHere.java74
1 files changed, 74 insertions, 0 deletions
diff --git a/org/madore/damlengine/TodoCutHere.java b/org/madore/damlengine/TodoCutHere.java
new file mode 100644
index 0000000..a28eb9f
--- /dev/null
+++ b/org/madore/damlengine/TodoCutHere.java
@@ -0,0 +1,74 @@
+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 a = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "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(a, explicitLang);
+ a.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(a, node);
+ Node killPoint = a;
+ 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;
+ }
+ }
+ }
+
+}