summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2011-09-08 15:53:31 +0200
committerDavid A. Madore <david+git@madore.org>2011-09-08 15:53:31 +0200
commitc1aa7509008d3aaa4afa9ceb3c3e029b9542f75a (patch)
tree6356f72d817b91c92ad2fd6ad99ff7ce2c9fa21c
parent85ce46d8677b5bdb85394ccb49964913343a41c9 (diff)
downloaddamlengine-c1aa7509008d3aaa4afa9ceb3c3e029b9542f75a.tar.gz
damlengine-c1aa7509008d3aaa4afa9ceb3c3e029b9542f75a.tar.bz2
damlengine-c1aa7509008d3aaa4afa9ceb3c3e029b9542f75a.zip
Improve title of weblog pages.
-rw-r--r--org/madore/damlengine/TodoElement.java1
-rw-r--r--org/madore/damlengine/TodoTitleElement.java55
-rw-r--r--org/madore/damlengine/TodoWeblogSelectionElement.java24
-rw-r--r--org/madore/damlengine/weblog-cat-template.daml2
-rw-r--r--org/madore/damlengine/weblog-index-template.daml2
-rw-r--r--org/madore/damlengine/weblog-month-template.daml2
6 files changed, 70 insertions, 16 deletions
diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java
index ee1a90f..12810c0 100644
--- a/org/madore/damlengine/TodoElement.java
+++ b/org/madore/damlengine/TodoElement.java
@@ -67,6 +67,7 @@ public abstract class TodoElement extends TodoItem {
damlFactories.put("weblog-selection-month-year", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.MONTH_YEAR));
damlFactories.put("weblog-selection-month-month", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.MONTH_MONTH));
damlFactories.put("weblog-selection-cat-code", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.CATEGORY_CODE));
+ damlFactories.put("weblog-selection-cat-name", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.CATEGORY_NAME));
}
protected final static Factory killAFactory
diff --git a/org/madore/damlengine/TodoTitleElement.java b/org/madore/damlengine/TodoTitleElement.java
index 877e719..9854f1a 100644
--- a/org/madore/damlengine/TodoTitleElement.java
+++ b/org/madore/damlengine/TodoTitleElement.java
@@ -20,23 +20,52 @@ public final class TodoTitleElement extends TodoDefaultElement {
super(node, ctx, caller);
}
+ public class TodoAgain extends TodoItem {
+ /* Make this a member class (i.e., not "static") so we can
+ * access the "node" field of the container class. Another
+ * option would have been to create a new subclass of
+ * TodoElement and initialize it on the same node: which is
+ * better? */
+ public TodoAgain(Context ctx, TodoItem caller) {
+ super(ctx, caller);
+ }
+ @Override
+ public void handle() {
+ assert(this.ctx == TodoTitleElement.this.ctx);
+ assert(this.caller == TodoTitleElement.this);
+ if ( ctx.gc.title != null )
+ throw new IllegalArgumentException("attempting to redefine title");
+ ctx.gc.title = ctx.doc.createDocumentFragment();
+ ctx.gc.titleStr = node.getTextContent();
+ ctx.gc.titleLang = LangHelper.getLangRec(node);
+ String lang = LangHelper.getLangNorec(node);
+ ArrayList<Node> childList = getChildList(node);
+ for ( Node child : childList ) {
+ ctx.gc.title.appendChild(child);
+ }
+ Element tit = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "title");
+ if ( lang != null )
+ LangHelper.setLangNorec(tit, lang);
+ node.getParentNode().replaceChild(tit, node);
+ tit.appendChild(ctx.doc.createTextNode(ctx.gc.titleStr));
+ }
+ }
+
@Override
public void handleNodeOnly() {
- if ( ctx.gc.title != null )
- throw new IllegalArgumentException("attempting to redefine title");
- ctx.gc.title = ctx.doc.createDocumentFragment();
- ctx.gc.titleStr = node.getTextContent();
- ctx.gc.titleLang = LangHelper.getLangRec(node);
- String lang = LangHelper.getLangNorec(node);
- ArrayList<Node> childList = getChildList(node);
+ // First process the children, then come back to processing
+ // title, so we can extract the text content after replacement.
+ ArrayList<Node> childList = getChildList(this.node);
+ ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>(childList.size());
for ( Node child : childList ) {
- ctx.gc.title.appendChild(child);
+ if ( child.getNodeType() == Node.ELEMENT_NODE ) {
+ TodoElement it
+ = TodoElement.getTodoElement((Element)child, this.ctx, this);
+ toProcess.add(it);
+ }
}
- Element tit = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "title");
- if ( lang != null )
- LangHelper.setLangNorec(tit, lang);
- node.getParentNode().replaceChild(tit, node);
- tit.appendChild(ctx.doc.createTextNode(ctx.gc.titleStr));
+ this.ownerDeque.registerAtStart(new TodoAgain(ctx, this));
+ this.ownerDeque.registerAtStart(toProcess);
}
}
diff --git a/org/madore/damlengine/TodoWeblogSelectionElement.java b/org/madore/damlengine/TodoWeblogSelectionElement.java
index 23c88ec..e33f2c0 100644
--- a/org/madore/damlengine/TodoWeblogSelectionElement.java
+++ b/org/madore/damlengine/TodoWeblogSelectionElement.java
@@ -1,5 +1,7 @@
package org.madore.damlengine;
+import java.util.Map;
+import java.util.HashMap;
import org.w3c.dom.*;
public final class TodoWeblogSelectionElement extends TodoDefaultElement {
@@ -8,6 +10,7 @@ public final class TodoWeblogSelectionElement extends TodoDefaultElement {
RECENT_COUNT,
MONTH_YEAR,
MONTH_MONTH,
+ CATEGORY_NAME,
CATEGORY_CODE;
}
@@ -35,6 +38,22 @@ public final class TodoWeblogSelectionElement extends TodoDefaultElement {
this.t = t;
}
+ protected final static Map<String,Map<String,String>> categoryNames;
+
+ static {
+ categoryNames = new HashMap<String,Map<String,String>>();
+ categoryNames.put("en", new HashMap<String,String>());
+ categoryNames.put("fr", new HashMap<String,String>());
+ categoryNames.get("en").put("glf", "Gratuitous Literary Fragments");
+ categoryNames.get("fr").put("glf", "Fragments lit\u00e9raires gratuits");
+ }
+
+ public String categoryName(String code, String lang) {
+ if ( categoryNames.get(lang) == null )
+ return code;
+ return categoryNames.get(lang).get(code);
+ }
+
@Override
public void handleNodeOnly() {
if ( ctx.wsc == null )
@@ -62,6 +81,11 @@ public final class TodoWeblogSelectionElement extends TodoDefaultElement {
throw new IllegalStateException("weblog-selection-recent-count element encountered while not in weblog category selection state");
str = ((Context.WeblogCategorySelectionContext)(ctx.wsc)).code;
break;
+ case CATEGORY_NAME:
+ if ( ! ( ctx.wsc instanceof Context.WeblogCategorySelectionContext ) )
+ throw new IllegalStateException("weblog-selection-recent-count element encountered while not in weblog category selection state");
+ str = categoryName(((Context.WeblogCategorySelectionContext)(ctx.wsc)).code, LangHelper.getLangRec(node));
+ break;
default:
throw new AssertionError("unknown type");
}
diff --git a/org/madore/damlengine/weblog-cat-template.daml b/org/madore/damlengine/weblog-cat-template.daml
index 01a56a0..7219ea3 100644
--- a/org/madore/damlengine/weblog-cat-template.daml
+++ b/org/madore/damlengine/weblog-cat-template.daml
@@ -14,7 +14,7 @@
<d:daml xml:lang="&file.language;" uri-to-top="&uri-to-top;" xmlns="http://www.w3.org/1999/xhtml" xmlns:d="http://www.madore.org/~david/NS/daml/">
-<d:title>David Madore's WebLog</d:title>
+<d:title>David Madore's WebLog: <d:weblog-selection-cat-name /></d:title>
<d:meta-description>David Alexander Madore's WebLog / Diary</d:meta-description>
diff --git a/org/madore/damlengine/weblog-index-template.daml b/org/madore/damlengine/weblog-index-template.daml
index f032b7b..3cd1277 100644
--- a/org/madore/damlengine/weblog-index-template.daml
+++ b/org/madore/damlengine/weblog-index-template.daml
@@ -14,7 +14,7 @@
<d:daml xml:lang="&file.language;" uri-to-top="&uri-to-top;" xmlns="http://www.w3.org/1999/xhtml" xmlns:d="http://www.madore.org/~david/NS/daml/">
-<d:title>David Madore's WebLog</d:title>
+<d:title>David Madore's WebLog: index</d:title>
<d:meta-description>David Alexander Madore's WebLog / Diary</d:meta-description>
diff --git a/org/madore/damlengine/weblog-month-template.daml b/org/madore/damlengine/weblog-month-template.daml
index 69a28b4..913f756 100644
--- a/org/madore/damlengine/weblog-month-template.daml
+++ b/org/madore/damlengine/weblog-month-template.daml
@@ -14,7 +14,7 @@
<d:daml xml:lang="&file.language;" uri-to-top="&uri-to-top;" xmlns="http://www.w3.org/1999/xhtml" xmlns:d="http://www.madore.org/~david/NS/daml/">
-<d:title>David Madore's WebLog</d:title>
+<d:title>David Madore's WebLog: <d:weblog-selection-month-year />-<d:weblog-selection-month-month /></d:title>
<d:meta-description>David Alexander Madore's WebLog / Diary</d:meta-description>