we preserve lang attribute on narrative div
This commit is contained in:
James Agnew 2020-01-07 09:53:43 -05:00
parent 9c1a6e61e6
commit d3cf93cf04
3 changed files with 33 additions and 13 deletions

View File

@ -394,13 +394,12 @@ public class XhtmlNode implements IBaseXhtml {
val = XhtmlDt.preprocessXhtmlNamespaceDeclaration(val); val = XhtmlDt.preprocessXhtmlNamespaceDeclaration(val);
try { try {
// TODO: this is ugly XhtmlDocument fragment = new XhtmlParser().parse(val, "div");
XhtmlNode fragment = new XhtmlParser().parseFragment(val); this.attributes = fragment.getAttributes();
this.attributes = fragment.attributes; this.childNodes = fragment.getChildNodes();
this.childNodes = fragment.childNodes; this.content = fragment.getContent();
this.content = fragment.content; this.name = fragment.getName();
this.name = fragment.name; this.nodeType= fragment.getNodeType();
this.nodeType= fragment.nodeType;
} catch (Exception e) { } catch (Exception e) {
// TODO: composer shouldn't throw exception like this // TODO: composer shouldn't throw exception like this
throw new RuntimeException(e); throw new RuntimeException(e);

View File

@ -54,6 +54,7 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -446,7 +447,7 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
} }
public XhtmlDocument parse(InputStream input, String entryName) throws FHIRFormatError, IOException { public XhtmlDocument parse(InputStream input, String entryName) throws FHIRFormatError, IOException {
rdr = new InputStreamReader(input, "UTF-8"); rdr = new InputStreamReader(input, StandardCharsets.UTF_8);
return parse(entryName); return parse(entryName);
} }
@ -1184,7 +1185,7 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
result.setName(n); result.setName(n);
unwindPoint = null; unwindPoint = null;
List<XhtmlNode> p = new ArrayList<XhtmlNode>(); List<XhtmlNode> p = new ArrayList<>();
parseElementInner(result, p, null, true); parseElementInner(result, p, null, true);
return result; return result;

View File

@ -1,10 +1,9 @@
package org.hl7.fhir.utilities.tests; package org.hl7.fhir.utilities.tests;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class XhtmlNodeTest { public class XhtmlNodeTest {
@ -26,5 +25,26 @@ public class XhtmlNodeTest {
} }
/**
* See https://github.com/jamesagnew/hapi-fhir/issues/1658
*/
@Test
public void testLangAttributePreserved() {
XhtmlNode dt = new XhtmlNode();
dt.setValueAsString("<div xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en-US\">help i'm a bug</div>");
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en-US\">help i'm a bug</div>", dt.getValueAsString());
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en-US\">help i'm a bug</div>", new XhtmlNode().setValue(dt.getValue()).getValueAsString());
}
@Test
public void testParseRsquo() {
XhtmlNode dt = new XhtmlNode();
dt.setValueAsString("It&rsquo;s January again");
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">Its January again</div>", dt.getValueAsString());
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">Its January again</div>", new XhtmlNode().setValue(dt.getValue()).getValueAsString());
}
} }