Search in sources :

Example 16 with CSFile

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

the class XmlValidator method checkBySchema.

public Element checkBySchema(String fileToCheck, boolean wantThrow) throws FileNotFoundException, SAXException, IOException, ParserConfigurationException, FHIRException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setValidating(false);
    factory.setSchema(schema);
    DocumentBuilder builder = factory.newDocumentBuilder();
    MyErrorHandler err = new MyErrorHandler(errors, fileToCheck);
    builder.setErrorHandler(err);
    CSFileInputStream f = new CSFileInputStream(new CSFile(fileToCheck));
    Document doc = builder.parse(f);
    if (wantThrow && err.getErrors().size() > 0)
        throw new FHIRException("File " + fileToCheck + " failed schema validation");
    return doc.getDocumentElement();
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Document(org.w3c.dom.Document) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 17 with CSFile

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

the class Publisher method produceTypeProfile.

private void produceTypeProfile(TypeDefn type) throws Exception {
    // ProfileDefn p = new ProfileDefn();
    // p.putMetadata("id", type.getName());
    // p.putMetadata("name", "Basic StructureDefinition for " + type.getName());
    // p.putMetadata("author.name", "FHIR Specification");
    // p.putMetadata("author.ref", "http://hl7.org/fhir");
    // p.putMetadata("description", "Basic StructureDefinition for " + type.getName() + " for validation support");
    // p.putMetadata("status", "draft");
    // p.putMetadata("date", new SimpleDateFormat("yyyy-MM-dd", new Locale("en", "US")).format(new Date()));
    // p.getElements().add(type);
    // ProfileGenerator pgen = new ProfileGenerator(page.getDefinitions());
    // String fn = "type-" + type.getName() + ".profile.xml";
    // StructureDefinition rp = pgen.generate(p, "type-" + type.getName() + ".profile", "<div>Type definition for " + type.getName() + " from <a href=\"http://hl7.org/fhir/datatypes.html#" + type.getName()
    // + "\">FHIR Specification</a></div>");
    String fn = type.getName().toLowerCase() + ".profile.xml";
    StructureDefinition rp = type.getProfile();
    FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + fn);
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, rp);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(fn, ".canonical.xml"));
    new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, rp);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(fn, ".json"));
    new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, rp);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(fn, ".canonical.json"));
    new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, rp);
    s.close();
    Utilities.copyFile(new CSFile(page.getFolders().dstDir + fn), new CSFile(Utilities.path(page.getFolders().dstDir, "examples", fn)));
    addToResourceFeed(rp, page.getTypeBundle(), fn);
    // saveAsPureHtml(rp, new FileOutputStream(page.getFolders().dstDir+ "html"
    // + File.separator + "datatypes.html"));
    cloneToXhtml(type.getName().toLowerCase() + ".profile", "StructureDefinition for " + type.getName(), false, "profile-instance:type:" + type.getName(), "Type", null, wg("mnm"));
    jsonToXhtml(type.getName().toLowerCase() + ".profile", "StructureDefinition for " + type.getName(), resource2Json(rp), "profile-instance:type:" + type.getName(), "Type", null, wg("mnm"));
    ttlToXhtml(type.getName().toLowerCase() + ".profile", "StructureDefinition for " + type.getName(), resource2Ttl(rp), "profile-instance:type:" + type.getName(), "Type", null, wg("mnm"));
    String shex = new ShExGenerator(page.getWorkerContext()).generate(HTMLLinkPolicy.NONE, rp);
    TextFile.stringToFile(shex, Utilities.changeFileExt(page.getFolders().dstDir + fn, ".shex"));
    shexToXhtml(type.getName().toLowerCase(), "ShEx statement for " + type.getName(), shex, "profile-instance:type:" + type.getName(), "Type", null, wg("mnm"));
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) FileOutputStream(java.io.FileOutputStream) CSFile(org.hl7.fhir.utilities.CSFile) JsonParser(org.hl7.fhir.r5.formats.JsonParser) ShExGenerator(org.hl7.fhir.r5.conformance.ShExGenerator)

Example 18 with CSFile

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

the class Publisher method copyIgImage.

