From 3b1ce20a6d59e3424225421da7aef6fc50b8e047 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Fri, 26 Aug 2011 17:46:14 +0200 Subject: Handle date-extra element. --- org/madore/damlengine/Context.java | 1 + org/madore/damlengine/TodoDateExtraElement.java | 36 +++++++++++++++++++++++++ org/madore/damlengine/TodoElement.java | 1 + org/madore/damlengine/TodoEntryElement.java | 1 + 4 files changed, 39 insertions(+) create mode 100644 org/madore/damlengine/TodoDateExtraElement.java (limited to 'org/madore/damlengine') diff --git a/org/madore/damlengine/Context.java b/org/madore/damlengine/Context.java index f5d12bf..5ae7285 100644 --- a/org/madore/damlengine/Context.java +++ b/org/madore/damlengine/Context.java @@ -33,6 +33,7 @@ public class Context implements Cloneable { public String date; public String number; public String dow; + public Element headerNode; public EntryContext(String year, String month, String day, String number, String dow) { this.year = year; this.month = month; this.day = day; diff --git a/org/madore/damlengine/TodoDateExtraElement.java b/org/madore/damlengine/TodoDateExtraElement.java new file mode 100644 index 0000000..a8dd0b6 --- /dev/null +++ b/org/madore/damlengine/TodoDateExtraElement.java @@ -0,0 +1,36 @@ +package org.madore.damlengine; + +import org.w3c.dom.*; + +public final class TodoDateExtraElement extends TodoDefaultElement { + + public static class Factory extends TodoElement.Factory { + @Override + public TodoDateExtraElement newItem(Element node, + Context ctx, + TodoItem caller) { + return new TodoDateExtraElement(node, ctx, caller); + } + } + + public TodoDateExtraElement(Element node, + Context ctx, + TodoItem caller) { + super(node, ctx, caller); + } + + @Override + public void handleNodeOnly() { + String lang = LangHelper.getLangRec(node); + String explicitLang = LangHelper.getLangNorec(node); + if ( explicitLang != null && explicitLang != lang ) { + System.err.println("warning: lang attribute on date-extra will be ignored"); + explicitLang = null; + } + if ( ctx.ent == null ) + throw new IllegalStateException("entry context not defined in date-extra element"); + ctx.ent.headerNode.appendChild(ctx.doc.createTextNode(" \u00b7 "+node.getTextContent())); + node.getParentNode().removeChild(node); + } + +} diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java index c597430..94867cc 100644 --- a/org/madore/damlengine/TodoElement.java +++ b/org/madore/damlengine/TodoElement.java @@ -42,6 +42,7 @@ public abstract class TodoElement extends TodoItem { damlFactories.put("translation", new TodoTranslationElement.Factory()); damlFactories.put("meta-description", new TodoMetaElement.Factory(TodoMetaElement.Type.DESCRIPTION)); damlFactories.put("meta-keywords", new TodoMetaElement.Factory(TodoMetaElement.Type.KEYWORDS)); + damlFactories.put("date-extra", new TodoDateExtraElement.Factory()); damlFactories.put("email-despammed", new TodoEmailDespammedElement.Factory()); damlFactories.put("email-at", new TodoEmailAtOrDotElement.Factory(TodoEmailAtOrDotElement.Type.AT)); damlFactories.put("email-dot", new TodoEmailAtOrDotElement.Factory(TodoEmailAtOrDotElement.Type.DOT)); diff --git a/org/madore/damlengine/TodoEntryElement.java b/org/madore/damlengine/TodoEntryElement.java index 4853a9a..8b38881 100644 --- a/org/madore/damlengine/TodoEntryElement.java +++ b/org/madore/damlengine/TodoEntryElement.java @@ -73,6 +73,7 @@ public final class TodoEntryElement extends TodoDefaultElement { ctx2.ent = new Context.EntryContext(entryYearStr, entryMonthStr, entryDayStr, entryNumberStr, entryDowStr); + ctx2.ent.headerNode = header; ArrayList childList = getChildList(this.node); ArrayList toProcess = new ArrayList(childList.size()+8); -- cgit v1.2.3