MIMETypes.st
changeset 1272 91ba4078b690
parent 1269 4362ec6dd5c2
child 1273 7a52d4bcdb10
equal deleted inserted replaced
1271:1fc0f8a774c7 1272:91ba4078b690
    13 "
    13 "
    14 
    14 
    15 Object subclass:#MIMETypes
    15 Object subclass:#MIMETypes
    16 	instanceVariableNames:''
    16 	instanceVariableNames:''
    17 	classVariableNames:'TypeToImageReaderClassMapping FileSuffixToTypeMapping
    17 	classVariableNames:'TypeToImageReaderClassMapping FileSuffixToTypeMapping
    18 		FileSuffixToImageReaderClassMapping CharSetToFontMapping'
    18 		FilenameToTypeMapping FileSuffixToImageReaderClassMapping
       
    19 		CharSetToFontMapping'
    19 	poolDictionaries:''
    20 	poolDictionaries:''
    20 	category:'System-Documentation'
    21 	category:'System-Documentation'
    21 !
    22 !
    22 
    23 
    23 !MIMETypes class methodsFor:'documentation'!
    24 !MIMETypes class methodsFor:'documentation'!
   103         'pdf'                   'application/pdf'
   104         'pdf'                   'application/pdf'
   104         'rtf'                   'application/rtf'
   105         'rtf'                   'application/rtf'
   105 
   106 
   106         "/ video formats ...
   107         "/ video formats ...
   107 
   108 
   108         'movie'                         'video/x-sgi-movie'
   109         'movie'                            'video/x-sgi-movie'
   109         'avi'                           'video/x-msvideo'
   110         'avi'                              'video/x-msvideo'
   110         ('qt' 'mov' 'moov')             'video/quicktime'
   111         ('qt' 'mov' 'moov')                'video/quicktime'
   111         ('mpv2' 'mp2v' 'mp2' 'mpeg2')         'video/x-mpeg2'
   112         ('mpv2' 'mp2v' 'mp2' 'mpeg2')      'video/x-mpeg2'
   112         ('mpv' 'mpegv' 'mpg' 'mpeg' 'mpe')    'video/mpeg'
   113         ('mpv' 'mpegv' 'mpg' 'mpeg' 'mpe') 'video/mpeg'
   113 
   114 
   114         "/ audio formats ...
   115         "/ audio formats ...
   115 
   116 
   116         ('ra' 'ram')            'audio/x-pn-realaudio'
   117         ('ra' 'ram')            'audio/x-pn-realaudio'
   117         ('mpa' 'mpega')         'audio/x-mpeg'
   118         ('mpa' 'mpega')         'audio/x-mpeg'
   122         "/ misc stuff
   123         "/ misc stuff
   123 
   124 
   124         "/ progr. languages
   125         "/ progr. languages
   125         'st'                    'application/x-smalltalk-source'
   126         'st'                    'application/x-smalltalk-source'
   126         ('js' 'mocha')          'application/x-javascript'
   127         ('js' 'mocha')          'application/x-javascript'
   127         'java'                  'application/x-java-source'
   128         ('java' 'jav')          'application/x-java-source'
   128         'sh'                    'application/x-sh'
   129         'sh'                    'application/x-sh'
   129         'csh'                   'application/x-csh'
   130         'csh'                   'application/x-csh'
   130         'tcl'                   'application/x-tcl'
   131         'tcl'                   'application/x-tcl'
   131         'pl'                    'application/x-perl'
   132         'pl'                    'application/x-perl'
   132         'mak'                   'application/x-make'
   133         'mak'                   'application/x-make'
   143     ) pairWiseDo:[:suff :type|
   144     ) pairWiseDo:[:suff :type|
   144         suff isArray ifTrue:[
   145         suff isArray ifTrue:[
   145             suff do:[:s | fileSuffixToTypeMapping at:s put:type]
   146             suff do:[:s | fileSuffixToTypeMapping at:s put:type]
   146         ] ifFalse:[
   147         ] ifFalse:[
   147             fileSuffixToTypeMapping at:suff put:type
   148             fileSuffixToTypeMapping at:suff put:type
       
   149         ]
       
   150     ].
       
   151 
       
   152     FilenameToTypeMapping := Dictionary new.
       
   153     #(
       
   154         ('makefile' 'make.proto')  'application/x-make'
       
   155     ) pairWiseDo:[:nm :type|
       
   156         nm isArray ifTrue:[
       
   157             nm do:[:s | FilenameToTypeMapping at:s put:type]
       
   158         ] ifFalse:[
       
   159             FilenameToTypeMapping at:nm put:type
   148         ]
   160         ]
   149     ].
   161     ].
   150 
   162 
   151     "/ setup mimeType to image reader class mapping ...
   163     "/ setup mimeType to image reader class mapping ...
   152 
   164 
   311 
   323 
   312     "Created: / 30.6.1997 / 21:56:11 / cg"
   324     "Created: / 30.6.1997 / 21:56:11 / cg"
   313     "Modified: / 1.8.1998 / 17:02:40 / cg"
   325     "Modified: / 1.8.1998 / 17:02:40 / cg"
   314 !
   326 !
   315 
   327 
       
   328 mimeTypeForFilename:filename
       
   329     "given a filename, return the mime-type or nil, if unknown"
       
   330 
       
   331     |type lcFilename|
       
   332 
       
   333     lcFilename := filename asFilename name asLowercase.
       
   334     type := FilenameToTypeMapping at:lcFilename ifAbsent:nil.
       
   335     type isNil ifTrue:[
       
   336         "/ allow for fallback ...
       
   337         type := OperatingSystem mimeTypeForFilename:lcFilename.
       
   338         "/ the special value #unknown is returned as nil;
       
   339         "/ this avoids constant retry if a mimeType is not known in
       
   340         "/ the OS.
       
   341         type isNil ifTrue:[
       
   342             (#('make.proto'
       
   343                'makefile'
       
   344             ) includes:lcFilename) ifTrue:[
       
   345                 type := 'application/x-make'
       
   346             ].
       
   347         ].
       
   348         type isNil ifTrue:[
       
   349             FilenameToTypeMapping at:lcFilename put:#unknown
       
   350         ].
       
   351     ].
       
   352 
       
   353     type == #unknown ifTrue:[
       
   354         type := nil.
       
   355     ].
       
   356     ^ type
       
   357 
       
   358 !
       
   359 
       
   360 mimeTypeForFilename:filename put:mimeType
       
   361     "register a mime type for a filename"
       
   362 
       
   363     FilenameToTypeMapping isNil ifTrue:[
       
   364         FilenameToTypeMapping := Dictionary new
       
   365     ].
       
   366     FilenameToTypeMapping at:filename put:mimeType asLowercase
       
   367 
       
   368 !
       
   369 
   316 mimeTypeForSuffix:suffix
   370 mimeTypeForSuffix:suffix
   317     "given a file suffix, return the mime-type"
   371     "given a file suffix, return the mime-type"
   318 
   372 
   319     |type lcSuffix|
   373     |type lcSuffix|
   320 
   374 
   329         type isNil ifTrue:[
   383         type isNil ifTrue:[
   330             FileSuffixToTypeMapping at:lcSuffix put:#unknown
   384             FileSuffixToTypeMapping at:lcSuffix put:#unknown
   331         ].
   385         ].
   332     ].
   386     ].
   333     type == #unknown ifTrue:[
   387     type == #unknown ifTrue:[
   334         ^ nil
   388         type := nil
   335     ].
   389     ].
   336     ^ type
   390     ^ type
   337 
   391 
   338     "Created: / 30.6.1997 / 21:55:51 / cg"
   392     "Created: / 30.6.1997 / 21:55:51 / cg"
   339     "Modified: / 1.8.1998 / 17:02:59 / cg"
   393     "Modified: / 1.8.1998 / 17:02:59 / cg"
   352 ! !
   406 ! !
   353 
   407 
   354 !MIMETypes class methodsFor:'documentation'!
   408 !MIMETypes class methodsFor:'documentation'!
   355 
   409 
   356 version
   410 version
   357     ^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.18 1999-11-19 14:18:51 cg Exp $'
   411     ^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.19 1999-12-01 10:19:43 cg Exp $'
   358 ! !
   412 ! !
   359 MIMETypes initialize!
   413 MIMETypes initialize!