Search in sources :

Example 86 with CSFile

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

the class TestingUtilities method checkXMLIsSame.

public static String checkXMLIsSame(String f1, String f2) throws Exception {
    String result = compareXml(f1, f2);
    if (result != null && SHOW_DIFF) {
        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();
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) CSFile(org.hl7.fhir.utilities.CSFile)

Example 87 with CSFile

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

the class TestingUtilities method checkJsonIsSame.

public static String checkJsonIsSame(String f1, String f2) throws JsonSyntaxException, FileNotFoundException, IOException {
    String result = compareJson(f1, f2);
    if (result != null && SHOW_DIFF) {
        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();
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) CSFile(org.hl7.fhir.utilities.CSFile)

Example 88 with CSFile

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

the class ToolsHelper method executeFragments.

public void executeFragments(String[] args) throws IOException {
    try {
        File source = new CSFile(args[1]);
        if (!source.exists())
            throw new FHIRException("Source File \"" + source.getAbsolutePath() + "\" not found");
        XmlPullParser xpp = loadXml(new FileInputStream(source));
        nextNoWhitespace(xpp);
        if (!xpp.getName().equals("tests"))
            throw new FHIRFormatError("Unable to parse file - starts with " + xpp.getName());
        xpp.next();
        nextNoWhitespace(xpp);
        StringBuilder s = new StringBuilder();
        s.append("<results>\r\n");
        int fail = 0;
        while (xpp.getEventType() == XmlPullParser.START_TAG && xpp.getName().equals("test")) {
            String id = xpp.getAttributeValue(null, "id");
            String type = xpp.getAttributeValue(null, "type");
            // test
            xpp.next();
            nextNoWhitespace(xpp);
            // pre
            xpp.next();
            nextNoWhitespace(xpp);
            XmlParser p = new XmlParser();
            try {
                p.parseFragment(xpp, type);
                s.append("<result id=\"" + id + "\" outcome=\"ok\"/>\r\n");
                nextNoWhitespace(xpp);
            } catch (Exception e) {
                s.append("<result id=\"" + id + "\" outcome=\"error\" msg=\"" + Utilities.escapeXml(e.getMessage()) + "\"/>\r\n");
                fail++;
            }
            while (xpp.getEventType() != XmlPullParser.END_TAG || !xpp.getName().equals("pre")) xpp.next();
            xpp.next();
            nextNoWhitespace(xpp);
            xpp.next();
            nextNoWhitespace(xpp);
        }
        s.append("</results>\r\n");
        TextFile.stringToFile(s.toString(), args[2]);
    } catch (Exception e) {
        e.printStackTrace();
        TextFile.stringToFile(e.getMessage(), args[2]);
    }
}
Also used : XmlParser(org.hl7.fhir.dstu2.formats.XmlParser) XmlPullParser(org.xmlpull.v1.XmlPullParser) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) CSFile(org.hl7.fhir.utilities.CSFile) 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) NotImplementedException(org.apache.commons.lang3.NotImplementedException) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

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