001package org.hl7.fhir.dstu3.elementmodel; 002 003import java.io.InputStream; 004import java.io.OutputStream; 005 006import org.hl7.fhir.dstu3.formats.IParser.OutputStyle; 007import org.hl7.fhir.dstu3.context.IWorkerContext; 008 009public class Manager { 010 011 public enum FhirFormat { XML, JSON, JSONLD, TURTLE ; 012 013 public String getExtension() { 014 switch (this) { 015 case JSON: 016 return "json"; 017 case JSONLD: 018 return "ld.json"; 019 case TURTLE: 020 return "ttl"; 021 case XML: 022 return "xml"; 023 } 024 return null; 025 } 026 } 027 028 public static Element parse(IWorkerContext context, InputStream source, FhirFormat inputFormat) throws Exception { 029 return makeParser(context, inputFormat).parse(source); 030 } 031 032 public static void compose(IWorkerContext context, Element e, OutputStream destination, FhirFormat outputFormat, OutputStyle style, String base) throws Exception { 033 makeParser(context, outputFormat).compose(e, destination, style, base); 034 } 035 036 public static ParserBase makeParser(IWorkerContext context, FhirFormat format) { 037 switch (format) { 038 case JSON : return new JsonParser(context); 039 case JSONLD : return new JsonLDParser(context); 040 case XML : return new XmlParser(context); 041 case TURTLE : return new TurtleParser(context); 042 } 043 return null; 044 } 045 046}