Skip to content

Commit

Permalink
Update IExtraMetadataWriter.setExtraMetadata(...) to accept an Object
Browse files Browse the repository at this point in the history
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 ome#4169.
  • Loading branch information
melissalinkert committed Sep 25, 2024
1 parent 800950a commit 1b27afa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
27 changes: 18 additions & 9 deletions components/formats-bsd/src/loci/formats/out/DicomWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

0 comments on commit 1b27afa

Please sign in to comment.