From e4b503751cefdaedcc1d3f76606afdc76d4b23e0 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 29 Oct 2021 09:20:23 +1100 Subject: [PATCH] improved validation of UUIDs --- .../org/hl7/fhir/utilities/ZipGenerator.java | 30 +++++++++++-------- .../fhir/utilities/i18n/I18nConstants.java | 2 +- .../xhtml/HierarchicalTableGenerator.java | 4 +-- .../src/main/resources/Messages.properties | 2 +- .../instance/InstanceValidator.java | 2 +- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/ZipGenerator.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/ZipGenerator.java index e5a8a25eb..ce63c59be 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/ZipGenerator.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/ZipGenerator.java @@ -121,19 +121,23 @@ public class ZipGenerator { File f = new CSFile(actualDir); String files[] = f.list(); - for (int i = 0; i < files.length; i++) { - if ( new CSFile(actualDir + files[i]).isFile() && ((ext == null || files[i].endsWith(ext)) && (noExt == null || !files[i].endsWith(noExt)))) { - FileInputStream fi = new FileInputStream(actualDir + files[i]); - BufferedInputStream origin = new BufferedInputStream(fi, BUFFER); - ZipEntry entry = new ZipEntry(statedDir + files[i]); - names.add(statedDir + files[i]); - out.putNextEntry(entry); - int count; - while ((count = origin.read(data, 0, BUFFER)) != -1) { - out.write(data, 0, count); - } - origin.close(); - } + if (files == null) { + System.out.println("no files found in "+f.getName()); + } else { + for (int i = 0; i < files.length; i++) { + if ( new CSFile(actualDir + files[i]).isFile() && ((ext == null || files[i].endsWith(ext)) && (noExt == null || !files[i].endsWith(noExt)))) { + FileInputStream fi = new FileInputStream(actualDir + files[i]); + BufferedInputStream origin = new BufferedInputStream(fi, BUFFER); + ZipEntry entry = new ZipEntry(statedDir + files[i]); + names.add(statedDir + files[i]); + out.putNextEntry(entry); + int count; + while ((count = origin.read(data, 0, BUFFER)) != -1) { + out.write(data, 0, count); + } + origin.close(); + } + } } } diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/i18n/I18nConstants.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/i18n/I18nConstants.java index 03e40d5c6..3edd09a85 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/i18n/I18nConstants.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/i18n/I18nConstants.java @@ -510,7 +510,7 @@ public class I18nConstants { public static final String TYPE_SPECIFIC_CHECKS_DT_CANONICAL_TYPE = "TYPE_SPECIFIC_CHECKS_DT_CANONICAL_TYPE"; public static final String TYPE_SPECIFIC_CHECKS_DT_CANONICAL_RESOLVE = "TYPE_SPECIFIC_CHECKS_DT_CANONICAL_RESOLVE"; public static final String TYPE_SPECIFIC_CHECKS_DT_UUID_STRAT = "Type_Specific_Checks_DT_UUID_Strat"; - public static final String TYPE_SPECIFIC_CHECKS_DT_UUID_VAID = "Type_Specific_Checks_DT_UUID_Vaid"; + public static final String TYPE_SPECIFIC_CHECKS_DT_UUID_VALID = "Type_Specific_Checks_DT_UUID_Valid"; public static final String UNABLE_TO_CONNECT_TO_TERMINOLOGY_SERVER = "Unable_to_connect_to_terminology_server"; public static final String UNABLE_TO_CONNECT_TO_TERMINOLOGY_SERVER_USE_PARAMETER_TX_NA_TUN_RUN_WITHOUT_USING_TERMINOLOGY_SERVICES_TO_VALIDATE_LOINC_SNOMED_ICDX_ETC_ERROR__ = "Unable_to_connect_to_terminology_server_Use_parameter_tx_na_tun_run_without_using_terminology_services_to_validate_LOINC_SNOMED_ICDX_etc_Error__"; public static final String UNABLE_TO_FIND_BASE_DEFINITION_FOR_LOGICAL_MODEL__FROM_ = "Unable_to_find_base_definition_for_logical_model__from_"; diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/HierarchicalTableGenerator.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/HierarchicalTableGenerator.java index b197b484b..4c07394f5 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/HierarchicalTableGenerator.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/HierarchicalTableGenerator.java @@ -598,7 +598,7 @@ public class HierarchicalTableGenerator extends TranslatingUtilities { TableModel model = new TableModel(id, isActive); model.setAlternating(alternating); - model.setDocoImg(prefix+"help16.png"); + model.setDocoImg(Utilities.pathURL(prefix, "help16.png")); model.setDocoRef(Utilities.pathURL(prefix, "formats.html#table")); model.getTitles().add(new Title(null, model.getDocoRef(), translate("sd.head", "Name"), translate("sd.hint", "The logical name of the element"), null, 0)); model.getTitles().add(new Title(null, model.getDocoRef(), translate("sd.head", "Flags"), translate("sd.hint", "Information about the use of the element"), null, 0)); @@ -615,7 +615,7 @@ public class HierarchicalTableGenerator extends TranslatingUtilities { TableModel model = new TableModel(id, true); model.setAlternating(true); - model.setDocoImg(prefix+"help16.png"); + model.setDocoImg(Utilities.pathURL(prefix, "help16.png")); model.setDocoRef(Utilities.pathURL(prefix, "formats.html#table")); model.getTitles().add(new Title(null, model.getDocoRef(), translate("sd.head", "Name"), translate("sd.hint", "The logical name of the element"), null, 0)); model.getTitles().add(new Title(null, model.getDocoRef(), translate("sd.head", "L Flags"), translate("sd.hint", "Information about the use of the element - Left Structure"), null, 0).setStyle("border-left: 1px grey solid")); diff --git a/org.hl7.fhir.utilities/src/main/resources/Messages.properties b/org.hl7.fhir.utilities/src/main/resources/Messages.properties index edcc34f0b..39d7fee92 100644 --- a/org.hl7.fhir.utilities/src/main/resources/Messages.properties +++ b/org.hl7.fhir.utilities/src/main/resources/Messages.properties @@ -208,7 +208,7 @@ Type_Specific_Checks_DT_URI_UUID = URI values cannot start with uuid: Type_Specific_Checks_DT_URI_WS = URI values cannot have whitespace(''{0}'') Type_Specific_Checks_DT_URL_Resolve = URL value ''{0}'' does not resolve Type_Specific_Checks_DT_UUID_Strat = UUIDs must start with urn:uuid: -Type_Specific_Checks_DT_UUID_Vaid = UUIDs must be valid +Type_Specific_Checks_DT_UUID_Valid = UUIDs must be valid (and lowercase) Validation_BUNDLE_Message = The first entry in a message must be a MessageHeader Validation_VAL_Content_Unknown = Unrecognised Content {0} Validation_VAL_NoType = Unknown type {0} 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 c289d1a66..f44803446 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 @@ -2035,7 +2035,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat } if (url != null && url.startsWith("urn:uuid:")) { - rule(errors, IssueType.INVALID, e.line(), e.col(), path, Utilities.isValidUUID(url.substring(9)), I18nConstants.TYPE_SPECIFIC_CHECKS_DT_UUID_VAID); + rule(errors, IssueType.INVALID, e.line(), e.col(), path, Utilities.isValidUUID(url.substring(9)), I18nConstants.TYPE_SPECIFIC_CHECKS_DT_UUID_VALID); } if (url != null && url.startsWith("urn:oid:")) { rule(errors, IssueType.INVALID, e.line(), e.col(), path, Utilities.isOid(url.substring(8)), I18nConstants.TYPE_SPECIFIC_CHECKS_DT_OID_VALID);