MIMETypes.st
changeset 1837 75e19f4e8b05
parent 1820 7817c4809af7
child 1840 19123ded64e3
equal deleted inserted replaced
1836:c1e0cf991a4d 1837:75e19f4e8b05
   541 mimeTypeForSuffix:suffix
   541 mimeTypeForSuffix:suffix
   542     "given a file suffix, return the mime-type"
   542     "given a file suffix, return the mime-type"
   543 
   543 
   544     |type lcSuffix|
   544     |type lcSuffix|
   545 
   545 
       
   546     suffix = LastSuffix ifTrue:[
       
   547         ^ LastType
       
   548     ].
       
   549 
   546     lcSuffix := suffix asLowercase.
   550     lcSuffix := suffix asLowercase.
   547     lcSuffix = LastSuffix ifTrue:[
   551     type := FileSuffixToTypeMapping at:lcSuffix ifAbsent:nil.
   548         type := LastType
   552     type isNil ifTrue:[
   549     ] ifFalse:[
   553         "/ allow for fallback ...
   550         type := FileSuffixToTypeMapping at:lcSuffix ifAbsent:nil.
   554         type := OperatingSystem mimeTypeForSuffix:lcSuffix.
   551         type isNil ifTrue:[
   555         "/ the special value #unknown is returned as nil;
   552             "/ allow for fallback ...
   556         "/ this avoids constant retry if a mimeType is not known in the OS.
   553             type := OperatingSystem mimeTypeForSuffix:lcSuffix.
   557 
   554             "/ the special value #unknown is returned as nil;
   558         type := type ? #unknown.
   555             "/ this avoids constant retry if a mimeType is not known in
   559         FileSuffixToTypeMapping at:lcSuffix put:type.
   556             "/ the OS.
   560     ].
   557     "/        type isNil ifTrue:[
   561 
   558     "/            FileSuffixToTypeMapping at:lcSuffix put:#unknown
       
   559     "/        ].
       
   560         ].
       
   561         LastSuffix := lcSuffix.
       
   562         LastType := type.
       
   563     ].
       
   564     type == #unknown ifTrue:[
   562     type == #unknown ifTrue:[
   565         type := nil
   563         type := nil.
   566     ].
   564     ].
   567     type notNil ifTrue:[
   565     LastSuffix := suffix.
   568         ^ MIMEType fromString:type
   566     LastType := type.
   569     ].
       
   570     ^ type
   567     ^ type
   571 
   568 
   572     "
   569     "
   573      self mimeTypeForSuffix:'xml'
   570      self mimeTypeForSuffix:'xml'
   574     "
   571     "
   841 ! !
   838 ! !
   842 
   839 
   843 !MIMETypes class methodsFor:'documentation'!
   840 !MIMETypes class methodsFor:'documentation'!
   844 
   841 
   845 version
   842 version
   846     ^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.62 2003-09-18 18:22:08 cg Exp $'
   843     ^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.63 2003-10-29 08:31:15 penk Exp $'
   847 ! !
   844 ! !
   848 
   845 
   849 MIMETypes initialize!
   846 MIMETypes initialize!
   850 MIMETypes::MIMEType initialize!
   847 MIMETypes::MIMEType initialize!