From 9265dd830db07fe53cad3cdb407ca16d21483e92 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sat, 30 Apr 2011 23:17:00 +0200 Subject: Handle and elements. --- org/madore/damlengine/TodoElement.java | 2 + .../damlengine/TodoExtraStyleOrScriptElement.java | 47 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 org/madore/damlengine/TodoExtraStyleOrScriptElement.java diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java index a5784bb..60b80c2 100644 --- a/org/madore/damlengine/TodoElement.java +++ b/org/madore/damlengine/TodoElement.java @@ -41,6 +41,8 @@ public abstract class TodoElement extends TodoItem { 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)); + damlFactories.put("extra-style", new TodoExtraStyleOrScriptElement.Factory(TodoStyleOrScript.Type.STYLE)); + damlFactories.put("extra-script", new TodoExtraStyleOrScriptElement.Factory(TodoStyleOrScript.Type.SCRIPT)); } protected final Element node; diff --git a/org/madore/damlengine/TodoExtraStyleOrScriptElement.java b/org/madore/damlengine/TodoExtraStyleOrScriptElement.java new file mode 100644 index 0000000..a475863 --- /dev/null +++ b/org/madore/damlengine/TodoExtraStyleOrScriptElement.java @@ -0,0 +1,47 @@ +package org.madore.damlengine; + +import java.util.regex.Pattern; +import org.w3c.dom.*; + +public final class TodoExtraStyleOrScriptElement extends TodoDefaultElement { + + public static class Factory extends TodoElement.Factory { + final TodoStyleOrScript.Type t; + public Factory(TodoStyleOrScript.Type t) { + super(); + this.t = t; + } + @Override + public TodoExtraStyleOrScriptElement newItem(Element node, + Context ctx, + TodoItem caller) { + return new TodoExtraStyleOrScriptElement(t, node, ctx, caller); + } + } + + final TodoStyleOrScript.Type t; + + public TodoExtraStyleOrScriptElement(TodoStyleOrScript.Type t, + Element node, + Context ctx, + TodoItem caller) { + super(node, ctx, caller); + this.t = t; + } + + @Override + public void handleNodeOnly() { + String content = node.getTextContent(); + if ( t == TodoStyleOrScript.Type.SCRIPT ) + ctx.scriptContent.append(content); + else + ctx.styleContent.append(content); + Node ws = node.getNextSibling(); + if ( ( ws.getNodeType() == Node.TEXT_NODE + || ws.getNodeType() == Node.CDATA_SECTION_NODE ) + && Pattern.matches("^\\s*$",((CharacterData)ws).getData()) ) + node.getParentNode().removeChild(ws); + node.getParentNode().removeChild(node); + } + +} -- cgit v1.2.3