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 " |