summaryrefslogtreecommitdiffstats
path: root/org
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2011-08-28 20:18:55 +0200
committerDavid A. Madore <david+git@madore.org>2011-08-28 20:18:55 +0200
commita0a7d6212299a1723cf6c0666f9838136934cc07 (patch)
treed01317d4fa1a2335365927d2ffe9fb3216be4657 /org
parent3b1023c45a919f25ef38c080f2ac2c0dc5d5e7ca (diff)
downloaddamlengine-a0a7d6212299a1723cf6c0666f9838136934cc07.tar.gz
damlengine-a0a7d6212299a1723cf6c0666f9838136934cc07.tar.bz2
damlengine-a0a7d6212299a1723cf6c0666f9838136934cc07.zip
Avoid pollution by redundant xmlns attributes.
Diffstat (limited to 'org')
-rw-r--r--org/madore/damlengine/DamlEngine.java1
-rw-r--r--org/madore/damlengine/TodoAttr.java6
-rw-r--r--org/madore/damlengine/TodoWrefAttr.java2
-rw-r--r--org/madore/damlengine/TodoXemptyAttr.java2
-rw-r--r--org/madore/damlengine/TodoXmlnsAttr.java28
5 files changed, 37 insertions, 2 deletions
diff --git a/org/madore/damlengine/DamlEngine.java b/org/madore/damlengine/DamlEngine.java
index da49aeb..6581f37 100644
--- a/org/madore/damlengine/DamlEngine.java
+++ b/org/madore/damlengine/DamlEngine.java
@@ -13,6 +13,7 @@ import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;
public final class DamlEngine {
+ public static final String XMLNS_NS = XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
public static final String XML_NS = XMLConstants.XML_NS_URI;
public static final String XHTML_NS = "http://www.w3.org/1999/xhtml";
public static final String DAML_NS = "http://www.madore.org/~david/NS/daml/";
diff --git a/org/madore/damlengine/TodoAttr.java b/org/madore/damlengine/TodoAttr.java
index b88dc53..8e672d0 100644
--- a/org/madore/damlengine/TodoAttr.java
+++ b/org/madore/damlengine/TodoAttr.java
@@ -21,6 +21,9 @@ public abstract class TodoAttr extends TodoItem {
damlAttrFactories.put("wref", new TodoWrefAttr.Factory());
}
+ protected final static Factory xmlnsAttrFactory
+ = new TodoXmlnsAttr.Factory();
+
protected final Attr attr;
protected final Element owner;
@@ -38,6 +41,9 @@ public abstract class TodoAttr extends TodoItem {
String nsuri = attr.getNamespaceURI();
if ( nsuri != null && nsuri.equals(DamlEngine.DAML_NS) )
factory = damlAttrFactories.get(attr.getLocalName());
+ else if ( nsuri != null && nsuri.equals(DamlEngine.XMLNS_NS) )
+ // Note to self: even the plain "xmlns" attribute has this namespace
+ factory = xmlnsAttrFactory;
if ( factory == null )
return null;
return factory.newItem(attr, owner, ctx, caller);
diff --git a/org/madore/damlengine/TodoWrefAttr.java b/org/madore/damlengine/TodoWrefAttr.java
index df30d99..d9b8950 100644
--- a/org/madore/damlengine/TodoWrefAttr.java
+++ b/org/madore/damlengine/TodoWrefAttr.java
@@ -42,7 +42,7 @@ public class TodoWrefAttr extends TodoAttr {
String targetFragment = "d." + wrefYearStr + "-" + wrefMonthStr
+ "-" + wrefDayStr + "." + wrefNumberStr + wrefSupplementStr;
String target = targetFile + "#" + targetFragment;
- this.owner.removeAttribute(this.attr.getName());
+ this.owner.removeAttributeNode(this.attr);
this.owner.setAttributeNS(null, "href", target);
if ( ! this.owner.hasAttributeNS(null, "class") )
this.owner.setAttributeNS(null, "class", "weblog-internal-link");
diff --git a/org/madore/damlengine/TodoXemptyAttr.java b/org/madore/damlengine/TodoXemptyAttr.java
index a9f7c94..332a63c 100644
--- a/org/madore/damlengine/TodoXemptyAttr.java
+++ b/org/madore/damlengine/TodoXemptyAttr.java
@@ -21,7 +21,7 @@ public class TodoXemptyAttr extends TodoAttr {
@Override
public void handle() {
- this.owner.removeAttribute(this.attr.getName());
+ this.owner.removeAttributeNode(this.attr);
this.owner.appendChild(ctx.doc.createComment(" EMPTY "));
}
diff --git a/org/madore/damlengine/TodoXmlnsAttr.java b/org/madore/damlengine/TodoXmlnsAttr.java
new file mode 100644
index 0000000..81dafb5
--- /dev/null
+++ b/org/madore/damlengine/TodoXmlnsAttr.java
@@ -0,0 +1,28 @@
+package org.madore.damlengine;
+
+import org.w3c.dom.*;
+
+public class TodoXmlnsAttr extends TodoAttr {
+
+ public static class Factory extends TodoAttr.Factory {
+ @Override
+ public TodoXmlnsAttr newItem(Attr attr, Element owner,
+ Context ctx,
+ TodoItem caller) {
+ return new TodoXmlnsAttr(attr, owner, ctx, caller);
+ }
+ }
+
+ public TodoXmlnsAttr(Attr attr, Element owner,
+ Context ctx,
+ TodoItem caller) {
+ super(attr, owner, ctx, caller);
+ }
+
+ @Override
+ public void handle() {
+ if ( this.attr.getName().equals("xmlns") )
+ this.owner.removeAttributeNode(this.attr);
+ }
+
+}