eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'MIMETypes':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: MIMETypes


Inheritance:

   Object
   |
   +--MIMETypes

Package:
stx:libview2
Category:
Net-Communication-Support
Version:
rev: 1.224 date: 2024/04/12 17:40:28
user: stefan
file: MIMETypes.st directory: libview2
module: stx stc-classLibrary: libview2

Description:


just a place to keep MIME information
(avoid spreading things at many places)

MIMETypes is abstract and functional.
Actually, in some OperatingSystems, this information may
be found in some config files (or registries).
Therefore, this class may have to be extended to support this
and fetch the information from there eventually.

copyright

COPYRIGHT (c) 1997 by eXept Software AG All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

knownTypes

simply a reminder for me ... application mime file extentsions powerpoint application/ms-powerpoint .pot, .ppz, .ppt, .pps, application/mspowerpoint application/vnd.ms-powerpoint application/x-mspowerpoint shockwave application/x-shockwave-flash .swf futuresplash application/futuresplash .spl

Class protocol:

initialization
o  addMimeTypeDetector: aMimeTypeFromContentsDetectorBlock
any class (especially: image readers) may add a block
that detects the MIME type from a given content.
The block is called with two arguments, some data (usually the first few kilobytes
of a file) and the suffix of the file, or nil if unknown.
The block should return the MIME type or nil.

o  defineImageType: mimeType suffix: aSuffix reader: aReaderClass
register an image reader.

o  defineImageType: mimeType suffix: aSuffix reader: aReaderClass info: info
register an image reader.

o  initialize
initialize wellKnown facts

Usage example(s):

     self initialize

o  initializeAudioReaderMappings
these are used so select an audio reader, based on a file's MIME type

o  initializeCommentStringMappings
these are used by the editor's comment/uncomment functions

o  initializeDefaultCommands
these are used to select an application to be opened when a file of a particular
type is double clicked in the browser.
TODO: move this to OS

Usage example(s):

     self initializeDefaultCommands

o  initializeFileInfoMappings
these are used by the file browser if a 'file' command is not present in the OS

Usage example(s):

     self initializeFileInfoMappings
     'foo.H' asFilename mimeTypeFromName
     'foo.o' asFilename mimeTypeFromName
     'foo.py' asFilename mimeTypeFromName

o  initializeFileNameToMimeTypeMapping
initialize wellKnown facts

Usage example(s):

     self initializeFileNameToMimeTypeMapping

o  initializeImageReaderMappings
these are used so select an image reader, based on a bitmap image's MIME type

o  initializeParenthesisSpecMappings
these are used by the editors to mark matching parentheses

o  mimeTypeForFilename: filename put: mimeType
register a MIME type for a filename

o  mimeTypeForSuffix: suffix put: mimeType
register a MIME type for a file suffix

initialization-lists
o  applicationCompressorsAndArchiveTypeList
compressor applications

o  applicationMiscTypeList
misc applications

o  applicationProgLangTypeList
applications for programming languages

o  applicationTextTypeList
text applications

o  applicationTypeList
applications

o  audioTypeList
audio formats ...

o  imageTypeList
wellknown image formats ...

o  miscFilenameList
other formats (not by suffix, but by fileName instead) ...

o  osSpecificTypeList
self osSpecificTypeList

o  osxSpecificTypeList
the first column is a list of extensions, the second the more-or-less official MIME type

o  textTypeList
misc text ...

o  unixSpecificTypeList
the first column is a list of extensions, the second the more-or-less official MIME type

o  videoTypeList
video formats ...

o  windowsSpecificTypeList
the first column is a list of extensions, the second the more-or-less official MIME type

obsolete
o  defaultCommandForMimeType: mimeType
MIMETypes defaultCommandTemplateToOpenMimeType:'application/pdf'


** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  fontForCharset: aCharSetName
return the font-encoding for an iso-charset

** This is an obsolete interface - do not use it (it may vanish in future versions) **

queries
o  fileInfoForMimeType: mimeType
given a mimeType, return an info string similar to what the unix 'file' command
provides. This info here is returned by systems which have no file (i.e. MSDOS) and
for types of which file does not know about (smalltalk files, for example)

Usage example(s):

     self fileInfoForMimeType:(MIMEType fromString:'text/html')
     self fileInfoForMimeType:(MIMEType fromString:'image/gif')

o  fileSuffixToImageReaderMapping
return the suffix-to-imageReader mapping

o  imageFileSuffixes
return a collection with known file suffixes

o  mimeTypeForFilename: filenameOrString
given a filename, return the MIME type or nil if unknown

