001package ca.uhn.fhir.narrative;
002
003/*
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2023 Smile CDR, Inc.
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import ca.uhn.fhir.narrative2.NarrativeTemplateManifest;
024import org.apache.commons.lang3.Validate;
025
026import java.util.Arrays;
027import java.util.List;
028
029public class CustomThymeleafNarrativeGenerator extends BaseThymeleafNarrativeGenerator {
030
031        private volatile List<String> myPropertyFile;
032        private volatile NarrativeTemplateManifest myManifest;
033
034        /**
035         * Constructor. If this constructor is used you must explicitly call
036         * {@link #setManifest(NarrativeTemplateManifest)} to provide a template
037         * manifest before using the generator.
038         */
039        public CustomThymeleafNarrativeGenerator() {
040                super();
041        }
042
043        /**
044                 * Create a new narrative generator
045                 *
046                 * @param theNarrativePropertyFiles The name of the property file, in one of the following formats:
047                 *                                  <ul>
048                 *                                  <li>file:/path/to/file/file.properties</li>
049                 *                                  <li>classpath:/com/package/file.properties</li>
050                 *                                  </ul>
051                 */
052        public CustomThymeleafNarrativeGenerator(String... theNarrativePropertyFiles) {
053                this();
054                setPropertyFile(theNarrativePropertyFiles);
055        }
056
057        /**
058         * Create a new narrative generator
059         *
060         * @param theNarrativePropertyFiles The name of the property file, in one of the following formats:
061         *                                  <ul>
062         *                                  <li>file:/path/to/file/file.properties</li>
063         *                                  <li>classpath:/com/package/file.properties</li>
064         *                                  </ul>
065         */
066        public CustomThymeleafNarrativeGenerator(List<String> theNarrativePropertyFiles) {
067                this(theNarrativePropertyFiles.toArray(new String[0]));
068        }
069
070        @Override
071        public NarrativeTemplateManifest getManifest() {
072                NarrativeTemplateManifest retVal = myManifest;
073                if (myManifest == null) {
074                        Validate.isTrue(myPropertyFile != null, "Neither a property file or a manifest has been provided");
075                        retVal = NarrativeTemplateManifest.forManifestFileLocation(myPropertyFile);
076                        setManifest(retVal);
077                }
078                return retVal;
079        }
080
081        public void setManifest(NarrativeTemplateManifest theManifest) {
082                myManifest = theManifest;
083        }
084
085        /**
086         * Set the property file to use
087         *
088         * @param thePropertyFile The name of the property file, in one of the following formats:
089         *                        <ul>
090         *                        <li>file:/path/to/file/file.properties</li>
091         *                        <li>classpath:/com/package/file.properties</li>
092         *                        </ul>
093         */
094        public void setPropertyFile(String... thePropertyFile) {
095                Validate.notNull(thePropertyFile, "Property file can not be null");
096                myPropertyFile = Arrays.asList(thePropertyFile);
097                myManifest = null;
098        }
099}