Skip to content

Conversation

@adamretter
Copy link
Member

@adamretter adamretter commented Nov 28, 2025

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:

  1. The mime-types.xml file and associated Java classes org.exist.util.MimeType and org.exist.util.MimeTable are 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.

  2. Elemental now uses the standard Jakarta Activation Framework as part of its implementation to support Internet Media Types.

  3. Elemental now loads Media Type information from two files:

    1. A Media Type database file named either jakarta.mime.types or mime.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
    2. A Mappings database file named 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.

  1. The file .jakarta.mime.types in the user's home directory.
  2. The file .mime.types in the user's home directory.
  3. The file jakarta.mime.types from within the user's home directory:
    • Linux/Unix: $XDG_DATA_HOME/jakarta.mime.types.
      If $XDG_DATA_HOME is not set then: ~/.local/share/jakarta.mime.types.
    • macOS: $XDG_DATA_HOME/jakarta.mime.types.
      If $XDG_DATA_HOME is not set then: ~/Library/Application Support/jakarta.mime.types.
    • Windows: %APPDATA%/jakarta.mime.types.
      If %APPDATA% is not set then: %USERPROFILE%/AppData/Local/jakarta.mime.types.
  4. The file jakarta.mime.types in the application's config directory, i.e.: $ELEMENTAL_HOME/etc/jakarta.mime.types.
  5. The file mime.types in the application's config directory, i.e.: $ELEMENTAL_HOME/etc/jakarta.mime.types.
  6. The default database shipped with Elemental from the resource: mime.types on the classpath in the package xyz.elemental.mediatype.
  7. The file jakarta.mime.types from the Java runtime.
  8. The file mime.types from the Java runtime.
  9. The resources named META-INF/jakarta.mime.types that are present on the classpath.
  10. The resources named META-INF/mime.types that are present on the classpath.
  11. The resources named META-INF/jakarta.mimetypes.default (usually found only in the activation.jar).
  12. The resources named META-INF/mimetypes.default (usually found only in the activation.jar file).

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.

  1. The file media-type-mappings.xml from within the user's home directory:
    • Linux/Unix: $XDG_CONFIG_HOME/elemental/media-type-mappings.xml.
      If $XDG_CONFIG_HOME is not set then: ~/.config/elemental/media-type-mappings.xml.
    • macOS: $XDG_CONFIG_HOME/elemental/media-type-mappings.xml.
      If $XDG_CONFIG_HOME is not set then: ~/Library/Preferences/xyz.elemental/media-type-mappings.xml.
    • Windows: %APPDATA%/Elemental/media-type-mappings.xml.
      If %APPDATA% is not set then: %USERPROFILE%/AppData/Local/Elemental/media-type-mappings.xml.
  2. The file named media-type-mappings.xml in the application's config directory, i.e.: $ELEMENTAL_HOME/etc/media-type-mappings.xml.
  3. The default database shipped with Elemental from the resource media-type-mappings.xml on the classpath in the package xyz.elemental.mediatype.

Closes eXist-db/exist#3608
Closes eXist-db/exist#5834

@adamretter adamretter added this to the elemental-7.5.0 milestone Nov 28, 2025
@adamretter adamretter self-assigned this Nov 28, 2025
@adamretter adamretter added the enhancement New feature or request label Nov 28, 2025
@cla-bot cla-bot bot added the cla-signed label Nov 28, 2025
@adamretter adamretter changed the base branch from main to develop-7.x.x November 28, 2025 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] mime-types can no longer be extended Fix mimetype handling

2 participants