Java Desktop System Release 3 Administration Guide

MIME Database

All MIME type information is stored in a database. The MIME database is located in the directory /usr/share/mime/. The MIME database contains a large number of common MIME types, stored in the file /usr/share/mime/packages/freedesktop.org.xml. Applications can add new MIME types to the MIME database.

Applications use the MIME database to detect the MIME type of a file, in the following ways:

The MIME database also contains a text description of each MIME type. The MIME database can also contain a list of applications that you can use to view or edit a MIME type.

Structure of the MIME Database

The following is a sample from the MIME type database:

<mime-type type="image/png">
		<comment>PNG image</comment>
		<comment xml:lang="de">PNG-Grafik</comment>
		:
		:
		:
		<magic priority="50">
			<match offset="0" type="string" value="\x89PNG" />
		</magic>
		<glob pattern="*.png" />
	</mime-type>

Table 5–1 describes the elements in the MIME type database.

Table 5–1 MIME Type Database Elements

Element 

Description 

mime-info

This is the document element, or highest level element in the MIME database. This element contains the required information for all MIME types. The namespace URI of this element is as follows:  

http://www.freedesktop.org/standards/shared-mime-info

mime-type

Describes one MIME type. This element has a type attribute, which specifies the MIME type.

comment

Provides a description of the MIME type that is used in the user interface. The description can be displayed in the file manager and other applications. 

The database might contain comment elements with xml:lang attributes. These elements can provide the descriptive text in other languages.

magic

Contains match elements. The match elements specify a particular pattern to search for in the contents of a file.

This associates a specific pattern in a file with the MIME type specified in the mime-type element. If an application finds a match for the pattern, the MIME type associated with the pattern is the MIME type of the file.

The magic element includes a priority attribute. You can specify a priority value for the pattern. If there are identical patterns in the magic elements in the MIME database, the element with the highest priority value takes precedence.

For more information about the attributes of a match element, see Attributes in Match Elements.

glob

Specifies a filename pattern to match with the MIME type. Any file that matches this filename pattern takes this MIME type.  

root-XML

If a file is identified as an XML file, you can associate a more specific MIME type than text/xml with the file. To do this, you assign values to the following attributes of the root-XML element:

  • namespaceURI: Type a namespace that uniquely identifies the type of XML file.

  • localName: Type a local name for the XML file. This name uniquely identifies the MIME type within the namespace of the XML file.

This element is optional. This element is not present in the example. 

Attributes in Match Elements

Table 5–2 describes the attributes in a match element.

Table 5–2 Attributes in match Elements

Attribute 

Description 

offset

Specifies characters to ignore in the file before searching for a pattern. You can specify an integer value. This specifies the number of characters to ignore in the file before searching for a pattern.  

Alternatively, you can specify a range of characters to search. For example, if you specify offset=”1:10”, only the first ten characters are searched.

type

Specifies the type of pattern to search for. You can use the following types for this attribute: 

  • big16

  • big32

  • byte

  • host16

  • host32

  • little16

  • little32

  • string

value

Specifies the pattern to search for.  

mask

Specifies a pattern mask. A pattern mask identifies bits in the pattern to ignore when searching for a pattern in a file.

Masks for strings must be in hexadecimal format, and begin with 0x.

This attribute is optional. This attribute is not present in the example. 

Files Generated From the MIME Database

When a new MIME type is installed, the update-mime-database command is executed to update the MIME database. Table 5–3 describes the files that the update-mime-database command generates:

Table 5–3 Files Generated by update-mime-database

File 

Description 

globs

The globs file is generated from the glob elements in the MIME database, and from the glob elements in any MIME type description files in the packages directory. The globs file contains a simple list of MIME types and the filename patterns that are associated with that file type.

The following are examples of entries in the globs file:

application/x-bzip-compressed-tar:*.tar.bz2
text/html:*.html
image/png:*.png

If there are two identical filename patterns in the glob elements in the MIME database, only the entry from the MIME type description file which comes later alphabetically is added to the globs file. For example, if the MIME type description files abc.xml and def.xml contain identical filename patterns in the glob elements, only the glob element from def.xml is added to the globs file. That is, filename patterns in alphabetically later MIME type description files take precedence.

If you want a MIME type description to take precedence over other MIME type descriptions, no matter what the alphabetical order is, put the MIME type description in a file called Override.xml in the packages directory.

magic

The magic file is generated from the magic elements in the MIME database, and from the magic elements in any MIME type description files in the packages directory. The magic file is stored in binary format.

XMLnamespaces

The magic file is generated from the root-XML elements in the MIME database. This file lists all of the XML namespaces that the XML file types use.

content-type/content-subtype.xml

These files are generated from the comment elements in the MIME database.