private void copyIgImage(ImplementationGuideDefn ig, String path) throws IOException {
    File file = new File(Utilities.path(page.getFolders().rootDir, ig.getSource(), "..", path));
    String prefix = ig.isCore() ? "" : ig.getCode() + File.separator;
    if (path.contains("*")) {
        final String filter = file.getName().replace("?", ".?").replace("*", ".*?");
        File[] files = new File(file.getParent()).listFiles(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                return name.matches(filter);
            }
        });
        for (File f : files) {
            Utilities.copyFile(f, new CSFile(Utilities.path(page.getFolders().dstDir, prefix + f.getName())));
            page.getHTMLChecker().registerFile(prefix + f.getName(), "Support File", HTMLLinkChecker.determineType(f.getName()), true);
        }
    } else {
        Utilities.copyFile(file, new CSFile(Utilities.path(page.getFolders().dstDir, prefix + file.getName())));
        page.getHTMLChecker().registerFile(prefix + file.getName(), "Support File", HTMLLinkChecker.determineType(file.getName()), true);
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) CSFile(org.hl7.fhir.utilities.CSFile) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile)

Example 19 with CSFile

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

the class ProfileUtilitiesTests method compareXml.

private void compareXml(StructureDefinition base, StructureDefinition focus) throws FileNotFoundException, IOException {
    base.setText(null);
    focus.setText(null);
    base.setDifferential(null);
    // focus.setDifferential(null);
    String f1 = Utilities.path("c:", "temp", "base.xml");
    String f2 = Utilities.path("c:", "temp", "derived.xml");
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(f1), base);
    ;
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(f2), focus);
    ;
    String diff = Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge", "WinMergeU.exe");
    List<String> command = new ArrayList<String>();
    command.add("\"" + diff + "\" \"" + f1 + "\" \"" + f2 + "\"");
    ProcessBuilder builder = new ProcessBuilder(command);
    builder.directory(new CSFile(Utilities.path("[tmp]")));
    builder.start();
}
Also used : XmlParser(org.hl7.fhir.dstu2.formats.XmlParser) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) CSFile(org.hl7.fhir.utilities.CSFile)

Example 20 with CSFile

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

the class ToolsHelper method executeRoundTrip.

public void executeRoundTrip(String[] args) throws IOException, FHIRException {
    FileInputStream in;
    File source = new CSFile(args[1]);
    File dest = new CSFile(args[2]);
    if (args.length >= 4) {
        Utilities.copyFile(args[1], args[3]);
    }
    if (!source.exists())
        throw new FHIRException("Source File \"" + source.getAbsolutePath() + "\" not found");
    in = new CSFileInputStream(source);
    XmlParser p = new XmlParser();
    JsonParser parser = new JsonParser();
    JsonParser pj = parser;
    Resource rf = p.parse(in);
    ByteArrayOutputStream json = new ByteArrayOutputStream();
    parser.setOutputStyle(OutputStyle.PRETTY);
    parser.compose(json, rf);
    json.close();
    TextFile.stringToFile(new String(json.toByteArray()), Utilities.changeFileExt(dest.getAbsolutePath(), ".json"));
    rf = pj.parse(new ByteArrayInputStream(json.toByteArray()));
    FileOutputStream s = new FileOutputStream(dest);
    new XmlParser().compose(s, rf, true);
    s.close();
}
Also used : XmlParser(org.hl7.fhir.dstu2.formats.XmlParser) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) Resource(org.hl7.fhir.dstu2.model.Resource) CSFile(org.hl7.fhir.utilities.CSFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CSFile(org.hl7.fhir.utilities.CSFile) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileInputStream(java.io.FileInputStream) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) JsonParser(org.hl7.fhir.dstu2.formats.JsonParser)

Aggregations

CSFile (org.hl7.fhir.utilities.CSFile)86 File (java.io.File)45 TextFile (org.hl7.fhir.utilities.TextFile)42 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)39 FHIRException (org.hl7.fhir.exceptions.FHIRException)37 FileOutputStream (java.io.FileOutputStream)36 ArrayList (java.util.ArrayList)29 FileInputStream (java.io.FileInputStream)27 XmlParser (org.hl7.fhir.r5.formats.XmlParser)21 IOException (java.io.IOException)16 IniFile (org.hl7.fhir.utilities.IniFile)16 JsonParser (org.hl7.fhir.r5.formats.JsonParser)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 FileNotFoundException (java.io.FileNotFoundException)10 DocumentBuilder (javax.xml.parsers.DocumentBuilder)9 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)9 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)9 Document (org.w3c.dom.Document)9 ByteArrayInputStream (java.io.ByteArrayInputStream)7 NotImplementedException (org.apache.commons.lang3.NotImplementedException)7