summaryrefslogtreecommitdiffstats
path: root/org
diff options
context:
space:
mode:
Diffstat (limited to 'org')
-rw-r--r--org/madore/damlengine/LangHelper.java24
-rw-r--r--org/madore/damlengine/TodoDamlElement.java14
2 files changed, 23 insertions, 15 deletions
diff --git a/org/madore/damlengine/LangHelper.java b/org/madore/damlengine/LangHelper.java
index 280e5ca..e2a74db 100644
--- a/org/madore/damlengine/LangHelper.java
+++ b/org/madore/damlengine/LangHelper.java
@@ -2,15 +2,23 @@ package org.madore.damlengine;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
+import org.w3c.dom.Attr;
public class LangHelper {
public static final String LANG = "lang";
public static String getLangNorec(Node node) {
- if ( node instanceof Element )
- return ((Element)node).getAttributeNS(DamlEngine.XML_NS, LANG);
- else
+ // Returns null when no xml:lang attribute is found,
+ // otherwise, returns its value.
+ if ( node instanceof Element ) {
+ Attr lang = ((Element)node).
+ getAttributeNodeNS(DamlEngine.XML_NS, LANG);
+ if ( lang == null )
+ return null;
+ else
+ return lang.getValue();
+ } else
return null;
}
@@ -25,22 +33,22 @@ public class LangHelper {
}
public static String getLangRec(Node node) {
- // node may be null (in which case, return null)
+ // Never returns null (returns the empty string for no language).
+ // node may be null (in which case, return "").
while ( node != null ) {
String lang = getLangNorec(node);
if ( lang != null )
return lang;
node = node.getParentNode();
}
- return null;
+ return "";
}
public static void setLangRec(Element node, String lang) {
if ( lang == null )
throw new Error("lang is null in setLangRec");
- Node parentNode = node.getParentNode();
- String parentLang = (parentNode!=null)?getLangNorec(parentNode):null;
- if ( parentLang != null && lang.equals(parentLang) )
+ String parentLang = getLangRec(node.getParentNode());
+ if ( lang.equals(parentLang) )
unsetLangNorec(node);
else
setLangNorec(node,lang);
diff --git a/org/madore/damlengine/TodoDamlElement.java b/org/madore/damlengine/TodoDamlElement.java
index 330c92d..e7b9527 100644
--- a/org/madore/damlengine/TodoDamlElement.java
+++ b/org/madore/damlengine/TodoDamlElement.java
@@ -26,12 +26,12 @@ public class TodoDamlElement extends TodoDefaultElement {
public void handleNodeOnly() {
if ( ! ( options instanceof DamlEngine.RootOptions ) )
throw new Error("daml node can only be root node");
- String uriToTop = node.getAttributeNS(null, "uri-to-top");
- if ( uriToTop != null )
- ctx.uriToTop = uriToTop;
- String fileName = node.getAttributeNS(null, "file.name");
- if ( fileName != null )
- ctx.fileName = fileName;
+ final String uriToTopName = "uri-to-top";
+ if ( node.hasAttributeNS(null, uriToTopName) )
+ ctx.uriToTop = node.getAttributeNS(null, uriToTopName);
+ final String fileNameName = "file.name";
+ if ( node.hasAttributeNS(null, fileNameName) )
+ ctx.fileName = node.getAttributeNS(null, fileNameName);
if ( ctx.htmlNode != null )
throw new Error("html node already defined at daml node");
@@ -68,7 +68,7 @@ public class TodoDamlElement extends TodoDefaultElement {
}
meta = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "link");
meta.setAttributeNS(null, "rel", "Shortcut Icon");
- meta.setAttributeNS(null, "href", (((uriToTop!=null)?uriToTop:"")
+ meta.setAttributeNS(null, "href", (((ctx.uriToTop!=null)?ctx.uriToTop:"")
+"favicon.ico"));
ctx.headNode.appendChild(meta);
ctx.headNode.appendChild(ctx.doc.createTextNode("\n"));