0

I am using the Sling MimeTypeService in order to get an appropriate extension for a given file & trying to override a default extension with my own.

E.g. if I had a method:

@Reference
MimeTypeService mimeTypeService;

public void getPlainTextAsDiff() {
    mimeTypeService.registerMimeType("text/plain", ".diff");
    mimeTypeService.getExtension("text/plain"); //returns ".txt"        
}

This returns ".txt" rather than ".diff", ignoring the first line of the method. This also seems to be inline with the documentation:

A MIME type may be mapped to multiple extensions (e.g. text/plain to txt, log, ...). This method is expected to returned one of those extensions. It is up to the implementation to select an appropriate extension if multiple mappings exist for a single MIME type.

[My emphasis]

I'm wondering if it's possible to circumvent this somehow, e.g. deregistering a mime-type or ranking those available, so that in the case above "diff" would guaranteed to be returned?

Community
  • 1
  • 1
anotherdave
  • 6,656
  • 4
  • 34
  • 65

1 Answers1

1

You can extend mime type mappings by providing MimeTypeProvider services, but looking at the MimeTypeServiceImpl code it looks like those are not sorted by service ranking. If I'm correct, you won't have a way to prioritize you MimeTypeProviders. You might want to experiment with this and submit an enhancement request or patch.

Bertrand Delacretaz
  • 6,100
  • 19
  • 24