mirror of
https://github.com/hapifhir/org.hl7.fhir.core.git
synced 2025-02-07 05:18:14 +00:00
add xhtml processing directly
This commit is contained in:
parent
23fdcf304d
commit
e5a709e8e8
@ -37,6 +37,8 @@ import org.hl7.fhir.r5.model.ValueSet;
|
|||||||
import org.hl7.fhir.r5.utils.FHIRPathEngine.ExpressionNodeWithOffset;
|
import org.hl7.fhir.r5.utils.FHIRPathEngine.ExpressionNodeWithOffset;
|
||||||
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
|
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
|
||||||
import org.hl7.fhir.utilities.Utilities;
|
import org.hl7.fhir.utilities.Utilities;
|
||||||
|
import org.hl7.fhir.utilities.xhtml.NodeType;
|
||||||
|
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
||||||
|
|
||||||
public class LiquidEngine implements IEvaluationContext {
|
public class LiquidEngine implements IEvaluationContext {
|
||||||
|
|
||||||
@ -427,4 +429,42 @@ public class LiquidEngine implements IEvaluationContext {
|
|||||||
return engine.getWorker().fetchResource(ValueSet.class, url);
|
return engine.getWorker().fetchResource(ValueSet.class, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lightweight method to replace fixed constants in resources
|
||||||
|
*
|
||||||
|
* @param node
|
||||||
|
* @param vars
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean replaceInHtml(XhtmlNode node, Map<String, String> vars) {
|
||||||
|
boolean replaced = false;
|
||||||
|
if (node.getNodeType() == NodeType.Text || node.getNodeType() == NodeType.Comment) {
|
||||||
|
String cnt = node.getContent();
|
||||||
|
for (String n : vars.keySet()) {
|
||||||
|
cnt = cnt.replace(n, vars.get(n));
|
||||||
|
}
|
||||||
|
if (!cnt.equals(node.getContent())) {
|
||||||
|
node.setContent(cnt);
|
||||||
|
replaced = true;
|
||||||
|
}
|
||||||
|
} else if (node.getNodeType() == NodeType.Element || node.getNodeType() == NodeType.Document) {
|
||||||
|
for (XhtmlNode c : node.getChildNodes()) {
|
||||||
|
if (replaceInHtml(c, vars)) {
|
||||||
|
replaced = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String an : node.getAttributes().keySet()) {
|
||||||
|
String cnt = node.getAttributes().get(an);
|
||||||
|
for (String n : vars.keySet()) {
|
||||||
|
cnt = cnt.replace(n, vars.get(n));
|
||||||
|
}
|
||||||
|
if (!cnt.equals(node.getAttributes().get(an))) {
|
||||||
|
node.getAttributes().put(an, cnt);
|
||||||
|
replaced = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return replaced;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user