001package org.hl7.fhir.validation.cli.renderers;
002
003import java.io.IOException;
004
005import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
006import org.hl7.fhir.r5.formats.IParser;
007import org.hl7.fhir.r5.formats.JsonParser;
008import org.hl7.fhir.r5.formats.XmlParser;
009import org.hl7.fhir.r5.model.Bundle;
010import org.hl7.fhir.r5.model.OperationOutcome;
011
012public class NativeRenderer extends ValidationOutputRenderer {
013
014  private FhirFormat format;
015
016  public NativeRenderer(FhirFormat format) {
017    this.format = format;
018  }
019
020  public boolean handlesBundleDirectly() {
021    return true;
022  }
023
024  @Override
025  public void render(OperationOutcome op) throws IOException {
026    IParser x;
027    if (format == FhirFormat.JSON) {
028      x = new JsonParser();
029    } else {
030      x = new XmlParser();
031    }
032    x.setOutputStyle(IParser.OutputStyle.PRETTY);
033    x.compose(dst, op);
034  }
035
036  @Override
037  public void render(Bundle bundle) throws IOException {
038    IParser x;
039    if (format == FhirFormat.JSON) {
040      x = new JsonParser();
041    } else {
042      x = new XmlParser();
043    }
044    x.setOutputStyle(IParser.OutputStyle.PRETTY);
045    x.compose(dst, bundle);
046  }
047  
048}