summaryrefslogtreecommitdiffstats
path: root/org/madore
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-10-10 22:47:29 +0200
committerDavid A. Madore <david+git@madore.org>2010-10-10 22:47:29 +0200
commit3d574c5090212ad271e1878719b4704a0466d2c5 (patch)
treee9d0fe73a35089e2b197ff8d1df82a48401ed21c /org/madore
parent5a64664941be9c96a4f32602f4ae94a8dc7c2f47 (diff)
downloaddamlengine-3d574c5090212ad271e1878719b4704a0466d2c5.tar.gz
damlengine-3d574c5090212ad271e1878719b4704a0466d2c5.tar.bz2
damlengine-3d574c5090212ad271e1878719b4704a0466d2c5.zip
Despammed email tags.
Diffstat (limited to 'org/madore')
-rw-r--r--org/madore/damlengine/TodoElement.java3
-rw-r--r--org/madore/damlengine/TodoEmailAtOrDotElement.java74
-rw-r--r--org/madore/damlengine/TodoEmailDespammedElement.java47
-rw-r--r--org/madore/damlengine/TodoMetaElement.java2
4 files changed, 124 insertions, 2 deletions
diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java
index 01e5863..80565cc 100644
--- a/org/madore/damlengine/TodoElement.java
+++ b/org/madore/damlengine/TodoElement.java
@@ -25,6 +25,9 @@ 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("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));
}
protected final Element node;
diff --git a/org/madore/damlengine/TodoEmailAtOrDotElement.java b/org/madore/damlengine/TodoEmailAtOrDotElement.java
new file mode 100644
index 0000000..8e3eed3
--- /dev/null
+++ b/org/madore/damlengine/TodoEmailAtOrDotElement.java
@@ -0,0 +1,74 @@
+package org.madore.damlengine;
+
+import org.w3c.dom.*;
+
+public final class TodoEmailAtOrDotElement extends TodoDefaultElement {
+
+ public enum Type {
+ AT("commercial-at", "commercial_at.png", "at sign", "arobase"),
+ DOT("full-stop", "full_stop.png", "dot", "point");
+ final String charName;
+ final String imgName;
+ final String enName;
+ final String frName;
+ Type(String charName, String imgName,
+ String enName, String frName) {
+ this.charName = charName;
+ this.imgName = imgName;
+ this.enName = enName;
+ this.frName = frName;
+ }
+ }
+
+ public static class Factory extends TodoElement.Factory {
+ final Type t;
+ public Factory(Type t) {
+ super();
+ this.t = t;
+ }
+ @Override
+ public TodoEmailAtOrDotElement newItem(Element node,
+ Context ctx,
+ TodoItem caller) {
+ return new TodoEmailAtOrDotElement(t, node, ctx, caller);
+ }
+ }
+
+ final Type t;
+
+ public TodoEmailAtOrDotElement(Type t,
+ Element node,
+ Context ctx,
+ TodoItem caller) {
+ super(node, ctx, caller);
+ this.t = t;
+ }
+
+ @Override
+ public void handleNodeOnly() {
+ if ( ! ( caller instanceof TodoEmailDespammedElement ) )
+ throw new IllegalArgumentException(node.getLocalName()+" node can only be child of email-despammed node");
+ Element span0 = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "span");
+ String expLang = LangHelper.getLangNorec(node);
+ String lang = LangHelper.getLangRec(node);
+ if ( lang == null || ! ( lang.equals("en") || lang.equals("fr") ) ) {
+ lang = "en";
+ expLang = "en";
+ }
+ if ( expLang != null )
+ LangHelper.setLangNorec(span0, expLang);
+ span0.setAttributeNS(null, "class", "replace-"+t.charName);
+ node.getParentNode().replaceChild(span0, node);
+ Element span1 = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "span");
+ span1.setAttributeNS(null, "class", "subreplace-"+t.charName);
+ span0.appendChild(span1);
+ Element img = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "img");
+ img.setAttributeNS(null, "src",
+ (ctx.uriToTop==null?"":ctx.uriToTop)+"images/"+t.imgName);
+ img.setAttributeNS(null, "alt", "["+(lang.equals("fr")?t.frName:t.enName)+"]");
+ img.setAttributeNS(null, "height", "15");
+ img.setAttributeNS(null, "width", "16");
+ span1.appendChild(img);
+ }
+
+}
diff --git a/org/madore/damlengine/TodoEmailDespammedElement.java b/org/madore/damlengine/TodoEmailDespammedElement.java
new file mode 100644
index 0000000..9d393ed
--- /dev/null
+++ b/org/madore/damlengine/TodoEmailDespammedElement.java
@@ -0,0 +1,47 @@
+package org.madore.damlengine;
+
+import java.util.ArrayList;
+import org.w3c.dom.*;
+
+public final class TodoEmailDespammedElement extends TodoDefaultElement {
+
+ public static class Factory extends TodoElement.Factory {
+ @Override
+ public TodoEmailDespammedElement newItem(Element node,
+ Context ctx,
+ TodoItem caller) {
+ return new TodoEmailDespammedElement(node, ctx, caller);
+ }
+ }
+
+ public TodoEmailDespammedElement(Element node,
+ Context ctx,
+ TodoItem caller) {
+ super(node, ctx, caller);
+ }
+
+ @Override
+ public void handleNodeOnly() {
+ Element out0 = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "code");
+ String lang = LangHelper.getLangNorec(node);
+ if ( lang != null )
+ LangHelper.setLangNorec(out0, lang);
+ Element out1 = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "a");
+ out0.appendChild(out1);
+ out1.setAttributeNS(null, "class", "despammed-address");
+ ArrayList<Node> childList = getChildList(node);
+ ArrayList<TodoElement> toProcess
+ = new ArrayList<TodoElement>(childList.size()+8);
+ for ( Node child : childList ) {
+ out1.appendChild(child);
+ if ( child.getNodeType() == Node.ELEMENT_NODE ) {
+ TodoElement it
+ = TodoElement.getTodoElement((Element)child, this.ctx, this);
+ toProcess.add(it);
+ }
+ }
+ node.getParentNode().replaceChild(out0, node);
+ this.ownerDeque.registerAtStart(toProcess);
+ }
+
+}
diff --git a/org/madore/damlengine/TodoMetaElement.java b/org/madore/damlengine/TodoMetaElement.java
index 1089bf9..509d560 100644
--- a/org/madore/damlengine/TodoMetaElement.java
+++ b/org/madore/damlengine/TodoMetaElement.java
@@ -1,7 +1,5 @@
package org.madore.damlengine;
-import java.util.ArrayList;
-import java.util.regex.Pattern;
import org.w3c.dom.*;
public final class TodoMetaElement extends TodoDefaultElement {