Beispiel #1
0
 @Override
 public void compose(Element e, OutputStream stream, OutputStyle style, String base)
     throws Exception {
   this.base = base;
   OutputStreamWriter osw = new OutputStreamWriter(stream, "UTF-8");
   if (style == OutputStyle.CANONICAL) json = new JsonCreatorCanonical(osw);
   else json = new JsonCreatorGson(osw);
   json.setIndent(style == OutputStyle.PRETTY ? "  " : "");
   json.beginObject();
   prop("@type", "fhir:" + e.getType());
   prop("@context", jsonLDBase + "fhir.jsonld");
   prop("role", "fhir:treeRoot");
   String id = e.getChildValue("id");
   if (base != null && id != null) {
     if (base.endsWith("#")) prop("@id", base + e.getType() + "-" + id + ">");
     else prop("@id", Utilities.pathReverse(base, e.getType(), id));
   }
   Set<String> done = new HashSet<String>();
   for (Element child : e.getChildren()) {
     compose(e.getName(), e, done, child);
   }
   json.endObject();
   json.finish();
   osw.flush();
 }
Beispiel #2
0
 private void decorateReference(Element element) throws IOException {
   String ref = element.getChildValue("reference");
   if (ref != null && (ref.startsWith("http://") || ref.startsWith("https://"))) {
     json.name("link");
     json.value(ref);
   } else if (base != null && ref != null && ref.contains("/")) {
     json.name("link");
     json.value(Utilities.pathReverse(base, ref));
   }
 }