Java Desktop System Release 3 Administration Guide

Chapter 5 MIME Types

This chapter describes MIME types, and the MIME database, and also describes how to add applications to the desktop.

Introduction to MIME Types

A Multipurpose Internet Mail Extension (MIME) type identifies the format of a file. The MIME type enables applications to read the file. Applications such as web browsers and email applications use the MIME type to handle files of different types. For example, an email application can use the MIME type to detect what type of file is attached to an email.

The file manager uses MIME types to identify the type of a file. The file manager needs to know the MIME type of a file to perform the following tasks:

If you add a new application to the desktop, you must ensure that other applications can recognize the files associated with the application. You must ensure that if the new application requires a new MIME type, that the new application installs the new MIME type.

This chapter describes the MIME database, and how applications are associated with MIME types. This chapter also describes the steps that you must follow to add a new application to the desktop.

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.

Adding a MIME Type to the MIME Database

To add a new MIME type to the database, an application must install a MIME type description file. A MIME type description file is an XML file that associates MIME types with file content sniffer information, and with file extensions and filename patterns.

The following is a sample MIME type description file:

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
	<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>
</mime-info>

The elements in a MIME type description file are similar to the elements in the MIME database. For information about the elements in a MIME type description file, see Structure of the MIME Database.

After the application installs the MIME type description file, the application must execute the update-mime-database command to update the MIME database.

Adding an Application to the Desktop

To add an application to the desktop, perform the following steps:

  1. Add a menu item for the application. For more information about how to add an item to a menu, see Chapter 2, Customizing Menus.

  2. Add an icon for the application to /usr/share/icons/theme-name/icon-size/apps. For more information about icons and themes, see Chapter 3, Installing Themes.

  3. If the application uses a new MIME type and does not automatically add the MIME type to the MIME database, add a MIME type description file to /usr/share/mime/packages/.

  4. If the application installs a new MIME type description file, ensure that the update-mime-database command is executed during the installation, to update the MIME database.

  5. If the application uses a new MIME type, add icons for the MIME type to /usr/share/icons/theme-name/icon-size/mimetypes. For more information about icons and themes, see Chapter 3, Installing Themes.

  6. Log out of the session, then log in again.