Search in sources :

Example 71 with XhtmlComposer

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

the class XmlParserBase method composeXhtml.

protected void composeXhtml(String name, XhtmlNode html) throws IOException {
    if (!Utilities.noString(xhtmlMessage)) {
        xml.enter(XhtmlComposer.XHTML_NS, name);
        xml.comment(xhtmlMessage, false);
        xml.exit(XhtmlComposer.XHTML_NS, name);
    } else {
        XhtmlComposer comp = new XhtmlComposer(XhtmlComposer.XML, htmlPretty);
        // name is also found in the html and should the same
        // ? check that
        boolean oldPretty = xml.isPretty();
        xml.setPretty(htmlPretty);
        if (html.getNodeType() != NodeType.Text && html.getNsDecl() == null)
            xml.namespace(XhtmlComposer.XHTML_NS, null);
        comp.compose(xml, html);
        xml.setPretty(oldPretty);
    }
}
Also used : XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer)

Example 72 with XhtmlComposer

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

the class ValueSetExpansionCache method loadCache.

private void loadCache() throws FHIRFormatError, IOException {
    File[] files = new File(cacheFolder).listFiles();
    for (File f : files) {
        if (f.getName().endsWith(".xml")) {
            final FileInputStream is = new FileInputStream(f);
            try {
                Resource r = context.newXmlParser().setOutputStyle(OutputStyle.PRETTY).parse(is);
                if (r instanceof OperationOutcome) {
                    OperationOutcome oo = (OperationOutcome) r;
                    expansions.put(ToolingExtensions.getExtension(oo, VS_ID_EXT).getValue().toString(), new ValueSetExpansionOutcome(new XhtmlComposer(XhtmlComposer.XML, false).composePlainText(oo.getText().getDiv()), TerminologyServiceErrorClass.UNKNOWN));
                } else if (r instanceof ValueSet) {
                    ValueSet vs = (ValueSet) r;
                    if (vs.hasExpansion())
                        expansions.put(vs.getUrl(), new ValueSetExpansionOutcome(vs));
                    else {
                        canonicals.put(vs.getUrl(), vs);
                        if (vs.hasVersion())
                            canonicals.put(vs.getUrl() + "|" + vs.getVersion(), vs);
                    }
                } else if (r instanceof CanonicalResource) {
                    CanonicalResource md = (CanonicalResource) r;
                    canonicals.put(md.getUrl(), md);
                    if (md.hasVersion())
                        canonicals.put(md.getUrl() + "|" + md.getVersion(), md);
                }
            } finally {
                IOUtils.closeQuietly(is);
            }
        }
    }
}
Also used : OperationOutcome(org.hl7.fhir.r5.model.OperationOutcome) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) Resource(org.hl7.fhir.r5.model.Resource) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) ValueSetExpansionOutcome(org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome) File(java.io.File) ValueSet(org.hl7.fhir.r5.model.ValueSet) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) FileInputStream(java.io.FileInputStream)

Example 73 with XhtmlComposer

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

the class XmlParserBase method composeXhtml.

protected void composeXhtml(String name, XhtmlNode html) throws IOException {
    if (!Utilities.noString(xhtmlMessage)) {
        xml.enter(XhtmlComposer.XHTML_NS, name);
        xml.comment(xhtmlMessage, false);
        xml.exit(XhtmlComposer.XHTML_NS, name);
    } else {
        XhtmlComposer comp = new XhtmlComposer(true, htmlPretty);
        // name is also found in the html and should the same
        // ? check that
        boolean oldPretty = xml.isPretty();
        if (html.getNodeType() != NodeType.Text)
            xml.namespace(XhtmlComposer.XHTML_NS, null);
        comp.compose(xml, html);
        xml.setPretty(oldPretty);
    }
}
Also used : XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer)

Example 74 with XhtmlComposer

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

the class XmlParserBase method composeXhtml.

protected void composeXhtml(String name, XhtmlNode html) throws IOException {
    if (!Utilities.noString(xhtmlMessage)) {
        xml.enter(XhtmlComposer.XHTML_NS, name);
        xml.comment(xhtmlMessage, false);
        xml.exit(XhtmlComposer.XHTML_NS, name);
    } else {
        XhtmlComposer comp = new XhtmlComposer(XhtmlComposer.XML, htmlPretty);
        // name is also found in the html and should the same
        // ? check that
        boolean oldPretty = xml.isPretty();
        xml.setPretty(htmlPretty);
        if (html.getNodeType() != NodeType.Text && html.getNsDecl() == null)
            xml.namespace(XhtmlComposer.XHTML_NS, null);
        comp.compose(xml, html);
        xml.setPretty(oldPretty);
    }
}
Also used : XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer)

Example 75 with XhtmlComposer

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

the class ComparisonRenderer method renderValueSet.

private void renderValueSet(String id, ValueSetComparison comp) throws FHIRException, IOException {
    String template = templates.get("ValueSet");
    Map<String, Base> vars = new HashMap<>();
    ValueSetComparer cs = new ValueSetComparer(session);
    vars.put("left", new StringType(comp.getLeft().present()));
    vars.put("right", new StringType(comp.getRight().present()));
    vars.put("leftId", new StringType(comp.getLeft().getId()));
    vars.put("rightId", new StringType(comp.getRight().getId()));
    vars.put("leftUrl", new StringType(comp.getLeft().getUrl()));
    vars.put("rightUrl", new StringType(comp.getRight().getUrl()));
    vars.put("errors", new StringType(new XhtmlComposer(true).compose(cs.renderErrors(comp))));
    vars.put("metadata", new StringType(new XhtmlComposer(true).compose(cs.renderMetadata(comp, "", ""))));
    vars.put("compose", new StringType(new XhtmlComposer(true).compose(cs.renderCompose(comp, "", ""))));
    vars.put("expansion", new StringType(new XhtmlComposer(true).compose(cs.renderExpansion(comp, "", ""))));
    String cnt = processTemplate(template, "ValueSet", vars);
    TextFile.stringToFile(cnt, file(comp.getId() + ".html"));
    new org.hl7.fhir.r4b.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(folder, comp.getId() + "-union.json")), comp.getUnion());
    new org.hl7.fhir.r4b.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(folder, comp.getId() + "-intersection.json")), comp.getIntersection());
}
Also used : HashMap(java.util.HashMap) StringType(org.hl7.fhir.r4b.model.StringType) FileOutputStream(java.io.FileOutputStream) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) Base(org.hl7.fhir.r4b.model.Base)

Aggregations

XhtmlComposer (org.hl7.fhir.utilities.xhtml.XhtmlComposer)78 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)31 FHIRException (org.hl7.fhir.exceptions.FHIRException)15 IOException (java.io.IOException)14 FileOutputStream (java.io.FileOutputStream)13 NotImplementedException (org.apache.commons.lang3.NotImplementedException)11 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)11 File (java.io.File)10 FileNotFoundException (java.io.FileNotFoundException)10 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)10 RenderingContext (org.hl7.fhir.r5.renderers.utils.RenderingContext)10 FileInputStream (java.io.FileInputStream)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 HashMap (java.util.HashMap)7 TransformerException (javax.xml.transform.TransformerException)7 XmlParser (org.hl7.fhir.r5.formats.XmlParser)7 ValueSet (org.hl7.fhir.r5.model.ValueSet)7 CanonicalResource (org.hl7.fhir.r5.model.CanonicalResource)6 URISyntaxException (java.net.URISyntaxException)5 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)5