Search in sources :

Example 1 with TurtleSpecGenerator

use of org.hl7.fhir.definitions.generators.specification.TurtleSpecGenerator in project kindling by HL7.

the class PageProcessor method ttlForDt.

private String ttlForDt(String dt, String pn) throws Exception {
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    TurtleSpecGenerator gen = new TurtleSpecGenerator(b, pn == null ? null : pn.substring(0, pn.indexOf(".")) + "-definitions.html", null, this, "", version.toCode());
    TypeParser tp = new TypeParser(version.toCode());
    TypeRef t = tp.parse(dt, false, null, workerContext, true).get(0);
    ElementDefn e = definitions.getElementDefn(t.getName());
    if (e == null) {
        gen.close();
        throw new Exception("unable to find definition for " + dt);
    } else {
        gen.generate(e, false);
        gen.close();
    }
    String val = new String(b.toByteArray()) + "\r\n";
    return val;
}
Also used : ITypeParser(org.hl7.fhir.r5.renderers.utils.RenderingContext.ITypeParser) TypeParser(org.hl7.fhir.definitions.parsers.TypeParser) TypeRef(org.hl7.fhir.definitions.model.TypeRef) TurtleSpecGenerator(org.hl7.fhir.definitions.generators.specification.TurtleSpecGenerator) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UcumException(org.fhir.ucum.UcumException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FileNotFoundException(java.io.FileNotFoundException) NotImplementedException(org.apache.commons.lang3.NotImplementedException)

Example 2 with TurtleSpecGenerator

use of org.hl7.fhir.definitions.generators.specification.TurtleSpecGenerator in project kindling by HL7.

the class Publisher method produceResource1.

private void produceResource1(ResourceDefn resource, boolean isAbstract) throws Exception {
    String n = resource.getName().toLowerCase();
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    XmlSpecGenerator gen = new XmlSpecGenerator(bs, n + "-definitions.html", null, page, "");
    gen.generate(resource.getRoot(), isAbstract, true);
    gen.close();
    String xml = new String(bs.toByteArray());
    bs = new ByteArrayOutputStream();
    JsonSpecGenerator genJ = new JsonSpecGenerator(bs, n + "-definitions.html", null, page, "", page.getVersion().toCode());
    genJ.generate(resource.getRoot(), true, isAbstract);
    genJ.close();
    String json = new String(bs.toByteArray());
    bs = new ByteArrayOutputStream();
    TurtleSpecGenerator gent = new TurtleSpecGenerator(bs, n + "-definitions.html", null, page, "", page.getVersion().toCode());
    gent.generate(resource.getRoot(), isAbstract);
    gent.close();
    String ttl = new String(bs.toByteArray());
    xmls.put(n, xml);
    jsons.put(n, json);
    ttls.put(n, ttl);
    generateProfile(resource, n, xml, json, ttl, false);
}
Also used : XmlSpecGenerator(org.hl7.fhir.definitions.generators.specification.XmlSpecGenerator) JsonSpecGenerator(org.hl7.fhir.definitions.generators.specification.JsonSpecGenerator) TurtleSpecGenerator(org.hl7.fhir.definitions.generators.specification.TurtleSpecGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with TurtleSpecGenerator

use of org.hl7.fhir.definitions.generators.specification.TurtleSpecGenerator in project kindling by HL7.

the class Publisher method produceExtensionDefinition.

private void produceExtensionDefinition(StructureDefinition ed) throws FileNotFoundException, Exception {
    if (!ped.contains(ed)) {
        ped.add(ed);
        ImplementationGuideDefn ig = page.getDefinitions().getIgs().get(ed.getUserString(ToolResourceUtilities.NAME_RES_IG));
        String prefix = ig.isCore() ? "" : ig.getCode() + File.separator;
        String filename = ed.getUserString("filename");
        FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + prefix + filename + ".xml");
        new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, ed);
        s.close();
        s = new FileOutputStream(page.getFolders().dstDir + prefix + filename + ".canonical.xml");
        new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, ed);
        s.close();
        s = new FileOutputStream(page.getFolders().dstDir + prefix + filename + ".json");
        new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, ed);
        s.close();
        s = new FileOutputStream(page.getFolders().dstDir + prefix + filename + ".canonical.json");
        new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, ed);
        s.close();
        cloneToXhtml(prefix + filename, ed.getName(), false, "summary-instance", ed.getUrl(), null, wg(ed));
        jsonToXhtml(prefix + filename, ed.getName(), resource2Json(ed), "extension", ed.getUrl(), null, wg(ed));
        ttlToXhtml(prefix + filename, ed.getName(), resource2Ttl(ed), "extension", ed.getUrl(), null, wg(ed));
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        XmlSpecGenerator gen = new XmlSpecGenerator(bytes, filename + "-definitions.html", null, /*"http://hl7.org/fhir/"*/
        page, page.genlevel(ig.isCore() ? 0 : 1));
        gen.generateExtension(ed);
        gen.close();
        String xml = bytes.toString();
        bytes = new ByteArrayOutputStream();
        JsonSpecGenerator genj = new JsonSpecGenerator(bytes, filename + "-definitions.html", null, /*"http://hl7.org/fhir/"*/
        page, page.genlevel(ig.isCore() ? 0 : 1), page.getVersion().toCode());
        genj.generateExtension(ed);
        genj.close();
        String json = bytes.toString();
        bytes = new ByteArrayOutputStream();
        TurtleSpecGenerator gent = new TurtleSpecGenerator(bytes, filename + "-definitions.html", null, /*"http://hl7.org/fhir/"*/
        page, page.genlevel(ig.isCore() ? 0 : 1), page.getVersion().toCode());
        gent.generateExtension(ed);
        gent.close();
        String ttl = bytes.toString();
        bytes = new ByteArrayOutputStream();
        TerminologyNotesGenerator tgen = new TerminologyNotesGenerator(bytes, page);
        tgen.generateExtension("", ed);
        tgen.close();
        String tx = bytes.toString();
        String src = TextFile.fileToString(page.getFolders().templateDir + "template-extension-mappings.html");
        src = page.processExtensionIncludes(filename, ed, xml, json, ttl, tx, src, filename + ".html", ig);
        page.getHTMLChecker().registerFile(prefix + filename + "-mappings.html", "Mappings for Extension " + ed.getName(), HTMLLinkChecker.XHTML_TYPE, true);
        TextFile.stringToFile(src, page.getFolders().dstDir + prefix + filename + "-mappings.html");
        src = TextFile.fileToString(page.getFolders().templateDir + "template-extension-definitions.html");
        src = page.processExtensionIncludes(filename, ed, xml, json, ttl, tx, src, filename + ".html", ig);
        page.getHTMLChecker().registerFile(prefix + filename + "-definitions.html", "Definitions for Extension " + ed.getName(), HTMLLinkChecker.XHTML_TYPE, true);
        TextFile.stringToFile(src, page.getFolders().dstDir + prefix + filename + "-definitions.html");
        src = TextFile.fileToString(page.getFolders().templateDir + "template-extension.html");
        src = page.processExtensionIncludes(filename, ed, xml, json, ttl, tx, src, filename + ".html", ig);
        page.getHTMLChecker().registerFile(prefix + filename + ".html", "Extension " + ed.getName(), HTMLLinkChecker.XHTML_TYPE, true);
        TextFile.stringToFile(src, page.getFolders().dstDir + prefix + filename + ".html");
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XmlSpecGenerator(org.hl7.fhir.definitions.generators.specification.XmlSpecGenerator) JsonSpecGenerator(org.hl7.fhir.definitions.generators.specification.JsonSpecGenerator) TerminologyNotesGenerator(org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator) FileOutputStream(java.io.FileOutputStream) TurtleSpecGenerator(org.hl7.fhir.definitions.generators.specification.TurtleSpecGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 TurtleSpecGenerator (org.hl7.fhir.definitions.generators.specification.TurtleSpecGenerator)3 JsonSpecGenerator (org.hl7.fhir.definitions.generators.specification.JsonSpecGenerator)2 XmlSpecGenerator (org.hl7.fhir.definitions.generators.specification.XmlSpecGenerator)2 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1 UcumException (org.fhir.ucum.UcumException)1 TerminologyNotesGenerator (org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator)1 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)1 ImplementationGuideDefn (org.hl7.fhir.definitions.model.ImplementationGuideDefn)1 TypeRef (org.hl7.fhir.definitions.model.TypeRef)1 TypeParser (org.hl7.fhir.definitions.parsers.TypeParser)1 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)1 FHIRException (org.hl7.fhir.exceptions.FHIRException)1 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)1