[7.x.x] New approach to resolving Internet Media Type #148
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Elemental previously inherited the Internet Media Type handling of eXist-db.
eXist-db looks up Internet Media Types and associated file extensions from a static bespoke config file named mime-types.xml. Unfortunately that file is hard baked into the Java classpath and resides witiin the
exist-core-6.3.0.jar; this means that users could not add new Media Types of reconfigure existing Media Types.In this PR we now take a completely new approach to resolving Media Types in Elemental. The key takeaways from this new approach are:
The
mime-types.xmlfile and associated Java classesorg.exist.util.MimeTypeandorg.exist.util.MimeTableare now deprecated. They are unused in Elemental, and will be removed at a suitable point in the future. They are retained for the time being to ensure compatibility with any pre-compiled eXist-db Java extensions that users may also wish to use on Elemental.Elemental now uses the standard Jakarta Activation Framework as part of its implementation to support Internet Media Types.
Elemental now loads Media Type information from two files:
jakarta.mime.typesormime.types.As a default Elemental ships with the latest Media Type database file from the Apache HTTP project which contains almost 1000 Media Type definitions. See: https://github.com/evolvedbinary/apache-httpd-mime-types
media-type-mappings.xml.This file informs elemental as to which storage method for a Media Type. At present just XML and Binary storage methods are exposed; support for HTML5, JSON, Markdown, and Text will also be exposed in future.
As a default Elemental ships with a default Mappings database that maps all XML Media Types to the XML storage method, and all other Media Types to the Binary storage method.
Elemental provides a hierarchical approach to locating and using both the Media Type database, and the Mappings database. Multiple configurations of each can be provided. This allows the user a great deal of flexibility in configuring Media Type information for Elemental, whilst also allowing us to ship sane defaults. Details about how to configure each of those follows:
Media Type Database
Elemental will load all Media Type databases in the following order from the following locations. Access to these is in priority order, which is to say that Elemental will favour definitions in (1) over (2), and then (2) over (3), etc.
.jakarta.mime.typesin the user's home directory..mime.typesin the user's home directory.jakarta.mime.typesfrom within the user's home directory:$XDG_DATA_HOME/jakarta.mime.types.If
$XDG_DATA_HOMEis not set then:~/.local/share/jakarta.mime.types.$XDG_DATA_HOME/jakarta.mime.types.If
$XDG_DATA_HOMEis not set then:~/Library/Application Support/jakarta.mime.types.%APPDATA%/jakarta.mime.types.If
%APPDATA%is not set then:%USERPROFILE%/AppData/Local/jakarta.mime.types.jakarta.mime.typesin the application's config directory, i.e.:$ELEMENTAL_HOME/etc/jakarta.mime.types.mime.typesin the application's config directory, i.e.:$ELEMENTAL_HOME/etc/jakarta.mime.types.mime.typeson the classpath in the packagexyz.elemental.mediatype.jakarta.mime.typesfrom the Java runtime.mime.typesfrom the Java runtime.META-INF/jakarta.mime.typesthat are present on the classpath.META-INF/mime.typesthat are present on the classpath.META-INF/jakarta.mimetypes.default(usually found only in theactivation.jar).META-INF/mimetypes.default(usually found only in theactivation.jarfile).Mappings Database
Elemental will load all Media Type databases in the following order from the following locations. Access to these is in priority order, which is to say that Elemental will favour definitions in (1) over (2), and then (2) over (3), etc.
media-type-mappings.xmlfrom within the user's home directory:$XDG_CONFIG_HOME/elemental/media-type-mappings.xml.If
$XDG_CONFIG_HOMEis not set then:~/.config/elemental/media-type-mappings.xml.$XDG_CONFIG_HOME/elemental/media-type-mappings.xml.If
$XDG_CONFIG_HOMEis not set then:~/Library/Preferences/xyz.elemental/media-type-mappings.xml.%APPDATA%/Elemental/media-type-mappings.xml.If
%APPDATA%is not set then:%USERPROFILE%/AppData/Local/Elemental/media-type-mappings.xml.media-type-mappings.xmlin the application's config directory, i.e.:$ELEMENTAL_HOME/etc/media-type-mappings.xml.media-type-mappings.xmlon the classpath in the packagexyz.elemental.mediatype.Closes eXist-db/exist#3608
Closes eXist-db/exist#5834