Indy 9
|
TIdMimeTable = class(TObject)
On the Windows platform, TIdMimeTable relies on an initial set of common MIME types supplemented by values harvested from the Windows HKEY_CLASSES_ROOT Registry key. On the Linux platform, there is no universal counterpart to the Windows Registry for MIME types. A text-based configuration file is normally present in most Linux distributions. But it's name and location in the file system hierarchy is different for each family of distribution. Each Desktop/Window manager, and many applications, maintain their own MIME type configuration files. Their names and locations are almost always radically different, too.
To accommodate developers on both platforms, TIdMimeTable provides methods that can be used to control the location, format, and content of values used for MIME types. The OnBuildCache event handler can be used to override loading of the cached MIME types registered on the local computer. In addition, LoadFromStrings and SaveToStrings can be used to override the values loaded and stored for TIdMimeTable.
GetFileMIMEType can be used to retrieve the MIME type for a specified file name based on the file extension. GetDefaultFileExt can be used to retrieve the file extension associated with the specified MIME type. Use AddMimeType to add a file extension and MIME type to TIdMimeTable.
TIdMimeTable is designed primarily for use by client applications. But, TIdMimeTable is also used in TIdCustomHTTPServer to determine the file names and extensions that can be provided for an HTTP request with "Accept" header(s) for specific MIME types.
property OnBuildCache: TNotifyEvent;
When a procedure has been assigned to the OnBuildCache event handler, it is entirely responsible for loading the file extensions and MIME type/subtypes used in the class instance. When OnBuildCache is unassigned, the default behavior is to loaded the MIME type and file extension mappings specific to the development platform.
OnBuildCache is triggered in the BuildCache method.
procedure AddMimeType(const Ext: string; const MIMEType: string);
Ext is the case-insensitive file extension including the '.' character. If the period character is not included in Ext, it will be inserted prior to inclusion in the list of file extensions. If Ext is an empty string (''), an EIdException will be raised with the message RSMIMEExtensionEmpty.
MIMEType is the case-insensitive IANA registered MIME type and subtype to be associated with the file extension in Ext. If MIMEType contains an empty string (''), and EIdException will be raised with the message RSMIMEMIMETypeEmpty.
Use GetFileMIMEType to get a MIME type for a specified file name and extension. Use GetDefaultFileExt to find the initial file extension found for a given MIME type and subtype. The MIME type mapping table can be loaded with custom values using LoadFromStrings.
procedure BuildCache; virtual;
When OnBuildCache is unassigned, the default behavior is to loaded the MIME type and file extension mappings specific to the development platform. This includes loading a common set of MIME type mapping values used for both Windows and Linux development platforms.
On the Windows platform, TIdMimeTable supplements these values by harvesting content types from the Windows HKEY_CLASSES_ROOT Registry key.
On the Linux platform, there is no universal counterpart to the Windows Registry for MIME types. A text-based configuration file is normally present in most Linux distributions. But it's name and location in the file system hierarchy is different for each family of distributions. Each Desktop/Window manager, and many applications, maintain their own MIME type configuration files. Their names and locations are almost always radically different, too. On the Linux platform, no additional MIME types are loaded other than the known values used for both development platforms.
No action is performed, however, when existing values are found in the MIME type mappings.
Use LoadFromStrings to load custom MIME type mappings from a TStringList.
constructor Create(Autofill: boolean = true); virtual;
When Autofill is True, Create calls the BuildCache method to populate the MIME type entries from system settings on the local computer, or using the OnBuildCache event handler. When Autofill is False, use LoadFromStrings to populate the MIME type mapping table.
destructor Destroy; override;
function GetDefaultFileExt(Const MIMEType: string): string;
The return value for GetDefaultFileExt will contain the file extension, including the '.' character, associate dwith the MIME type in MIMEType. The return value for the method can be an empty string ('') when the value in MIMEType cannot be found in the MIME type mapping after checking the cached values.
Use AddMimeType to add a new file extension to MIME type mapping to the table.
Use GetFileMIMEType to retrieve the MIME type for a specified file name and file extension.
function GetFileMIMEType(const AFileName: string): string;
procedure LoadFromStrings(AStrings: TStrings; const MimeSeparator: Char = '=');
LoadFromStrings clears any existing file extension and MIME type mappings prior to loading each line in AStrings. LoadFromStrings converts file extensions to their lowercase representation prior to addition to the file extenstion list. LoadFromStrings calls AddMimeType if the file extension does not already exist in the MIME type mapping table.
procedure SaveToStrings(AStrings: TStrings; const MimeSeparator: Char = '=');