summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2011-11-12 16:05:42 +0100
committerDavid A. Madore <david+git@madore.org>2011-11-12 16:05:42 +0100
commitd01e4c18d9956e1e7d6566de188f44220639d6b6 (patch)
treeaab44be7942c8f528f0af1bfd03b9e6ce965535a
parent07f2f3c30a6e0bc811e436925dfdfcf5befdecb7 (diff)
downloaddamlengine-d01e4c18d9956e1e7d6566de188f44220639d6b6.tar.gz
damlengine-d01e4c18d9956e1e7d6566de188f44220639d6b6.tar.bz2
damlengine-d01e4c18d9956e1e7d6566de188f44220639d6b6.zip
Implement <d:cut-here /> for cutting long entries.
-rw-r--r--org/madore/damlengine/Context.java5
-rw-r--r--org/madore/damlengine/TodoCutHere.java74
-rw-r--r--org/madore/damlengine/TodoElement.java1
-rw-r--r--org/madore/damlengine/TodoEntryElement.java5
4 files changed, 83 insertions, 2 deletions
diff --git a/org/madore/damlengine/Context.java b/org/madore/damlengine/Context.java
index 6674c76..9249fe5 100644
--- a/org/madore/damlengine/Context.java
+++ b/org/madore/damlengine/Context.java
@@ -76,16 +76,19 @@ public class Context implements Cloneable {
public String date;
public String number;
public String dow;
+ public String doSinglePage;
public ArrayList<String> catList;
public Element headerNode;
public Element headlinkNode;
+ public Element mainDivNode;
public EntryContext(String year, String month, String day,
- String number, String dow,
+ String number, String dow, String doSinglePage,
ArrayList<String> catList) {
this.year = year; this.month = month; this.day = day;
this.yandm = year+"-"+month;
this.date = yandm+"-"+day;
this.number = number; this.dow = dow;
+ this.doSinglePage = doSinglePage;
this.catList = catList;
}
}
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;
+ }
+ }
+ }
+
+}
diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java
index 5f4fe3c..0b2baf5 100644
--- a/org/madore/damlengine/TodoElement.java
+++ b/org/madore/damlengine/TodoElement.java
@@ -70,6 +70,7 @@ public abstract class TodoElement extends TodoItem {
damlFactories.put("weblog-selection-cat-name", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.CATEGORY_NAME));
damlFactories.put("weblog-selection-single-number", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.SINGLE_NUMBER));
damlFactories.put("weblog-selection-single-title", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.SINGLE_TITLE));
+ damlFactories.put("cut-here", new TodoCutHere.Factory());
}
protected final static Factory killAFactory
diff --git a/org/madore/damlengine/TodoEntryElement.java b/org/madore/damlengine/TodoEntryElement.java
index 712e121..4b844a9 100644
--- a/org/madore/damlengine/TodoEntryElement.java
+++ b/org/madore/damlengine/TodoEntryElement.java
@@ -112,9 +112,12 @@ public final class TodoEntryElement extends TodoDefaultElement {
Context ctx2 = ctx.clone();
ctx2.ent
= new Context.EntryContext(entryYearStr, entryMonthStr, entryDayStr,
- entryNumberStr, entryDowStr, entryCatList);
+ entryNumberStr, entryDowStr,
+ entryDoSinglePageStr,
+ entryCatList);
ctx2.ent.headerNode = header;
ctx2.ent.headlinkNode = headlink;
+ ctx2.ent.mainDivNode = mainDiv;
ArrayList<Node> childList = getChildList(this.node);
ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>(childList.size()+8);