summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-10-10 18:41:54 +0200
committerDavid A. Madore <david+git@madore.org>2010-10-10 18:41:54 +0200
commit5a64664941be9c96a4f32602f4ae94a8dc7c2f47 (patch)
treeea4fc58dea5c80b548cbb481b151100bfe3d2309
parentfab2da0e75bc84e0a811c31a8082e4b00769b5e5 (diff)
downloaddamlengine-5a64664941be9c96a4f32602f4ae94a8dc7c2f47.tar.gz
damlengine-5a64664941be9c96a4f32602f4ae94a8dc7c2f47.tar.bz2
damlengine-5a64664941be9c96a4f32602f4ae94a8dc7c2f47.zip
Handle meta-description and meta-keywords.
-rw-r--r--org/madore/damlengine/TodoElement.java2
-rw-r--r--org/madore/damlengine/TodoMetaElement.java53
2 files changed, 55 insertions, 0 deletions
diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java
index c8b2d11..01e5863 100644
--- a/org/madore/damlengine/TodoElement.java
+++ b/org/madore/damlengine/TodoElement.java
@@ -23,6 +23,8 @@ public abstract class TodoElement extends TodoItem {
damlFactories.put("title", new TodoTitleElement.Factory());
damlFactories.put("subtitle", new TodoSubtitleElement.Factory());
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));
}
protected final Element node;
diff --git a/org/madore/damlengine/TodoMetaElement.java b/org/madore/damlengine/TodoMetaElement.java
new file mode 100644
index 0000000..1089bf9
--- /dev/null
+++ b/org/madore/damlengine/TodoMetaElement.java
@@ -0,0 +1,53 @@
+package org.madore.damlengine;
+
+import java.util.ArrayList;
+import java.util.regex.Pattern;
+import org.w3c.dom.*;
+
+public final class TodoMetaElement extends TodoDefaultElement {
+
+ public enum Type {
+ DESCRIPTION("Description"),
+ KEYWORDS("Keywords");
+ final String metaName;
+ Type(String metaName) {
+ this.metaName = metaName;
+ }
+ }
+
+ public static class Factory extends TodoElement.Factory {
+ final Type t;
+ public Factory(Type t) {
+ super();
+ this.t = t;
+ }
+ @Override
+ public TodoMetaElement newItem(Element node,
+ Context ctx,
+ TodoItem caller) {
+ return new TodoMetaElement(t, node, ctx, caller);
+ }
+ }
+
+ final Type t;
+
+ public TodoMetaElement(Type t,
+ Element node,
+ Context ctx,
+ TodoItem caller) {
+ super(node, ctx, caller);
+ this.t = t;
+ }
+
+ @Override
+ public void handleNodeOnly() {
+ Element meta = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "meta");
+ String lang = LangHelper.getLangNorec(node);
+ if ( lang != null )
+ LangHelper.setLangNorec(meta, lang);
+ meta.setAttributeNS(null, "name", t.metaName);
+ meta.setAttributeNS(null, "content", node.getTextContent());
+ node.getParentNode().replaceChild(meta, node);
+ }
+
+}