use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class ToolsHelper method generateSnapshots.
private void generateSnapshots(String[] args) throws IOException, FHIRException {
if (args.length == 1) {
System.out.println("tools.jar snapshot-maker [source] -defn [definitions]");
System.out.println("");
System.out.println("Generates a snapshot from a differential. The nominated profile must have a single struture that has a differential");
System.out.println("");
System.out.println("source - the profile to generate the snapshot for. Maybe a file name, or a URL reference to a server running FHIR RESTful API");
System.out.println("definitions - filename for local copy of the validation.zip file");
}
String address = args[1];
String definitions = args[3];
SimpleWorkerContext context = SimpleWorkerContext.fromDefinitions(getDefinitions(definitions));
// } else {
throw new NotImplementedException("generating snapshots not done yet (address = " + address + ")");
// }
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class ToolsHelper method processExamples.
public void processExamples(String rootDir, Collection<String> list) throws FHIRException {
for (String n : list) {
try {
String filename = rootDir + n + ".xml";
// 1. produce canonical XML
CSFileInputStream source = new CSFileInputStream(filename);
FileOutputStream dest = new FileOutputStream(Utilities.changeFileExt(filename, ".canonical.xml"));
XmlParser p = new XmlParser();
Resource r = p.parse(source);
XmlParser cxml = new XmlParser();
cxml.setOutputStyle(OutputStyle.CANONICAL);
cxml.compose(dest, r);
// 2. produce JSON
source = new CSFileInputStream(filename);
dest = new FileOutputStream(Utilities.changeFileExt(filename, ".json"));
r = p.parse(source);
JsonParser json = new JsonParser();
json.setOutputStyle(OutputStyle.PRETTY);
json.compose(dest, r);
json = new JsonParser();
json.setOutputStyle(OutputStyle.CANONICAL);
dest = new FileOutputStream(Utilities.changeFileExt(filename, ".canonical.json"));
json.compose(dest, r);
} catch (Exception e) {
e.printStackTrace();
throw new FHIRException("Error Processing " + n + ".xml: " + e.getMessage(), e);
}
}
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source 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();
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class ToolsHelper method executeJson.
public String executeJson(String[] args) throws IOException, FHIRException {
FileInputStream in;
File source = new CSFile(args[1]);
File dest = new CSFile(args[2]);
File destc = new CSFile(Utilities.changeFileExt(args[2], ".canonical.json"));
File destt = new CSFile(args[2] + ".tmp");
if (!source.exists())
throw new FHIRException("Source File \"" + source.getAbsolutePath() + "\" not found");
in = new CSFileInputStream(source);
XmlParser p = new XmlParser();
Resource rf = p.parse(in);
JsonParser json = new JsonParser();
json.setOutputStyle(OutputStyle.PRETTY);
FileOutputStream s = new FileOutputStream(dest);
json.compose(s, rf);
s.close();
json.setOutputStyle(OutputStyle.CANONICAL);
s = new FileOutputStream(destc);
json.compose(s, rf);
s.close();
json.setSuppressXhtml("Snipped for Brevity");
json.setOutputStyle(OutputStyle.PRETTY);
s = new FileOutputStream(destt);
json.compose(s, rf);
s.close();
return TextFile.fileToString(destt.getAbsolutePath());
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class ToolsHelper method executeCanonicalXml.
public void executeCanonicalXml(String[] args) throws FHIRException, IOException {
FileInputStream in;
File source = new CSFile(args[1]);
File dest = new CSFile(args[2]);
if (!source.exists())
throw new FHIRException("Source File \"" + source.getAbsolutePath() + "\" not found");
in = new CSFileInputStream(source);
XmlParser p = new XmlParser();
Resource rf = p.parse(in);
XmlParser cxml = new XmlParser();
cxml.setOutputStyle(OutputStyle.NORMAL);
cxml.compose(new FileOutputStream(dest), rf);
}
Aggregations