From 1b27afacb6e7358ec7e71998efe77b1705b1baae Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Wed, 25 Sep 2024 16:01:39 -0500 Subject: [PATCH] Update IExtraMetadataWriter.setExtraMetadata(...) to accept an Object If an ITagProvider is passed to this method when called on DicomWriter, the ITagProvider is directly added to the tag provider list. If a String is passed instead, then it is assumed to be a path to a file that can be parsed by DicomJSONProvider (as before). See #4169. --- .../src/loci/formats/out/DicomWriter.java | 27 ++++++++++++------- .../formats/out/IExtraMetadataWriter.java | 2 +- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/components/formats-bsd/src/loci/formats/out/DicomWriter.java b/components/formats-bsd/src/loci/formats/out/DicomWriter.java index 027d7b27bb3..ff8703b7103 100644 --- a/components/formats-bsd/src/loci/formats/out/DicomWriter.java +++ b/components/formats-bsd/src/loci/formats/out/DicomWriter.java @@ -146,8 +146,14 @@ public DicomWriter() { // -- IExtraMetadataWriter API methods -- + /** + * Add a tag provider. + * + * tagSource is expected to be either an ITagProvider, + * or a String file name that can be read by DicomJSONProvider. + */ @Override - public void setExtraMetadata(String tagSource) { + public void setExtraMetadata(Object tagSource) { FormatTools.assertId(currentId, false, 1); StopWatch metadataWatch = stopWatch(); @@ -157,20 +163,23 @@ public void setExtraMetadata(String tagSource) { if (tagSource != null) { ITagProvider provider = null; - if (checkSuffix(tagSource, "json")) { + if (tagSource instanceof ITagProvider) { + provider = (ITagProvider) tagSource; + } + else if (tagSource instanceof String && checkSuffix((String) tagSource, "json")) { provider = new DicomJSONProvider(); + try { + provider.readTagSource((String) tagSource); + } + catch (IOException e) { + LOGGER.error("Could not parse extra metadata: " + tagSource, e); + } } else { throw new IllegalArgumentException("Unknown tag format: " + tagSource); } - try { - provider.readTagSource(tagSource); - tagProviders.add(provider); - } - catch (IOException e) { - LOGGER.error("Could not parse extra metadata: " + tagSource, e); - } + tagProviders.add(provider); } metadataWatch.stop("parsed extra metadata from " + tagSource); } diff --git a/components/formats-bsd/src/loci/formats/out/IExtraMetadataWriter.java b/components/formats-bsd/src/loci/formats/out/IExtraMetadataWriter.java index 7cc1da2170d..5bf392bde46 100644 --- a/components/formats-bsd/src/loci/formats/out/IExtraMetadataWriter.java +++ b/components/formats-bsd/src/loci/formats/out/IExtraMetadataWriter.java @@ -48,6 +48,6 @@ public interface IExtraMetadataWriter { * * All calls to this method must occur before setId is called. */ - void setExtraMetadata(String metadataSource); + void setExtraMetadata(Object metadataSource); }