From 3c0b20eb16128252934d6f2d0101a34a9cf32d7d Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 22 Sep 2020 02:34:04 +1000 Subject: [PATCH] Add quality code (yet to turn it on) --- .../hl7/fhir/utilities/xhtml/XhtmlNode.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java index 9a0d0cba7..e561009f2 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java @@ -90,6 +90,9 @@ public class XhtmlNode implements IBaseXhtml { private List childNodes = new ArrayList(); private String content; private boolean notPretty; + private boolean inPara; + private boolean inLink; + public XhtmlNode() { super(); @@ -144,7 +147,7 @@ public class XhtmlNode implements IBaseXhtml { return this; } - public void validate(List errors, String path, boolean inResource, boolean inPara) { + public void validate(List errors, String path, boolean inResource, boolean inPara, boolean inLink) { if (nodeType == NodeType.Element || nodeType == NodeType.Document) { path = Utilities.noString(path) ? name : path+"/"+name; if (inResource) { @@ -172,13 +175,19 @@ public class XhtmlNode implements IBaseXhtml { if (inPara && Utilities.existsInList(name, "div", "blockquote", "table", "ol", "ul", "p")) { errors.add("Error at "+path+": Found "+name+" inside an html paragraph"); } + if (inLink && Utilities.existsInList(name, "a")) { + errors.add("Error at "+path+": Found an inside an paragraph"); + } if (childNodes != null) { if ("p".equals(name)) { inPara = true; } + if ("a".equals(name)) { + inLink = true; + } for (XhtmlNode child : childNodes) { - child.validate(errors, path, inResource, inPara); + child.validate(errors, path, inResource, inPara, inLink); } } } @@ -191,8 +200,20 @@ public class XhtmlNode implements IBaseXhtml { throw new Error("Wrong node type - node is "+nodeType.toString()+" ('"+getName()+"/"+getContent()+"')"); } +// if (inPara && name.equals("p")) { +// throw new FHIRException("nested Para"); +// } +// if (inLink && name.equals("a")) { +// throw new FHIRException("Nested Link"); +// } XhtmlNode node = new XhtmlNode(NodeType.Element); node.setName(name); + if (inPara || name.equals("p")) { + node.inPara = true; + } + if (inLink || name.equals("a")) { + node.inLink = true; + } childNodes.add(node); return node; } @@ -203,6 +224,12 @@ public class XhtmlNode implements IBaseXhtml { if (!(nodeType == NodeType.Element || nodeType == NodeType.Document)) throw new Error("Wrong node type. is "+nodeType.toString()); XhtmlNode node = new XhtmlNode(NodeType.Element); + if (inPara || name.equals("p")) { + node.inPara = true; + } + if (inLink || name.equals("a")) { + node.inLink = true; + } node.setName(name); childNodes.add(index, node); return node;