author | Claus Gittinger <cg@exept.de> |
Fri, 04 Apr 2003 19:07:54 +0200 | |
changeset 1737 | a1ed08195ee7 |
parent 1729 | 5d1b74b8d264 |
child 1775 | cce9dce012ce |
permissions | -rw-r--r-- |
643 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
1612 | 3 |
All Rights Reserved |
643 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
||
12 |
||
13 |
" |
|
14 |
||
1410 | 15 |
"{ Package: 'stx:libview2' }" |
16 |
||
643 | 17 |
Object subclass:#MIMETypes |
1612 | 18 |
instanceVariableNames:'' |
1729 | 19 |
classVariableNames:'TypeToImageReaderClassMapping TypeToCommentStringMapping |
20 |
SuffixToCommentStringMapping FileSuffixToTypeMapping |
|
1612 | 21 |
FilenameToTypeMapping FileSuffixToImageReaderClassMapping |
1691
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
22 |
CharSetToFontMapping LastSuffix LastType |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
23 |
DefaultCommandPerMIMEPerOS' |
1612 | 24 |
poolDictionaries:'' |
1716 | 25 |
category:'System-Communication-Support' |
1612 | 26 |
! |
27 |
||
28 |
String variableByteSubclass:#MIMEType |
|
29 |
instanceVariableNames:'' |
|
30 |
classVariableNames:'CachedTypes' |
|
31 |
poolDictionaries:'' |
|
32 |
privateIn:MIMETypes |
|
643 | 33 |
! |
34 |
||
35 |
!MIMETypes class methodsFor:'documentation'! |
|
36 |
||
37 |
copyright |
|
38 |
" |
|
39 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
1612 | 40 |
All Rights Reserved |
643 | 41 |
|
42 |
This software is furnished under a license and may be used |
|
43 |
only in accordance with the terms of that license and with the |
|
44 |
inclusion of the above copyright notice. This software may not |
|
45 |
be provided or otherwise made available to, or used by, any |
|
46 |
other person. No title to or ownership of the software is |
|
47 |
hereby transferred. |
|
48 |
||
49 |
||
50 |
" |
|
51 |
! |
|
52 |
||
53 |
documentation |
|
54 |
" |
|
55 |
just a place to keep MIME information |
|
56 |
(avoid spreading things at many places) |
|
57 |
||
1021 | 58 |
MIMETypes is abstract and functional. |
59 |
Actually, in some OperatingSystems, this information may |
|
60 |
be found in some config files (or registries). |
|
61 |
Therefore, this class may have to be extended to support this |
|
62 |
and fetch the information from there eventually. |
|
63 |
||
643 | 64 |
[author:] |
65 |
Claus Gittinger |
|
66 |
" |
|
1311 | 67 |
! |
68 |
||
69 |
knownTypes |
|
70 |
" |
|
71 |
simply a reminder for me ... |
|
72 |
||
73 |
application mime file extentsions |
|
74 |
||
75 |
powerpoint application/ms-powerpoint .pot, .ppz, .ppt, .pps, |
|
76 |
application/mspowerpoint |
|
77 |
application/vnd.ms-powerpoint |
|
78 |
application/x-mspowerpoint |
|
79 |
||
1312 | 80 |
shockwave application/x-shockwave-flash .swf |
1311 | 81 |
|
1312 | 82 |
futuresplash application/futuresplash .spl |
1311 | 83 |
" |
643 | 84 |
! ! |
85 |
||
86 |
!MIMETypes class methodsFor:'initialization'! |
|
87 |
||
1729 | 88 |
initialize |
89 |
"initialize wellKnown facts" |
|
90 |
||
91 |
MIMEType initialize. "must be initialized first" |
|
92 |
LastSuffix := LastType := nil. |
|
93 |
||
94 |
self initializeFileNameToMimeTypeMapping. |
|
95 |
self initializeImageReaderMappings. |
|
96 |
self initializeCommentStringMappings. |
|
97 |
||
98 |
" |
|
99 |
self initialize |
|
100 |
" |
|
101 |
||
102 |
"Modified: / 19.11.1999 / 15:01:53 / cg" |
|
103 |
! |
|
104 |
||
105 |
initializeCommentStringMappings |
|
106 |
TypeToCommentStringMapping := Dictionary new. |
|
107 |
SuffixToCommentStringMapping := Dictionary new. |
|
108 |
||
109 |
TypeToCommentStringMapping |
|
110 |
at:'application/x-make' |
|
111 |
put:#('#' (nil nil)). "/ '#' for EOL comments only |
|
112 |
||
113 |
TypeToCommentStringMapping |
|
114 |
at:'application/x-sh' |
|
115 |
put:#('#' (nil nil)). "/ '#' for EOL comments only |
|
116 |
||
117 |
#('text/html' 'text/xml' 'application/xml') |
|
118 |
do:[:eachXMLType | |
|
119 |
TypeToCommentStringMapping |
|
120 |
at:eachXMLType |
|
121 |
put:#(nil ('<!!-- ' ' -->')). "/ '<!!-- ... -->' delimited comments only |
|
122 |
]. |
|
123 |
||
124 |
TypeToCommentStringMapping |
|
125 |
at:'application/x-batch-script' |
|
126 |
put:#('rem ' (nil nil)). "/ 'rem ' for EOL comments only |
|
127 |
||
128 |
"/ the following is ST/X specific |
|
129 |
TypeToCommentStringMapping |
|
130 |
at:'application/x-smalltalk-source' |
|
131 |
put:#('"/' ('"' '"')). "/ '"/ ' for EOL; ".." for delimited comments |
|
132 |
||
133 |
"/ this is for standard smalltalk |
|
134 |
"/ TypeToCommentStringMapping |
|
135 |
"/ at:'application/x-smalltalk-source' |
|
136 |
"/ put:#(nil ('"' '"')). "/ ".." for delimited comments only |
|
137 |
||
138 |
||
139 |
TypeToCommentStringMapping |
|
140 |
at:'application/x-pascal-source' |
|
141 |
put:#(nil ('{' '}')). "/ '{'..'}' for delimited comments |
|
142 |
||
143 |
"/ the following is k&r |
|
144 |
TypeToCommentStringMapping |
|
145 |
at:'application/x-c-source' |
|
146 |
put:#(nil ('/*' '*/')). "/ '/*'..'*/' for delimited comments |
|
147 |
||
148 |
"/ this is ANSI-c |
|
149 |
TypeToCommentStringMapping |
|
150 |
at:'application/x-c-source' |
|
151 |
put:#('//' ('/*' '*/')). |
|
152 |
||
153 |
TypeToCommentStringMapping |
|
154 |
at:'application/x-cpp-source' |
|
155 |
put:#('//' ('/*' '*/')). |
|
156 |
||
157 |
TypeToCommentStringMapping |
|
158 |
at:'application/x-java-source' |
|
159 |
put:#('//' ('/*' '*/')). |
|
160 |
||
161 |
TypeToCommentStringMapping |
|
162 |
at:'application/x-asn1-source' |
|
163 |
put:#('--' ('--' '--')). |
|
164 |
||
165 |
||
166 |
"/ st/x support files |
|
167 |
SuffixToCommentStringMapping |
|
168 |
at:'style' |
|
169 |
put:#(';' (nil nil)). |
|
1604 | 170 |
|
1729 | 171 |
SuffixToCommentStringMapping |
172 |
at:'rs' |
|
173 |
put:#(';' (nil nil)). |
|
174 |
! |
|
175 |
||
176 |
initializeDefaultCommands |
|
177 |
"TODO: move this to OS" |
|
178 |
||
179 |
|unixCommands win32Commands| |
|
180 |
||
181 |
DefaultCommandPerMIMEPerOS := Dictionary new. |
|
182 |
DefaultCommandPerMIMEPerOS at:#unix put:(unixCommands := Dictionary new). |
|
183 |
DefaultCommandPerMIMEPerOS at:#win32 put:(win32Commands := Dictionary new). |
|
184 |
||
185 |
unixCommands at:'application/x-tar-compressed' put:'gunzip < %1 | tar tvf -'. |
|
186 |
unixCommands at:'application/pdf' put:'acroread -display %2 %1'. |
|
187 |
||
188 |
" |
|
189 |
self initializeDefaultCommands |
|
190 |
" |
|
191 |
! |
|
192 |
||
193 |
initializeFileNameToMimeTypeMapping |
|
194 |
"initialize wellKnown facts" |
|
195 |
||
196 |
|types| |
|
197 |
||
198 |
FileSuffixToTypeMapping isNil ifTrue:[ |
|
199 |
FileSuffixToTypeMapping := Dictionary new |
|
200 |
]. |
|
201 |
FilenameToTypeMapping isNil ifTrue:[ |
|
202 |
FilenameToTypeMapping := Dictionary new. |
|
203 |
]. |
|
204 |
||
205 |
types := OrderedCollection new. |
|
206 |
types addAll:self textTypeList. |
|
207 |
types addAll:self imageTypeList. |
|
208 |
types addAll:self videoTypeList. |
|
209 |
types addAll:self audioTypeList. |
|
210 |
types addAll:self applicationTypeList. |
|
211 |
types pairWiseDo:[:suff :typeString| |
|
212 |
|type| |
|
213 |
||
214 |
type := MIMEType fromString:typeString. |
|
215 |
suff isArray ifTrue:[ |
|
216 |
suff do:[:s | FileSuffixToTypeMapping at:s put:type] |
|
217 |
] ifFalse:[ |
|
218 |
FileSuffixToTypeMapping at:suff put:type |
|
219 |
] |
|
220 |
]. |
|
221 |
||
222 |
self miscFilenameList pairWiseDo:[:nm :typeString| |
|
223 |
|type| |
|
224 |
||
225 |
type := MIMEType fromString:typeString. |
|
226 |
nm isArray ifTrue:[ |
|
227 |
nm do:[:s | FilenameToTypeMapping at:s put:type] |
|
228 |
] ifFalse:[ |
|
229 |
FilenameToTypeMapping at:nm put:type |
|
230 |
] |
|
231 |
]. |
|
232 |
! |
|
233 |
||
234 |
initializeImageReaderMappings |
|
235 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[ |
|
236 |
FileSuffixToImageReaderClassMapping := Dictionary new |
|
237 |
]. |
|
238 |
"MIME" TypeToImageReaderClassMapping isNil ifTrue:[ |
|
239 |
TypeToImageReaderClassMapping := Dictionary new |
|
240 |
]. |
|
241 |
||
242 |
"/ setup mimeType to image reader class mapping ... |
|
243 |
||
244 |
TypeToImageReaderClassMapping at:'image/jpeg' put:JPEGReader. |
|
245 |
TypeToImageReaderClassMapping at:'image/gif' put:GIFReader. |
|
246 |
TypeToImageReaderClassMapping at:'image/tiff' put:TIFFReader. |
|
247 |
||
248 |
"/ setup suffix to image reader class mapping ... |
|
249 |
||
250 |
FileSuffixToImageReaderClassMapping at:'jpg' put:JPEGReader. |
|
251 |
FileSuffixToImageReaderClassMapping at:'gif' put:GIFReader. |
|
252 |
FileSuffixToImageReaderClassMapping at:'tif' put:TIFFReader. |
|
253 |
! ! |
|
254 |
||
255 |
!MIMETypes class methodsFor:'initialization-lists'! |
|
256 |
||
257 |
applicationCompressorsAndArchiveTypeList |
|
1604 | 258 |
^ #( |
259 |
'tar' 'application/x-tar' |
|
260 |
'gtar' 'application/x-gtar' |
|
261 |
'tgz' 'application/x-tar-compressed' |
|
262 |
'zip' 'application/x-zip-compressed' |
|
263 |
('gz' 'z') 'application/x-gzip-compressed' |
|
264 |
'cpio' 'application/x-cpio' |
|
265 |
'shar' 'application/x-shar' |
|
266 |
'jar' 'application/java-archive' |
|
267 |
) |
|
268 |
! |
|
645 | 269 |
|
1609 | 270 |
applicationMiscTypeList |
271 |
"misc applications" |
|
272 |
||
273 |
^ #( |
|
274 |
('a' 'o' 'obj' ) 'application/binary' |
|
275 |
'a' 'application/library' |
|
276 |
('dll' 'so') 'application/shared-library' |
|
277 |
) |
|
278 |
! |
|
279 |
||
1604 | 280 |
applicationProgLangTypeList |
1606 | 281 |
"applications for programm languages" |
713 | 282 |
|
1604 | 283 |
^ #( |
1609 | 284 |
('st' 'cls' 'rc') 'application/x-smalltalk-source' |
1604 | 285 |
'sif' 'application/x-smalltalk-source-sif' |
1668 | 286 |
'pac' 'application/x-smalltalk-dolphin-package' |
1604 | 287 |
'c' 'application/x-c-source' |
288 |
('cc' 'cpp') 'application/x-cpp-source' |
|
1609 | 289 |
('h' 'hi') 'application/x-c-header' |
1604 | 290 |
('js' 'mocha') 'application/x-javascript' |
291 |
('java' 'jav') 'application/x-java-source' |
|
292 |
'sh' 'application/x-sh' |
|
293 |
'csh' 'application/x-csh' |
|
294 |
'tcl' 'application/x-tcl' |
|
295 |
'pl' 'application/x-perl' |
|
296 |
'mak' 'application/x-make' |
|
297 |
'bat' 'application/x-batch-script' |
|
298 |
('asn1' 'x409' 'gdmo' 'gdm') 'application/x-asn1-source' |
|
299 |
) |
|
300 |
! |
|
1561 | 301 |
|
1604 | 302 |
applicationTextTypeList |
1606 | 303 |
"text applications" |
1604 | 304 |
|
305 |
^ #( |
|
306 |
('ps' 'eps') 'application/postscript' |
|
307 |
'pdf' 'application/pdf' |
|
308 |
'rtf' 'application/rtf' |
|
309 |
'doc' 'application/winword' |
|
310 |
) |
|
311 |
! |
|
312 |
||
313 |
applicationTypeList |
|
1606 | 314 |
"applications" |
1604 | 315 |
|
1729 | 316 |
|typeList| |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
317 |
|
1729 | 318 |
typeList := OrderedCollection new. |
319 |
typeList addAll:self applicationProgLangTypeList. |
|
320 |
typeList addAll:self applicationTextTypeList. |
|
321 |
typeList addAll:self applicationCompressorsAndArchiveTypeList. |
|
322 |
typeList addAll:self applicationMiscTypeList. |
|
1616 | 323 |
|
1729 | 324 |
^ typeList |
1604 | 325 |
! |
326 |
||
327 |
audioTypeList |
|
1606 | 328 |
"audio formats ..." |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
329 |
|
1604 | 330 |
^ #( |
1720 | 331 |
('au' 'snd') 'audio/basic' |
1604 | 332 |
('ra' 'ram') 'audio/x-pn-realaudio' |
1680 | 333 |
'rpm' 'audio/x-pn-realaudio-plugin' |
1720 | 334 |
('mpa' 'mpega') 'audio/mpeg' |
1680 | 335 |
'mp3' 'audio/x-mp3' |
1604 | 336 |
'wav' 'audio/x-wav' |
337 |
('aif' 'aiff' 'aifc') 'audio/x-aiff' |
|
338 |
) |
|
339 |
! |
|
340 |
||
341 |
imageTypeList |
|
342 |
||
343 |
^ #( |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
344 |
"/ image formats ... |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
345 |
|
1216 | 346 |
('jpg' 'jpeg') 'image/jpeg' |
1188 | 347 |
'gif' 'image/gif' |
348 |
('tif' 'tiff') 'image/tiff' |
|
349 |
'xbm' 'image/x-xbitmap' |
|
350 |
'xpm' 'image/x-xpixmap' |
|
1720 | 351 |
'png' 'image/png' |
1188 | 352 |
'pcd' 'image/x-photo-cd' |
353 |
'bmp' 'image/x-MS-bmp' |
|
354 |
'rgb' 'image/x-rgb' |
|
355 |
'ppm' 'image/x-portable-pixmap' |
|
356 |
'pgm' 'image/x-portable-graymap' |
|
357 |
'pbm' 'image/x-portable-bitmap' |
|
358 |
'pnm' 'image/x-portable-anymap' |
|
359 |
'xwd' 'image/x-xwindowdump' |
|
360 |
'ras' 'image/x-cmu-raster' |
|
1216 | 361 |
'tga' 'image/x-targa' |
1604 | 362 |
) |
363 |
! |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
364 |
|
1609 | 365 |
miscFilenameList |
366 |
"other formats (not by suffix, but by fileName isnstead) ..." |
|
367 |
||
368 |
^ #( |
|
369 |
('makefile' 'make.proto') 'application/x-make' |
|
1681 | 370 |
'swf' 'application/x-shockwave-flash' |
1609 | 371 |
) |
372 |
! |
|
373 |
||
1604 | 374 |
textTypeList |
375 |
"/ misc text ... |
|
376 |
||
377 |
^ #( |
|
378 |
('htm' 'html') 'text/html' |
|
1680 | 379 |
'shtml' 'text/html' |
1604 | 380 |
('txt' 'text') 'text/plain' |
1680 | 381 |
'xml' 'text/xml' |
1604 | 382 |
) |
383 |
! |
|
384 |
||
385 |
videoTypeList |
|
386 |
"/ video formats ... |
|
387 |
||
388 |
^ #( |
|
1720 | 389 |
('qt' 'mov' 'moov') 'video/quicktime' |
390 |
('mpv' 'mpegv' 'mpg' 'mpeg' 'mpe') 'video/mpeg' |
|
1604 | 391 |
'movie' 'video/x-sgi-movie' |
392 |
'avi' 'video/x-msvideo' |
|
393 |
('mpv2' 'mp2v' 'mp2' 'mpeg2') 'video/x-mpeg2' |
|
1680 | 394 |
'rm' 'application/vnd.rn-realmedia' |
395 |
'rv' 'video/x-pn-realvideo' |
|
1604 | 396 |
) |
643 | 397 |
! ! |
398 |
||
1729 | 399 |
!MIMETypes class methodsFor:'obsolete'! |
1489 | 400 |
|
1729 | 401 |
fontForCharset:aCharSetName |
402 |
"return the font-encoding for an iso-charset" |
|
1489 | 403 |
|
1729 | 404 |
self obsoleteMethodWarning:'use FontDescription >> fontNamePatternForCharset:'. |
405 |
^ FontDescription fontNamePatternForCharset:aCharSetName. |
|
1489 | 406 |
|
407 |
" |
|
1729 | 408 |
MIMETypes fontForCharset:'iso2022-jp' |
409 |
MIMETypes fontForCharset:'euc-jp' |
|
1472 | 410 |
" |
411 |
||
1729 | 412 |
"Modified: / 1.8.1998 / 17:00:57 / cg" |
413 |
! ! |
|
1472 | 414 |
|
1729 | 415 |
!MIMETypes class methodsFor:'queries'! |
1472 | 416 |
|
1691
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
417 |
defaultCommandPerMIME |
1729 | 418 |
"TODO: move this to OS/UserPreferences" |
1691
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
419 |
|
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
420 |
DefaultCommandPerMIMEPerOS isNil ifTrue:[ |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
421 |
self initializeDefaultCommands |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
422 |
]. |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
423 |
OperatingSystem isUNIXlike ifTrue:[ |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
424 |
^ DefaultCommandPerMIMEPerOS at:#unix |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
425 |
]. |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
426 |
^ DefaultCommandPerMIMEPerOS at:#win32 |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
427 |
! |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
428 |
|
647 | 429 |
defineImageType:mimeType suffix:aSuffix reader:aReaderClass |
430 |
"register an image reader." |
|
431 |
||
432 |
aSuffix notNil ifTrue:[ |
|
433 |
self imageReaderForSuffix:aSuffix put:aReaderClass. |
|
434 |
]. |
|
435 |
||
436 |
mimeType notNil ifTrue:[ |
|
437 |
self imageReaderForType:mimeType put:aReaderClass |
|
438 |
]. |
|
439 |
||
440 |
(aSuffix notNil and:[mimeType notNil]) ifTrue:[ |
|
441 |
self mimeTypeForSuffix:aSuffix put:mimeType |
|
442 |
]. |
|
443 |
! |
|
444 |
||
643 | 445 |
fileSuffixToImageReaderMapping |
1021 | 446 |
"return the suffix-to-imageReader mapping" |
447 |
||
643 | 448 |
^ FileSuffixToImageReaderClassMapping ? #() |
449 |
||
1021 | 450 |
"Modified: / 1.8.1998 / 17:00:11 / cg" |
643 | 451 |
! |
452 |
||
453 |
imageFileSuffixes |
|
1021 | 454 |
"return a collection with known file suffixes" |
455 |
||
643 | 456 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[^ #()]. |
457 |
^ FileSuffixToImageReaderClassMapping keys |
|
458 |
||
1021 | 459 |
"Created: / 30.6.1997 / 22:04:48 / cg" |
460 |
"Modified: / 1.8.1998 / 17:01:26 / cg" |
|
643 | 461 |
! |
462 |
||
1473 | 463 |
mimeTypeForFilename:filenameArg |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
464 |
"given a filename, return the mime-type or nil, if unknown" |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
465 |
|
1473 | 466 |
|type filename lcFilename suff| |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
467 |
|
1473 | 468 |
filename := filenameArg asFilename. |
1474 | 469 |
|
470 |
lcFilename := filename baseName asLowercase. |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
471 |
type := FilenameToTypeMapping at:lcFilename ifAbsent:nil. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
472 |
type isNil ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
473 |
"/ allow for fallback ... |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
474 |
type := OperatingSystem mimeTypeForFilename:lcFilename. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
475 |
"/ the special value #unknown is returned as nil; |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
476 |
"/ this avoids constant retry if a mimeType is not known in |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
477 |
"/ the OS. |
1275 | 478 |
"/ type isNil ifTrue:[ |
479 |
"/ FilenameToTypeMapping at:lcFilename put:#unknown |
|
480 |
"/ ]. |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
481 |
]. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
482 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
483 |
type == #unknown ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
484 |
type := nil. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
485 |
]. |
1273
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
486 |
|
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
487 |
type isNil ifTrue:[ |
1473 | 488 |
suff := filename suffix. |
1273
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
489 |
suff size ~~ 0 ifTrue:[ |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
490 |
^ self mimeTypeForSuffix:suff |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
491 |
] |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
492 |
]. |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
493 |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
494 |
^ type |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
495 |
! |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
496 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
497 |
mimeTypeForFilename:filename put:mimeType |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
498 |
"register a mime type for a filename" |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
499 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
500 |
FilenameToTypeMapping isNil ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
501 |
FilenameToTypeMapping := Dictionary new |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
502 |
]. |
1612 | 503 |
FilenameToTypeMapping at:filename put:(MIMEType fromString:mimeType asLowercase) |
1611 | 504 |
! |
505 |
||
643 | 506 |
mimeTypeForSuffix:suffix |
1021 | 507 |
"given a file suffix, return the mime-type" |
508 |
||
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
509 |
|type lcSuffix| |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
510 |
|
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
511 |
lcSuffix := suffix asLowercase. |
1300 | 512 |
lcSuffix = LastSuffix ifTrue:[ |
513 |
type := LastType |
|
514 |
] ifFalse:[ |
|
515 |
type := FileSuffixToTypeMapping at:lcSuffix ifAbsent:nil. |
|
516 |
type isNil ifTrue:[ |
|
517 |
"/ allow for fallback ... |
|
518 |
type := OperatingSystem mimeTypeForSuffix:lcSuffix. |
|
519 |
"/ the special value #unknown is returned as nil; |
|
520 |
"/ this avoids constant retry if a mimeType is not known in |
|
521 |
"/ the OS. |
|
522 |
"/ type isNil ifTrue:[ |
|
523 |
"/ FileSuffixToTypeMapping at:lcSuffix put:#unknown |
|
524 |
"/ ]. |
|
525 |
]. |
|
526 |
LastSuffix := lcSuffix. |
|
527 |
LastType := type. |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
528 |
]. |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
529 |
type == #unknown ifTrue:[ |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
530 |
type := nil |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
531 |
]. |
1612 | 532 |
type notNil ifTrue:[ |
533 |
^ MIMEType fromString:type |
|
534 |
]. |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
535 |
^ type |
643 | 536 |
|
1666 | 537 |
" |
538 |
self mimeTypeForSuffix:'xml' |
|
539 |
" |
|
540 |
||
1021 | 541 |
"Created: / 30.6.1997 / 21:55:51 / cg" |
1300 | 542 |
"Modified: / 23.12.1999 / 22:30:55 / cg" |
643 | 543 |
! |
544 |
||
545 |
mimeTypeForSuffix:suffix put:mimeType |
|
1021 | 546 |
"register a mime type for a file suffix" |
547 |
||
643 | 548 |
FileSuffixToTypeMapping isNil ifTrue:[ |
549 |
FileSuffixToTypeMapping := Dictionary new |
|
550 |
]. |
|
551 |
FileSuffixToTypeMapping at:suffix put:mimeType asLowercase |
|
552 |
||
1021 | 553 |
"Created: / 30.6.1997 / 21:56:20 / cg" |
554 |
"Modified: / 1.8.1998 / 17:03:18 / cg" |
|
1593 | 555 |
! |
556 |
||
557 |
mimeTypeForSuffixMapping |
|
558 |
||
559 |
^ FileSuffixToTypeMapping |
|
1611 | 560 |
! |
561 |
||
562 |
mimeTypeOfContents:filename |
|
563 |
"given a filename, scan the contents, return the mime-type or nil, if unknown" |
|
564 |
||
1612 | 565 |
|typeString| |
566 |
||
567 |
typeString := filename mimeTypeOfContents. |
|
568 |
typeString isNil ifTrue:[^ nil]. |
|
569 |
^ MIMEType fromString:typeString. |
|
570 |
! ! |
|
571 |
||
1729 | 572 |
!MIMETypes class methodsFor:'queries-image formats'! |
573 |
||
574 |
imageReaderClasses |
|
575 |
"return a collection of registered image reader classes" |
|
576 |
||
577 |
|setOfClasses| |
|
578 |
||
579 |
setOfClasses := IdentitySet new. |
|
580 |
FileSuffixToImageReaderClassMapping notNil ifTrue:[ |
|
581 |
FileSuffixToImageReaderClassMapping keysAndValuesDo:[:suff :cls | |
|
582 |
setOfClasses add:cls |
|
583 |
]. |
|
584 |
]. |
|
585 |
TypeToImageReaderClassMapping notNil ifTrue:[ |
|
586 |
TypeToImageReaderClassMapping keysAndValuesDo:[:suff :cls | |
|
587 |
setOfClasses add:cls |
|
588 |
]. |
|
589 |
]. |
|
590 |
^ setOfClasses |
|
591 |
||
592 |
"Created: / 30.6.1997 / 22:03:42 / cg" |
|
593 |
"Modified: / 1.8.1998 / 16:59:52 / cg" |
|
594 |
! |
|
595 |
||
596 |
imageReaderForSuffix:aSuffix |
|
597 |
"given a file suffix, return an approriate image reader class" |
|
598 |
||
599 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[^ nil]. |
|
600 |
^ FileSuffixToImageReaderClassMapping at:aSuffix asLowercase ifAbsent:nil |
|
601 |
||
602 |
"Created: / 30.6.1997 / 21:59:11 / cg" |
|
603 |
"Modified: / 1.8.1998 / 17:01:58 / cg" |
|
604 |
! |
|
605 |
||
606 |
imageReaderForSuffix:aSuffix put:aReaderClass |
|
607 |
"register an image reader for a file suffix" |
|
608 |
||
609 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[ |
|
610 |
FileSuffixToImageReaderClassMapping := Dictionary new. |
|
611 |
]. |
|
612 |
FileSuffixToImageReaderClassMapping at:aSuffix asLowercase put:aReaderClass |
|
613 |
||
614 |
"Created: / 30.6.1997 / 21:59:43 / cg" |
|
615 |
"Modified: / 1.8.1998 / 17:02:14 / cg" |
|
616 |
! |
|
617 |
||
618 |
imageReaderForType:mimeTypeString |
|
619 |
"given a mime-type, return an approriate image reader class" |
|
620 |
||
621 |
TypeToImageReaderClassMapping isNil ifTrue:[^ nil]. |
|
622 |
^ TypeToImageReaderClassMapping at:mimeTypeString asLowercase ifAbsent:nil |
|
623 |
||
624 |
"Created: / 30.6.1997 / 21:56:01 / cg" |
|
625 |
"Modified: / 1.8.1998 / 17:02:28 / cg" |
|
626 |
! |
|
627 |
||
628 |
imageReaderForType:mimeTypeString put:aReaderClass |
|
629 |
"register an image reader for a mime-type" |
|
630 |
||
631 |
TypeToImageReaderClassMapping isNil ifTrue:[ |
|
632 |
TypeToImageReaderClassMapping := Dictionary new. |
|
633 |
]. |
|
634 |
TypeToImageReaderClassMapping at:mimeTypeString asLowercase put:aReaderClass |
|
635 |
||
636 |
"Created: / 30.6.1997 / 21:56:11 / cg" |
|
637 |
"Modified: / 1.8.1998 / 17:02:40 / cg" |
|
638 |
! ! |
|
639 |
||
640 |
!MIMETypes class methodsFor:'queries-language syntax'! |
|
641 |
||
642 |
commentStringsForFilename:aFilename |
|
643 |
"return a useful comment definition; heuristics for now. |
|
644 |
The returned value is an array of 2 elements; |
|
645 |
the first is the end-of-line comment string (or nil); |
|
646 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
647 |
||
648 |
|mime| |
|
649 |
||
650 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
651 |
^ self commentStringsForMimeType:mime suffix:(aFilename asFilename suffix) |
|
652 |
||
653 |
" |
|
654 |
MIMETypes commentStringsForFilename:'Makefile'. |
|
655 |
MIMETypes commentStringsForFilename:'Object.st'. |
|
656 |
MIMETypes commentStringsForFilename:'Foo.java'. |
|
657 |
" |
|
658 |
! |
|
659 |
||
660 |
commentStringsForFilename:aFilename ifUnknown:alternativeBlockReturningCommentString |
|
661 |
"return a useful comment definition; heuristics for now. |
|
662 |
The returned value is an array of 2 elements; |
|
663 |
the first is the end-of-line comment string (or nil); |
|
664 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
665 |
||
666 |
|mime| |
|
667 |
||
668 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
669 |
^ self commentStringsForMimeType:mime suffix:(aFilename asFilename suffix) ifUnknown:alternativeBlockReturningCommentString |
|
670 |
||
671 |
" |
|
672 |
MIMETypes commentStringsForFilename:'Makefile'. |
|
673 |
MIMETypes commentStringsForFilename:'Object.st'. |
|
674 |
MIMETypes commentStringsForFilename:'Foo.java'. |
|
675 |
" |
|
676 |
! |
|
677 |
||
678 |
commentStringsForMimeType:mime suffix:suff |
|
679 |
"return a useful comment definition; heuristics for now. |
|
680 |
The returned value is an array of 2 elements; |
|
681 |
the first is the end-of-line comment string (or nil); |
|
682 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
683 |
||
684 |
^ self |
|
685 |
commentStringsForMimeType:mime suffix:suff |
|
686 |
ifUnknown: #(';' (nil nil)) |
|
687 |
||
688 |
" |
|
689 |
|mime| |
|
690 |
||
691 |
mime := MIMETypes mimeTypeForFilename:'Makefile'. |
|
692 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
693 |
" |
|
694 |
||
695 |
" |
|
696 |
|mime| |
|
697 |
||
698 |
mime := MIMETypes mimeTypeForFilename:'Object.st'. |
|
699 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
700 |
" |
|
701 |
! |
|
702 |
||
703 |
commentStringsForMimeType:mime suffix:suff ifUnknown:alternativeBlockReturningCommentString |
|
704 |
"return a useful comment definition; heuristics for now. |
|
705 |
The returned value is an array of 2 elements; |
|
706 |
the first is the end-of-line comment string (or nil); |
|
707 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
708 |
||
709 |
|commentSpec| |
|
710 |
||
711 |
commentSpec := TypeToCommentStringMapping at:mime ifAbsent:nil. |
|
712 |
commentSpec notNil ifTrue:[ |
|
713 |
^ commentSpec |
|
714 |
]. |
|
715 |
||
716 |
commentSpec := SuffixToCommentStringMapping at:suff ifAbsent:nil. |
|
717 |
commentSpec notNil ifTrue:[ |
|
718 |
^ commentSpec |
|
719 |
]. |
|
720 |
||
721 |
^ alternativeBlockReturningCommentString value |
|
722 |
||
723 |
" |
|
724 |
|mime| |
|
725 |
||
726 |
mime := MIMETypes mimeTypeForFilename:'Makefile'. |
|
727 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
728 |
" |
|
729 |
||
730 |
" |
|
731 |
|mime| |
|
732 |
||
733 |
mime := MIMETypes mimeTypeForFilename:'Object.st'. |
|
734 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
735 |
" |
|
736 |
! ! |
|
737 |
||
1612 | 738 |
!MIMETypes::MIMEType class methodsFor:'documentation'! |
739 |
||
740 |
documentation |
|
741 |
" |
|
742 |
like a string, but knows that it represents a mimeType |
|
743 |
" |
|
744 |
! ! |
|
745 |
||
746 |
!MIMETypes::MIMEType class methodsFor:'initialization'! |
|
747 |
||
748 |
initialize |
|
749 |
CachedTypes := CacheDictionary new:30. |
|
750 |
||
751 |
" |
|
752 |
self initialize |
|
753 |
" |
|
754 |
! ! |
|
755 |
||
756 |
!MIMETypes::MIMEType class methodsFor:'instance creation'! |
|
757 |
||
758 |
fromString:aString |
|
759 |
|cachedType newType| |
|
760 |
||
761 |
aString class == self ifTrue:[^ aString]. |
|
762 |
||
763 |
cachedType := CachedTypes at:aString ifAbsent:nil. |
|
764 |
cachedType notNil ifTrue:[^ cachedType]. |
|
765 |
newType := aString copy changeClassTo:self. |
|
766 |
CachedTypes at:aString put:newType. |
|
767 |
^ newType |
|
768 |
||
769 |
" |
|
770 |
self fromString:'text/html' |
|
771 |
" |
|
772 |
! ! |
|
773 |
||
774 |
!MIMETypes::MIMEType methodsFor:'queries'! |
|
775 |
||
1693 | 776 |
isArchive |
1612 | 777 |
|archivTypes| |
778 |
||
1729 | 779 |
archivTypes := MIMETypes applicationCompressorsAndArchiveTypeList. |
1612 | 780 |
archivTypes pairWiseDo:[: ext : type | |
781 |
self = type ifTrue:[ ^ true]. |
|
782 |
]. |
|
783 |
^ false |
|
784 |
! |
|
785 |
||
786 |
isHtml |
|
787 |
||
788 |
^ (self = 'text/html') |
|
789 |
! |
|
790 |
||
791 |
isImage |
|
792 |
||
1693 | 793 |
^ (self startsWith:'image/') |
1612 | 794 |
! |
795 |
||
796 |
isPdf |
|
797 |
^ (self = 'application/pdf') |
|
798 |
! |
|
799 |
||
800 |
isSmalltalkSource |
|
801 |
^ (self = 'application/x-smalltalk-source') |
|
643 | 802 |
! ! |
803 |
||
804 |
!MIMETypes class methodsFor:'documentation'! |
|
805 |
||
806 |
version |
|
1729 | 807 |
^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.52 2003-03-28 11:30:35 cg Exp $' |
643 | 808 |
! ! |
1666 | 809 |
|
643 | 810 |
MIMETypes initialize! |
1666 | 811 |
MIMETypes::MIMEType initialize! |