From fc26fdba30e084a2e8a8278d09a1be08a83e0722 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Fri, 26 Aug 2011 17:28:05 +0200 Subject: Handle d:img-a element. --- org/madore/damlengine/TodoElement.java | 1 + org/madore/damlengine/TodoImgAElement.java | 44 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 org/madore/damlengine/TodoImgAElement.java (limited to 'org') diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java index 95a22c4..c597430 100644 --- a/org/madore/damlengine/TodoElement.java +++ b/org/madore/damlengine/TodoElement.java @@ -59,6 +59,7 @@ public abstract class TodoElement extends TodoItem { damlFactories.put("smiley-twisted", new TodoSmileyElement.Factory(TodoSmileyElement.Type.TWISTED)); damlFactories.put("smiley-cry", new TodoSmileyElement.Factory(TodoSmileyElement.Type.CRY)); damlFactories.put("smiley-evil", new TodoSmileyElement.Factory(TodoSmileyElement.Type.EVIL)); + damlFactories.put("img-a", new TodoImgAElement.Factory()); } protected final Element node; diff --git a/org/madore/damlengine/TodoImgAElement.java b/org/madore/damlengine/TodoImgAElement.java new file mode 100644 index 0000000..25a8263 --- /dev/null +++ b/org/madore/damlengine/TodoImgAElement.java @@ -0,0 +1,44 @@ +package org.madore.damlengine; + +import java.util.ArrayList; +import org.w3c.dom.*; + +public final class TodoImgAElement extends TodoDefaultElement { + + public static class Factory extends TodoElement.Factory { + @Override + public TodoImgAElement newItem(Element node, + Context ctx, + TodoItem caller) { + return new TodoImgAElement(node, ctx, caller); + } + } + + public TodoImgAElement(Element node, + Context ctx, + TodoItem caller) { + super(node, ctx, caller); + } + + @Override + public void handleNodeOnly() { + String explicitLang = LangHelper.getLangNorec(node); + Element a = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "a"); + if ( explicitLang != null ) + LangHelper.setLangNorec(node, explicitLang); + node.getParentNode().replaceChild(a, node); + Element img = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "img"); + a.appendChild(img); + ArrayList attrList = getAttrList(this.node); + for ( Attr attr : attrList ) { + if ( attr.getNamespaceURI() == null ) { + String attName = attr.getLocalName(); + if ( attName == "src" ) + a.setAttributeNS(null, "href", attr.getValue()); + node.removeAttributeNode(attr); + img.setAttributeNodeNS(attr); + } + } + } + +} -- cgit v1.2.3