Search in sources :

Example 41 with XhtmlParser

use of org.hl7.fhir.utilities.xhtml.XhtmlParser in project org.hl7.fhir.core by hapifhir.

the class LiquidRenderer method render.

@Override
public boolean render(XhtmlNode x, ResourceWrapper r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
    LiquidEngine engine = new LiquidEngine(context.getWorker(), context.getServices());
    XhtmlNode xn;
    try {
        LiquidDocument doc = engine.parse(liquidTemplate, "template");
        String html = engine.evaluate(doc, r.getBase(), rcontext);
        xn = new XhtmlParser().parseFragment(html);
        if (!x.getName().equals("div"))
            throw new FHIRException("Error in template: Root element is not 'div'");
    } catch (FHIRException | IOException e) {
        xn = new XhtmlNode(NodeType.Element, "div");
        xn.para().b().style("color: maroon").tx("Exception generating Narrative: " + e.getMessage());
    }
    x.getChildNodes().addAll(xn.getChildNodes());
    return true;
}
Also used : LiquidDocument(org.hl7.fhir.r4b.utils.LiquidEngine.LiquidDocument) XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) IOException(java.io.IOException) LiquidEngine(org.hl7.fhir.r4b.utils.LiquidEngine) FHIRException(org.hl7.fhir.exceptions.FHIRException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 42 with XhtmlParser

use of org.hl7.fhir.utilities.xhtml.XhtmlParser in project org.hl7.fhir.core by hapifhir.

the class LiquidRenderer method render.

@Override
public boolean render(XhtmlNode x, Resource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
    LiquidEngine engine = new LiquidEngine(context.getWorker(), context.getServices());
    XhtmlNode xn;
    try {
        LiquidDocument doc = engine.parse(liquidTemplate, "template");
        String html = engine.evaluate(doc, r, rcontext);
        xn = new XhtmlParser().parseFragment(html);
        if (!x.getName().equals("div"))
            throw new FHIRException("Error in template: Root element is not 'div'");
    } catch (FHIRException | IOException e) {
        xn = new XhtmlNode(NodeType.Element, "div");
        xn.para().b().style("color: maroon").tx("Exception generating Narrative: " + e.getMessage());
    }
    x.getChildNodes().addAll(xn.getChildNodes());
    return true;
}
Also used : LiquidDocument(org.hl7.fhir.r4b.utils.LiquidEngine.LiquidDocument) XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) IOException(java.io.IOException) LiquidEngine(org.hl7.fhir.r4b.utils.LiquidEngine) FHIRException(org.hl7.fhir.exceptions.FHIRException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)40 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)25 FHIRException (org.hl7.fhir.exceptions.FHIRException)19 IOException (java.io.IOException)14 XhtmlComposer (org.hl7.fhir.utilities.xhtml.XhtmlComposer)11 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)10 FileNotFoundException (java.io.FileNotFoundException)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)7 XhtmlDocument (org.hl7.fhir.utilities.xhtml.XhtmlDocument)6 TransformerException (javax.xml.transform.TransformerException)5 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)5 CDANarrativeFormat (org.hl7.fhir.utilities.xhtml.CDANarrativeFormat)5 Node (org.w3c.dom.Node)5 NotImplementedException (org.apache.commons.lang3.NotImplementedException)4 MarkDownProcessor (org.hl7.fhir.utilities.MarkDownProcessor)4 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)3 ArrayList (java.util.ArrayList)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3