Usage example(s):

     MIMETypes mimeTypeForFilename:'typeinst.dvi'
     MIMETypes mimeTypeForFilename:'foo.tar'
     MIMETypes mimeTypeForFilename:'foo.tgz'
     MIMETypes mimeTypeForFilename:'foo.tar.gz'
     MIMETypes mimeTypeForFilename:'foo.txt'
     MIMETypes mimeTypeForFilename:'foo.pkg'
     MIMETypes mimeTypeForFilename:'foo.sm'
     MIMETypes mimeTypeForFilename:'foo.cbl'
     MIMETypes mimeTypeForFilename:'/Users/cg/work/stx/goodies/bitmaps/tiffimages/moreSamples/multi-channel.ome.tif'
     MIMETypes mimeTypeForFilename:'multi-channel.ome.tif'
     MIMETypes mimeTypeForFilename:'multi-channel.tif'
     Time microsecondsToRun:[ MIMETypes mimeTypeForFilename:'orders.edi' ]   
     MIMETypes mimeTypeForFilename:'orders.edi'  

o  mimeTypeForSuffix: suffix
given a file suffix, return the MIME type

Usage example(s):

     self mimeTypeForSuffix:'gif'
     self mimeTypeForSuffix:'rpm'
     self mimeTypeForSuffix:'zip'
     self mimeTypeForSuffix:'py'
     self mimeTypeForSuffix:'svg'

o  mimeTypeForSuffixMapping

o  mimeTypeFromString: mimeTypeString
given a MIME type for a string

Usage example(s):

     MIMETypes mimeTypeFromString:'text/html'
     MIMETypes mimeTypeFromString:'image/gif'
     MIMETypes mimeTypeFromString:'application/x-expecco-testsuite'

o  mimeTypeOfContents: filename
given a filename, scan the contents, return the MIME type or nil, if unknown

o  mimeTypeOfData: someData
this tries to guess the MIME type of contents of someData.
Returns nil if unknown.
This is done using some heuristics, and may need some improvement

o  mimeTypeOfData: someData suffix: fileNameSuffixOrNilIfUnknown
this tries to guess the MIME type of someData.
Returns nil if unknown.
In addition to registered detectors (see addMimeTypeDetector:),
this is done using heuristics, and may need some improvement

o  suffixForMimeType: mimeType
given a file suffix, return the MIME type

Usage example(s):

     self suffixForMimeType:(MIMEType fromString:'image/gif')

o  suffixForMimeTypeString: mimeTypeString
given a file suffix, return the MIME type

Usage example(s):

     self suffixForMimeTypeString:'image/gif'

o  typeToInfoMapping

queries-applications
o  defaultCommandPerMIME
returns the collection which is used to map MIME type to command-templates.

Usage example(s):

     MIMETypes defaultCommandPerMIME

o  defaultCommandTemplateToOpenMimeType: mimeType
MIMETypes defaultCommandTemplateToOpenMimeType:'application/pdf'
MIMETypes defaultCommandTemplateToOpenMimeType:'text/html'

o  defaultCommandTemplateToPrintMimeType: mimeType
MIMETypes defaultCommandTemplateToPrintMimeType:'application/pdf'

o  defaultPrintCommandPerMIME
returns the collection which is used to map MIME type to printing command-templates.

queries-audio formats
o  audioReaderClasses
return a collection of registered audio reader classes

o  audioReaderForSuffix: aSuffix
given a file suffix, return an appropriate audio reader class

Usage example(s):

     self audioReaderForSuffix:'wav'
     self audioReaderForSuffix:'snd'
     self audioReaderForSuffix:'aiff'

o  audioReaderForSuffix: aSuffix put: aReaderClass
register an audio reader for a file suffix

o  audioReaderForType: mimeTypeString
given a MIME type, return an appropriate audio reader class

o  audioReaderForType: mimeTypeString put: aReaderClass
register an audio reader for a MIME type

queries-image formats
o  imageReaderClasses
return a collection of registered image reader classes

o  imageReaderForSuffix: aSuffix
given a file suffix, return an appropriate image reader class

Usage example(s):

     self imageReaderForSuffix:'wbmp'

o  imageReaderForSuffix: aSuffix put: aReaderClass
register an image reader for a file suffix

o  imageReaderForType: mimeTypeString
given a MIME type, return an appropriate image reader class

o  imageReaderForType: mimeTypeString put: aReaderClass
register an image reader for a MIME type

queries-language syntax
o  commentStringsForFilename: aFilenameOrString
return a useful comment definition; heuristics for now.
The returned value is an array of 2 elements;
the first is the end-of-line comment string (or nil);
the second an array of opening/closing delimiters (or an array of nils)

Usage example(s):

     MIMETypes commentStringsForFilename:'Makefile'.
     MIMETypes commentStringsForFilename:'Object.st'.
     MIMETypes commentStringsForFilename:'Foo.java'.
     MIMETypes commentStringsForFilename:'Foo.html'.

