diff options
Diffstat (limited to 'org/madore/damlengine/TodoExtraStyleOrScriptElement.java')
-rw-r--r-- | org/madore/damlengine/TodoExtraStyleOrScriptElement.java | 47 |
1 files changed, 47 insertions, 0 deletions
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); + } + +} |