Search in sources :

Example 16 with XhtmlComposer

use of org.hl7.fhir.utilities.xhtml.XhtmlComposer in project kindling by HL7.

the class Publisher method processFragment.

private void processFragment(String filename, XhtmlNode node, String type, String clss, String id) throws Exception {
    if ("xml".equals(clss)) {
        String xml = new XhtmlComposer(XhtmlComposer.XML).compose(node);
        Fragment f = new Fragment();
        f.setType(type);
        f.setXml(Utilities.unescapeXml(xml));
        f.setPage(filename);
        f.setJson(false);
        f.setId(id);
        fragments.add(f);
    }
    if ("json".equals(clss)) {
        String xml = new XhtmlComposer(XhtmlComposer.XML).compose(node);
        Fragment f = new Fragment();
        f.setType(type);
        f.setXml(xml);
        f.setPage(filename);
        f.setId(id);
        f.setJson(true);
        fragments.add(f);
    }
}
Also used : XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer)

Example 17 with XhtmlComposer

use of org.hl7.fhir.utilities.xhtml.XhtmlComposer in project kindling by HL7.

the class MappingsGenerator method generate.

public void generate(ResourceDefn resource) throws IOException {
    StringBuilder s = new StringBuilder();
    List<String> maps = new ArrayList<String>();
    listKnownMappings(resource.getRoot(), maps);
    Collections.sort(maps, new Sorter());
    StringBuilder list = new StringBuilder();
    for (String m : maps) {
        MappingSpace ms = definitions.getMapTypes().get(m);
        list.append("|" + ms.getTitle() + "#" + ms.getId());
        s.append("<a name=\"" + m + "\"> </a><a name=\"" + ms.getId() + "\"> </a>");
        if (!Utilities.noString(ms.getLink()))
            s.append("<h3>" + ms.getTitle() + " (<a href=\"" + ms.getLink() + "\">" + m + "</a>)</h3>");
        else
            s.append("<h3>" + ms.getTitle() + " (" + m + ")</h3>");
        XhtmlNode pre = ms.getPreamble();
        if (pre != null)
            s.append(new XhtmlComposer(XhtmlComposer.HTML).compose(pre));
        s.append("<table class=\"grid\">\r\n");
        genElement(s, 0, resource.getRoot(), m, ROOT_ONLY, true, ms.isSparse());
        genInherited(s, resource, m);
        genElement(s, 0, resource.getRoot(), m, CHILDREN_ONLY, true, ms.isSparse());
        s.append("</table>\r\n");
    }
    mappings = s.toString();
    mappingsList = list.length() == 0 ? "" : list.toString().substring(1);
}
Also used : MappingSpace(org.hl7.fhir.definitions.model.MappingSpace) ArrayList(java.util.ArrayList) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 18 with XhtmlComposer

use of org.hl7.fhir.utilities.xhtml.XhtmlComposer in project kindling by HL7.

the class MappingsGenerator method generate.

public void generate(StructureDefinition profile) throws IOException {
    if (profile.getMapping().isEmpty())
        mappings = "<p>No Mappings</p>";
    else {
        StringBuilder s = new StringBuilder();
        for (StructureDefinitionMappingComponent map : profile.getMapping()) {
            s.append("<a name=\"" + map.getIdentity() + "\"> </a><h3>" + map.getName() + " (" + map.getUri() + ")</h3>");
            if (map.hasComment())
                s.append("<p>" + Utilities.escapeXml(map.getComment()) + "</p>");
            else if (definitions.getMapTypes().containsKey(map.getUri())) {
                XhtmlNode pre = definitions.getMapTypes().get(map.getUri()).getPreamble();
                if (pre != null)
                    s.append(new XhtmlComposer(XhtmlComposer.HTML).compose(pre));
            }
            s.append("<table class=\"grid\">\r\n");
            s.append(" <tr><td colspan=\"3\"><b>" + Utilities.escapeXml(profile.getName()) + "</b></td></tr>\r\n");
            String path = null;
            for (ElementDefinition e : profile.getSnapshot().getElement()) {
                if (path == null || !e.getPath().startsWith(path)) {
                    path = null;
                    if (e.hasMax() && e.getMax().equals("0")) {
                        path = e.getPath() + ".";
                    } else
                        genElement(s, e, map.getIdentity());
                }
            }
            s.append("</table>\r\n");
        }
        mappings = s.toString();
    }
}
Also used : StructureDefinitionMappingComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 19 with XhtmlComposer

