From df8682428adec23e0ffca8d8bf91c6da6ad51863 Mon Sep 17 00:00:00 2001 From: patrick-werner Date: Fri, 13 Mar 2020 08:49:05 +0100 Subject: [PATCH 1/2] readding all the i18n work --- .../src/main/resources/Messages.properties | 0 .../src/main/resources/Messages_de.properties | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {org.hl7.fhir.validation => org.hl7.fhir.utilities}/src/main/resources/Messages.properties (100%) rename {org.hl7.fhir.validation => org.hl7.fhir.utilities}/src/main/resources/Messages_de.properties (100%) diff --git a/org.hl7.fhir.validation/src/main/resources/Messages.properties b/org.hl7.fhir.utilities/src/main/resources/Messages.properties similarity index 100% rename from org.hl7.fhir.validation/src/main/resources/Messages.properties rename to org.hl7.fhir.utilities/src/main/resources/Messages.properties diff --git a/org.hl7.fhir.validation/src/main/resources/Messages_de.properties b/org.hl7.fhir.utilities/src/main/resources/Messages_de.properties similarity index 100% rename from org.hl7.fhir.validation/src/main/resources/Messages_de.properties rename to org.hl7.fhir.utilities/src/main/resources/Messages_de.properties From 109b80ed6f8556a5d18944c9de9269f377f18ed6 Mon Sep 17 00:00:00 2001 From: patrick-werner Date: Fri, 13 Mar 2020 09:53:59 +0100 Subject: [PATCH 2/2] start movin i18n code Contexts -> utilities --- .../fhir/r4/context/BaseWorkerContext.java | 34 -------------- .../fhir/r5/conformance/ProfileUtilities.java | 4 +- .../fhir/r5/context/BaseWorkerContext.java | 43 ++---------------- .../fhir/r5/context/SimpleWorkerContext.java | 10 +---- .../hl7/fhir/r5/elementmodel/JsonParser.java | 3 +- .../hl7/fhir/r5/elementmodel/ParserBase.java | 2 +- .../fhir/r5/elementmodel/TurtleParser.java | 2 +- .../hl7/fhir/r5/elementmodel/XmlParser.java | 3 +- .../terminologies/ValueSetCheckerSimple.java | 3 +- .../org/hl7/fhir/utilities/i18n/I18nBase.java | 44 +++++++++++++++++++ .../utilities/{ => i18n}/I18nConstants.java | 2 +- .../instance/InstanceValidator.java | 2 +- 12 files changed, 56 insertions(+), 96 deletions(-) create mode 100644 org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/i18n/I18nBase.java rename org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/{ => i18n}/I18nConstants.java (99%) diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/context/BaseWorkerContext.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/context/BaseWorkerContext.java index 62d11f7cf..7e0d83f98 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/context/BaseWorkerContext.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/context/BaseWorkerContext.java @@ -1179,38 +1179,4 @@ public abstract class BaseWorkerContext implements IWorkerContext { return corePath+"snomed.html"; return null; } - - @Override - public Locale getLocale() { - if (Objects.nonNull(locale)){ - return locale; - } else { - return Locale.US; - } - } - - @Override - public void setLocale(Locale locale) { - this.locale = locale; - setValidationMessageLanguage(getLocale()); - } - - @Override - public String formatMessage(String theMessage, Object... theMessageArguments) { - String message = theMessage; - if (Objects.nonNull(i18Nmessages) && i18Nmessages.containsKey(theMessage)) { - if (Objects.nonNull(theMessageArguments) && theMessageArguments.length > 0) { - message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments); - } else { - message = i18Nmessages.getString(theMessage); - } - } - return message; - } - - @Override - public void setValidationMessageLanguage(Locale locale) { - i18Nmessages = ResourceBundle.getBundle("Messages", locale ); - } - } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java index 10f17881b..238a8a258 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java @@ -31,7 +31,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.ResourceBundle; import java.util.Set; import org.apache.commons.lang3.StringUtils; @@ -95,7 +94,7 @@ import org.hl7.fhir.r5.utils.TranslatingUtilities; import org.hl7.fhir.r5.utils.formats.CSVWriter; import org.hl7.fhir.r5.utils.formats.XLSXWriter; import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; -import org.hl7.fhir.utilities.I18nConstants; +import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.validation.ValidationOptions; @@ -266,7 +265,6 @@ public class ProfileUtilities extends TranslatingUtilities { private boolean newSlicingProcessing; private String defWebRoot; private boolean autoFixSliceNames; - private ResourceBundle i18nMessages; public ProfileUtilities(IWorkerContext context, List messages, ProfileKnowledgeProvider pkp) { super(); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java index d283ce277..19166f4d5 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java @@ -22,7 +22,6 @@ package org.hl7.fhir.r5.context; import java.io.FileNotFoundException; import java.io.IOException; -import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -32,7 +31,6 @@ import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Objects; import java.util.ResourceBundle; import java.util.Set; @@ -83,7 +81,8 @@ import org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome; import org.hl7.fhir.r5.terminologies.ValueSetExpanderSimple; import org.hl7.fhir.r5.utils.ToolingExtensions; import org.hl7.fhir.r5.utils.client.ToolingClientLogger; -import org.hl7.fhir.utilities.I18nConstants; +import org.hl7.fhir.utilities.i18n.I18nBase; +import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.OIDUtils; import org.hl7.fhir.utilities.TranslationServices; import org.hl7.fhir.utilities.Utilities; @@ -95,10 +94,7 @@ import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType; import com.google.gson.JsonObject; -public abstract class BaseWorkerContext implements IWorkerContext { - - private ResourceBundle i18Nmessages; - private Locale locale; +public abstract class BaseWorkerContext extends I18nBase implements IWorkerContext{ public class MetadataResourceVersionComparator implements Comparator { @@ -1282,37 +1278,4 @@ public abstract class BaseWorkerContext implements IWorkerContext { public Map getBinaries() { return binaries; } - - @Override - public Locale getLocale() { - if (Objects.nonNull(locale)){ - return locale; - } else { - return Locale.US; - } - } - - @Override - public void setLocale(Locale locale) { - this.locale = locale; - setValidationMessageLanguage(getLocale()); - } - - @Override - public String formatMessage(String theMessage, Object... theMessageArguments) { - String message = theMessage; - if (Objects.nonNull(i18Nmessages) && i18Nmessages.containsKey(theMessage)) { - if (Objects.nonNull(theMessageArguments) && theMessageArguments.length > 0) { - message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments); - } else { - message = i18Nmessages.getString(theMessage); - } - } - return message; - } - - @Override - public void setValidationMessageLanguage(Locale locale) { - i18Nmessages = ResourceBundle.getBundle("Messages", locale); - } } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java index 04aa00fc3..907f52d2b 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java @@ -25,14 +25,10 @@ import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.net.URISyntaxException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Locale; @@ -48,16 +44,13 @@ import org.hl7.fhir.exceptions.FHIRFormatError; import org.hl7.fhir.r5.conformance.ProfileUtilities; import org.hl7.fhir.r5.conformance.ProfileUtilities.ProfileKnowledgeProvider; import org.hl7.fhir.r5.context.IWorkerContext.ILoggingService.LogCategory; -import org.hl7.fhir.r5.context.SimpleWorkerContext.ILoadFilter; import org.hl7.fhir.r5.formats.IParser; import org.hl7.fhir.r5.formats.JsonParser; import org.hl7.fhir.r5.formats.ParserType; import org.hl7.fhir.r5.formats.XmlParser; -import org.hl7.fhir.r5.formats.IParser.OutputStyle; import org.hl7.fhir.r5.model.Bundle; import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent; import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent; -import org.hl7.fhir.r5.model.ImplementationGuide; import org.hl7.fhir.r5.model.CanonicalResource; import org.hl7.fhir.r5.model.Questionnaire; import org.hl7.fhir.r5.model.Resource; @@ -73,7 +66,7 @@ import org.hl7.fhir.r5.utils.INarrativeGenerator; import org.hl7.fhir.r5.utils.IResourceValidator; import org.hl7.fhir.r5.utils.NarrativeGenerator; import org.hl7.fhir.utilities.CSFileInputStream; -import org.hl7.fhir.utilities.I18nConstants; +import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.cache.NpmPackage; @@ -81,7 +74,6 @@ import org.hl7.fhir.utilities.validation.ValidationMessage; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType; import org.hl7.fhir.utilities.validation.ValidationMessage.Source; -import ca.uhn.fhir.fluentpath.IFluentPath; import ca.uhn.fhir.parser.DataFormatException; /* diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java index 68e1441bd..a8fdb0d6f 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java @@ -26,7 +26,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.math.BigDecimal; -import java.util.HashMap; import java.util.HashSet; import java.util.IdentityHashMap; import java.util.List; @@ -45,7 +44,7 @@ import org.hl7.fhir.r5.formats.JsonCreatorCanonical; import org.hl7.fhir.r5.formats.JsonCreatorGson; import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent; import org.hl7.fhir.r5.model.StructureDefinition; -import org.hl7.fhir.utilities.I18nConstants; +import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.json.JsonTrackingParser; diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ParserBase.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ParserBase.java index fe3d4a53d..03b4ce1e7 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ParserBase.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ParserBase.java @@ -35,7 +35,7 @@ import org.hl7.fhir.r5.formats.IParser.OutputStyle; import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule; import org.hl7.fhir.r5.utils.ToolingExtensions; -import org.hl7.fhir.utilities.I18nConstants; +import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.validation.ValidationMessage; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity; diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/TurtleParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/TurtleParser.java index ea8f08214..13758469e 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/TurtleParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/TurtleParser.java @@ -46,7 +46,7 @@ import org.hl7.fhir.r5.utils.formats.Turtle.TTLList; import org.hl7.fhir.r5.utils.formats.Turtle.TTLLiteral; import org.hl7.fhir.r5.utils.formats.Turtle.TTLObject; import org.hl7.fhir.r5.utils.formats.Turtle.TTLURL; -import org.hl7.fhir.utilities.I18nConstants; +import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity; diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java index c8bf87a03..b72342b1b 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java @@ -40,7 +40,6 @@ import javax.xml.transform.sax.SAXSource; import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRFormatError; -import org.hl7.fhir.r5.elementmodel.Element; import org.hl7.fhir.r5.conformance.ProfileUtilities; import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.elementmodel.Element.SpecialElement; @@ -54,7 +53,7 @@ import org.hl7.fhir.r5.utils.ToolingExtensions; import org.hl7.fhir.r5.utils.formats.XmlLocationAnnotator; import org.hl7.fhir.r5.utils.formats.XmlLocationData; import org.hl7.fhir.utilities.ElementDecoration; -import org.hl7.fhir.utilities.I18nConstants; +import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType; diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ValueSetCheckerSimple.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ValueSetCheckerSimple.java index ef7cbc985..60a2e3fe9 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ValueSetCheckerSimple.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ValueSetCheckerSimple.java @@ -22,7 +22,6 @@ package org.hl7.fhir.r5.terminologies; import java.util.ArrayList; -import java.util.EnumSet; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -46,7 +45,7 @@ import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent; import org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent; import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent; import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; -import org.hl7.fhir.utilities.I18nConstants; +import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.validation.ValidationOptions; import org.hl7.fhir.utilities.validation.ValidationOptions.ValueSetMode; diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/i18n/I18nBase.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/i18n/I18nBase.java new file mode 100644 index 000000000..26911b549 --- /dev/null +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/i18n/I18nBase.java @@ -0,0 +1,44 @@ +package org.hl7.fhir.utilities.i18n; + +import java.text.MessageFormat; +import java.util.Locale; +import java.util.Objects; +import java.util.ResourceBundle; + +public abstract class I18nBase { + + + private Locale locale; + private ResourceBundle i18Nmessages; + + public Locale getLocale() { + if (Objects.nonNull(locale)){ + return locale; + } else { + return Locale.US; + } + } + + public void setLocale(Locale locale) { + this.locale = locale; + setValidationMessageLanguage(getLocale()); + } + + public String formatMessage(String theMessage, Object... theMessageArguments) { + String message = theMessage; + if (Objects.nonNull(i18Nmessages) && i18Nmessages.containsKey(theMessage)) { + if (Objects.nonNull(theMessageArguments) && theMessageArguments.length > 0) { + message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments); + } else { + message = i18Nmessages.getString(theMessage); + } + } + return message; + } + + public void setValidationMessageLanguage(Locale locale) { + i18Nmessages = ResourceBundle.getBundle("Messages", locale); + } +} + + diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/I18nConstants.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/i18n/I18nConstants.java similarity index 99% rename from org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/I18nConstants.java rename to org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/i18n/I18nConstants.java index a7c50cfeb..fee1ac15a 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/I18nConstants.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/i18n/I18nConstants.java @@ -1,4 +1,4 @@ -package org.hl7.fhir.utilities; +package org.hl7.fhir.utilities.i18n; import java.text.MessageFormat; import java.util.ResourceBundle; diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java index 3d45abf61..f8d598b82 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java @@ -126,7 +126,7 @@ import org.hl7.fhir.r5.utils.FHIRPathEngine; import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext; import org.hl7.fhir.r5.utils.IResourceValidator; import org.hl7.fhir.r5.utils.ToolingExtensions; -import org.hl7.fhir.utilities.I18nConstants; +import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.validation.BaseValidator; import org.hl7.fhir.validation.instance.EnableWhenEvaluator.QStack; import org.hl7.fhir.validation.XVerExtensionManager;