o  commentStringsForFilename: aFilename ifUnknown: alternativeBlockReturningCommentString
return a useful comment definition; heuristics for now.
The returned value is an array of 2 elements;
the first is the end-of-line comment string (or nil);
the second an array of opening/closing delimiters (or an array of nils)

Usage example(s):

     MIMETypes commentStringsForFilename:'Makefile'.
     MIMETypes commentStringsForFilename:'Object.st'.
     MIMETypes commentStringsForFilename:'Foo.java'.

o  commentStringsForMimeType: mime suffix: suff
return a useful comment definition; heuristics for now.
The returned value is an array of 2 elements;
the first is the end-of-line comment string (or nil);
the second an array of opening/closing delimiters (or an array of nils)

Usage example(s):

     |mime|

     mime := MIMETypes mimeTypeForFilename:'Makefile'.
     MIMETypes commentStringsForMimeType:mime suffix:nil.

Usage example(s):

     |mime|

     mime := MIMETypes mimeTypeForFilename:'Object.st'.
     MIMETypes commentStringsForMimeType:mime suffix:nil.

o  commentStringsForMimeType: mime suffix: suff ifUnknown: alternativeBlockReturningCommentString
return a useful comment definition; heuristics for now.
The returned value is an array of 2 elements;
the first is the end-of-line comment string (or nil);
the second an array of opening/closing delimiters (or an array of nils)

Usage example(s):

     |mime|

     mime := MIMETypes mimeTypeForFilename:'Makefile'.
     MIMETypes commentStringsForMimeType:mime suffix:nil.

Usage example(s):

     |mime|

     mime := MIMETypes mimeTypeForFilename:'Object.st'.
     MIMETypes commentStringsForMimeType:mime suffix:nil.

o  parenthesisSpecForFilename: aFilename
return a useful parenthesis spec; heuristics for now.
The returned value is a dictionary to be used as parenthesis spec in an editor

Usage example(s):

     MIMETypes parenthesisSpecForFilename:'Object.st'.
     MIMETypes parenthesisSpecForFilename:'Foo.java'.
     MIMETypes parenthesisSpecForFilename:'Foo.html'.
     MIMETypes parenthesisSpecForFilename:'Foo.lsp'.
     MIMETypes parenthesisSpecForFilename:'Foo.py'.
     MIMETypes parenthesisSpecForFilename:'Foo.bla'.

o  parenthesisSpecForFilename: aFilename ifUnknown: alternative
MIMETypes parenthesisSpecForFilename:'Foo.py' ifUnknown:#bad.
MIMETypes parenthesisSpecForFilename:'Foo.bla' ifUnknown:#bad.
MIMETypes parenthesisSpecForFilename:'Foo.scm' ifUnknown:#bad.
MIMETypes parenthesisSpecForFilename:'Foo.py' ifUnknown:#bad.
MIMETypes parenthesisSpecForFilename:'Foo.js' ifUnknown:#bad.

o  parenthesisSpecForMimeType: mime
|mime1 mime2|

mime1 := 'application/x-python-source' asMimeType.
MIMETypes parenthesisSpecForMimeType:mime1.

mime1 := 'application/x-foobar' asMimeType.
MIMETypes parenthesisSpecForMimeType:mime2.

o  parenthesisSpecForMimeType: mime ifUnknown: alternative
|mime1 mime2|

mime1 := 'application/x-python-source' asMimeType.
MIMETypes parenthesisSpecForMimeType:mime1 ifUnknown:#bad.

mime1 := 'application/x-foobar' asMimeType.
MIMETypes parenthesisSpecForMimeType:mime2 ifUnknown:#bad.

o  parenthesisSpecForMimeType: mime suffix: suff

o  parenthesisSpecForMimeType: mime suffix: suff ifUnknown: alternativeValue
basic fetcher; tries to find an entry either in the mime-types dict,
or the suffix dict.

Usage example(s):

     |mime1 mime2|

     mime1 := 'application/x-python-source' asMimeType.
     MIMETypes parenthesisSpecForMimeType:mime1 suffix:'bla' ifUnknown:#bad.

     mime2 := 'application/x-foobar' asMimeType.
     MIMETypes parenthesisSpecForMimeType:mime2 suffix:'py' ifUnknown:#bad.

     mime2 := 'application/x-foobar' asMimeType.
     MIMETypes parenthesisSpecForMimeType:mime2 suffix:'bla' ifUnknown:#bad.


Private classes:

    MIMEType

Examples:


    MIMETypes mimeTypeFromString:'text/plain'
    MIMETypes mimeTypeFromString:'application/x-expecco-testsuite'
    MIMETypes mimeTypeForSuffix:'gif'
    MIMETypes mimeTypeForSuffix:'ets'
    MIMETypes mimeTypeForSuffix:'xlsx'


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 04:31:46 GMT