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();
}
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"));
}
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);
}
}
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();
}
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();
}
Aggregations