summaryrefslogtreecommitdiffstats
path: root/org
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2011-09-07 14:51:59 +0200
committerDavid A. Madore <david+git@madore.org>2011-09-07 14:51:59 +0200
commit7fb2155a48f7312ff71bc841ce587c44f333384b (patch)
treea2c303966a686f5450adf99178b95bab28a90fab /org
parent58e0ddcdc2b5d47db753868b3cc937bbac59ec55 (diff)
downloaddamlengine-7fb2155a48f7312ff71bc841ce587c44f333384b.tar.gz
damlengine-7fb2155a48f7312ff71bc841ce587c44f333384b.tar.bz2
damlengine-7fb2155a48f7312ff71bc841ce587c44f333384b.zip
Fix and correct some aspects of language handling.
In particular, take better care to ensure that when an element is removed which might have an xml:lang attribute, its children keep their original language.
Diffstat (limited to 'org')
-rw-r--r--org/madore/damlengine/LangHelper.java8
-rw-r--r--org/madore/damlengine/TodoBodyElement.java3
-rw-r--r--org/madore/damlengine/TodoCommentsScript.java6
-rw-r--r--org/madore/damlengine/TodoKillAElement.java3
-rw-r--r--org/madore/damlengine/TodoKillAcronymElement.java6
-rw-r--r--org/madore/damlengine/TodoWeblogElement.java6
6 files changed, 26 insertions, 6 deletions
diff --git a/org/madore/damlengine/LangHelper.java b/org/madore/damlengine/LangHelper.java
index a94f5be..aea1240 100644
--- a/org/madore/damlengine/LangHelper.java
+++ b/org/madore/damlengine/LangHelper.java
@@ -32,6 +32,14 @@ public class LangHelper {
node.removeAttributeNS(DamlEngine.XML_NS, LANG);
}
+ public static void setWeakLangNorec(Element node, String lang) {
+ if ( lang == null )
+ throw new NullPointerException("lang is null in setWeakLangNorec");
+ String currentLang = getLangNorec(node);
+ if ( currentLang == null )
+ setLangNorec(node,lang);
+ }
+
public static String getLangRec(Node node) {
// Never returns null (returns the empty string for no language).
// node may be null (in which case, return "").
diff --git a/org/madore/damlengine/TodoBodyElement.java b/org/madore/damlengine/TodoBodyElement.java
index 1db657b..2e48ee8 100644
--- a/org/madore/damlengine/TodoBodyElement.java
+++ b/org/madore/damlengine/TodoBodyElement.java
@@ -27,6 +27,7 @@ public final class TodoBodyElement extends TodoDefaultElement {
throw new IllegalArgumentException("body node can only be child of daml node");
Element parent = (Element)(this.node.getParentNode());
+ String explicitLang = LangHelper.getLangNorec(this.node);
ArrayList<Node> childList = getChildList(this.node);
ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>(childList.size());
for ( Node child : childList ) {
@@ -37,6 +38,8 @@ public final class TodoBodyElement extends TodoDefaultElement {
}
parent.insertBefore(child, node);
if ( child.getNodeType() == Node.ELEMENT_NODE ) {
+ if ( explicitLang != null )
+ LangHelper.setWeakLangNorec((Element)child, explicitLang);
TodoElement it
= TodoElement.getTodoElement((Element)child, this.ctx, this);
toProcess.add(it);
diff --git a/org/madore/damlengine/TodoCommentsScript.java b/org/madore/damlengine/TodoCommentsScript.java
index 224d547..eb250e8 100644
--- a/org/madore/damlengine/TodoCommentsScript.java
+++ b/org/madore/damlengine/TodoCommentsScript.java
@@ -1,5 +1,6 @@
package org.madore.damlengine;
+import java.util.regex.Pattern;
import org.w3c.dom.*;
public final class TodoCommentsScript extends TodoElement {
@@ -13,6 +14,11 @@ public final class TodoCommentsScript extends TodoElement {
@Override
public void handle() {
if ( ctx.gc.commentsJSParam == null ) {
+ 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);
return;
}
diff --git a/org/madore/damlengine/TodoKillAElement.java b/org/madore/damlengine/TodoKillAElement.java
index 4478fae..f230ee0 100644
--- a/org/madore/damlengine/TodoKillAElement.java
+++ b/org/madore/damlengine/TodoKillAElement.java
@@ -22,11 +22,14 @@ public final class TodoKillAElement extends TodoDefaultElement {
@Override
public void handleNodeOnly() {
+ String explicitLang = LangHelper.getLangNorec(this.node);
ArrayList<Node> childList = getChildList(node);
ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>(childList.size());
for ( Node child : childList ) {
node.getParentNode().insertBefore(child, node);
if ( child.getNodeType() == Node.ELEMENT_NODE ) {
+ if ( explicitLang != null )
+ LangHelper.setWeakLangNorec((Element)child, explicitLang);
TodoElement it
= TodoElement.getTodoElement((Element)child, this.ctx, this);
toProcess.add(it);
diff --git a/org/madore/damlengine/TodoKillAcronymElement.java b/org/madore/damlengine/TodoKillAcronymElement.java
index 65664e9..f7e6190 100644
--- a/org/madore/damlengine/TodoKillAcronymElement.java
+++ b/org/madore/damlengine/TodoKillAcronymElement.java
@@ -28,9 +28,9 @@ public final class TodoKillAcronymElement extends TodoDefaultElement {
"acronym "+node.getAttributeNS(null, "class"));
else
newNode.setAttributeNS(null, "class", "acronym");
- String lang = LangHelper.getLangNorec(node);
- if ( lang != null )
- LangHelper.setLangNorec(newNode, lang);
+ String explicitLang = LangHelper.getLangNorec(node);
+ if ( explicitLang != null )
+ LangHelper.setLangNorec(newNode, explicitLang);
ArrayList<Attr> attrList = getAttrList(this.node);
for ( Attr attr : attrList ) {
if ( attr.getNamespaceURI() == null ) {
diff --git a/org/madore/damlengine/TodoWeblogElement.java b/org/madore/damlengine/TodoWeblogElement.java
index 3d457a8..1cbc53c 100644
--- a/org/madore/damlengine/TodoWeblogElement.java
+++ b/org/madore/damlengine/TodoWeblogElement.java
@@ -25,7 +25,7 @@ public final class TodoWeblogElement extends TodoDefaultElement {
public void handleNodeOnly() {
System.err.println("warning: weblog element should not be processed this way!");
Node parent = node.getParentNode();
- String lang = LangHelper.getLangNorec(node);
+ String explicitLang = LangHelper.getLangNorec(node);
ArrayList<Node> childList = getChildList(this.node);
ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>(childList.size()+8);
for ( Node child : childList ) {
@@ -36,8 +36,8 @@ public final class TodoWeblogElement extends TodoDefaultElement {
}
parent.insertBefore(child, node);
if ( child.getNodeType() == Node.ELEMENT_NODE ) {
- if ( lang != null )
- LangHelper.setLangRec((Element)child, lang); // Dubious
+ if ( explicitLang != null )
+ LangHelper.setWeakLangNorec((Element)child, explicitLang);
TodoElement it
= TodoElement.getTodoElement((Element)child, this.ctx, this);
toProcess.add(it);