use of org.hl7.fhir.utilities.xhtml.XhtmlComposer in project kindling by HL7.

the class MappingsGenerator method generateExtension.

public void generateExtension(StructureDefinition ed) throws IOException {
    if (ed.getMapping().isEmpty())
        mappings = "<p>No Mappings</p>";
    else {
        StringBuilder s = new StringBuilder();
        for (StructureDefinitionMappingComponent map : ed.getMapping()) {
            s.append("<a name=\"" + map.getIdentity() + "\"> </a><h3>" + map.getName() + " (" + map.getUri() + ")</h3>");
            if (map.hasComment())
                s.append("<p>" + Utilities.escapeXml(map.getComment()) + "</p>");
            else if (definitions.getMapTypes().containsKey(map.getUri())) {
                XhtmlNode pre = definitions.getMapTypes().get(map.getUri()).getPreamble();
                if (pre != null)
                    s.append(new XhtmlComposer(XhtmlComposer.HTML).compose(pre));
            }
            s.append("<table class=\"grid\">\r\n");
            s.append(" <tr><td colspan=\"3\"><b>" + Utilities.escapeXml(ed.getName()) + "</b></td></tr>\r\n");
            String path = null;
            for (ElementDefinition e : ed.getSnapshot().getElement()) {
                if (path == null || !e.getPath().startsWith(path)) {
                    path = null;
                    if (e.hasMax() && e.getMax().equals("0")) {
                        path = e.getPath() + ".";
                    } else
                        genElement(s, e, map.getIdentity());
                }
            }
            s.append("</table>\r\n");
        }
        mappings = s.toString();
    }
}
Also used : StructureDefinitionMappingComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 20 with XhtmlComposer

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

the class SpecDifferenceEvaluator method getDiffAsHtml.

public String getDiffAsHtml(TypeLinkProvider linker) throws IOException {
    this.linker = linker;
    start();
    header("Types");
    for (String s : sorted(revision.getTypes().keySet())) {
        StructureDefinition orig = original.getTypes().get(s);
        StructureDefinition rev = revision.getTypes().get(s);
        if (orig == null) {
            markNew(rev.getName(), true, false, false);
        } else if (rev.getKind() == StructureDefinitionKind.PRIMITIVETYPE) {
            markNoChanges(rev.getName(), true);
        } else if (rev.hasDerivation() && orig.hasDerivation() && rev.getDerivation() != orig.getDerivation()) {
            markChanged(rev.getName(), "Changed from a " + orig.getDerivation().toCode() + " to a " + rev.getDerivation().toCode(), true);
        } else {
            compare(orig, rev);
        }
    }
    for (String s : sorted(original.getTypes().keySet())) {
        StructureDefinition orig = original.getTypes().get(s);
        StructureDefinition rev = revision.getTypes().get(s);
        if (rev == null)
            markDeleted(orig.getName(), true);
    }
    header("Resources");
    for (String s : sorted(revision.getResources().keySet())) {
        StructureDefinition orig = original.getResources().get(checkRename(s));
        StructureDefinition rev = revision.getResources().get(s);
        if (orig == null) {
            markNew(rev.getName(), true, true, false);
        } else {
            compare(orig, rev);
        }
    }
    for (String s : sorted(original.getResources().keySet())) {
        StructureDefinition orig = original.getResources().get(s);
        StructureDefinition rev = revision.getResources().get(s);
        if (rev == null)
            markDeleted(orig.getName(), true);
    }
    return new XhtmlComposer(false, true).compose(tbl);
}
Also used : XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer)

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