001package org.hl7.fhir.r5.renderers;
002
003import org.hl7.fhir.r5.context.IWorkerContext;
004import org.hl7.fhir.r5.renderers.utils.RenderingContext;
005import org.hl7.fhir.r5.renderers.utils.RenderingContext.GenerationRules;
006import org.hl7.fhir.r5.renderers.utils.RenderingContext.ResourceRendererMode;
007import org.hl7.fhir.r5.utils.TranslatingUtilities;
008import org.hl7.fhir.utilities.MarkDownProcessor;
009import org.hl7.fhir.utilities.MarkDownProcessor.Dialect;
010import org.hl7.fhir.utilities.validation.ValidationOptions;
011
012/**
013 * Rendering framework:
014 * 
015 *   * boolean render(DomainResource) : produce an HTML representation suitable for runtime / documentation, and insert it into the resource. Return true of any extensions encountered
016 *   * boolean render(XhtmlNode, Resource: produce an HTML representation, and fill out the provided node with it. Return true of any extensions encountered
017 *   * XhtmlNode build(DomainResource): same as render(DomainResource) but also return the XHtmlNode 
018 *   
019 *   * String display(Base) : produce a plan text concise representation that serves to describe the resource
020 *   * void display(XhtmlNode, Base) : produce a plan text concise representation that serves to describe the resource
021 *   
022 *   * void describe(XhtmlNode, Resource) : produce a short summary of the resource with key details presented (potentially more verbose than display, but still suitable for a single line)  
023 *   
024 * if not specific code for rendering a resource has been provided, and there's no liquid script to guide it, a generic rendering based onthe profile will be performed
025 *   
026 * @author graha
027 *
028 */
029public class Renderer extends TranslatingUtilities {
030
031  protected RenderingContext context;
032  
033  public Renderer(RenderingContext context) {
034    this.context = context;
035  }
036
037  public Renderer(IWorkerContext worker) {
038    this.context = new RenderingContext(worker, new MarkDownProcessor(Dialect.COMMON_MARK), ValidationOptions.defaults(), "http://hl7.org/fhir/R5", "", null, ResourceRendererMode.END_USER, GenerationRules.IG_PUBLISHER);
039  }
040
041
042  protected static final String RENDER_BUNDLE_HEADER_ROOT = "RENDER_BUNDLE_HEADER_ROOT";
043  protected static final String RENDER_BUNDLE_HEADER_ENTRY = "RENDER_BUNDLE_HEADER_ENTRY";
044  protected static final String RENDER_BUNDLE_HEADER_ENTRY_URL = "RENDER_BUNDLE_HEADER_ENTRY_URL";
045  protected static final String RENDER_BUNDLE_RESOURCE = "RENDER_BUNDLE_RESOURCE";
046  protected static final String RENDER_BUNDLE_SEARCH = "RENDER_BUNDLE_SEARCH";
047  protected static final String RENDER_BUNDLE_SEARCH_MODE = "RENDER_BUNDLE_SEARCH_MODE"; 
048  protected static final String RENDER_BUNDLE_SEARCH_SCORE = "RENDER_BUNDLE_SEARCH_SCORE";
049  protected static final String RENDER_BUNDLE_RESPONSE = "RENDER_BUNDLE_RESPONSE";
050  protected static final String RENDER_BUNDLE_LOCATION = "RENDER_BUNDLE_LOCATION";
051  protected static final String RENDER_BUNDLE_ETAG = "RENDER_BUNDLE_ETAG";
052  protected static final String RENDER_BUNDLE_LAST_MOD = "RENDER_BUNDLE_LAST_MOD";
053  protected static final String RENDER_BUNDLE_REQUEST = "RENDER_BUNDLE_REQUEST";
054  protected static final String RENDER_BUNDLE_IF_NON_MATCH = "RENDER_BUNDLE_IF_NON_MATCH";
055  protected static final String RENDER_BUNDLE_IF_MOD = "RENDER_BUNDLE_IF_MOD";
056  protected static final String RENDER_BUNDLE_IF_MATCH = "RENDER_BUNDLE_IF_MATCH";
057  protected static final String RENDER_BUNDLE_IF_NONE = "RENDER_BUNDLE_IF_NONE";
058  protected static final String RENDER_BUNDLE_DOCUMENT_CONTENT = "RENDER_BUNDLE_DOCUMENT_CONTENT";
059  protected static final String RENDER_BUNDLE_HEADER_DOC_ENTRY_URD = "RENDER_BUNDLE_HEADER_DOC_ENTRY_URD";
060  protected static final String RENDER_BUNDLE_HEADER_DOC_ENTRY_U = "RENDER_BUNDLE_HEADER_DOC_ENTRY_U";
061  protected static final String RENDER_BUNDLE_HEADER_DOC_ENTRY_RD = "RENDER_BUNDLE_HEADER_DOC_ENTRY_RD";
062
063  /** the plan here is to make this have it's own implementation of messages, rather than using the 
064   * validator messages, for better alignment with publisher I18n strategy
065   * 
066   * @param theMessage
067   * @param theMessageArguments
068   * @return
069   */
070  protected String formatMessage(String theMessage, Object... theMessageArguments) {
071    return context.getWorker().formatMessage(theMessage, theMessageArguments);
072  }
073
074}