author | Claus Gittinger <cg@exept.de> |
Mon, 19 May 2003 22:18:02 +0200 | |
changeset 1777 | 5879ec563fc1 |
parent 1775 | cce9dce012ce |
child 1778 | 6a019cc68896 |
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' |
|
1775 | 267 |
'sar' 'application/x-squeak-archive' |
1604 | 268 |
) |
269 |
! |
|
645 | 270 |
|
1609 | 271 |
applicationMiscTypeList |
272 |
"misc applications" |
|
273 |
||
274 |
^ #( |
|
275 |
('a' 'o' 'obj' ) 'application/binary' |
|
276 |
'a' 'application/library' |
|
277 |
('dll' 'so') 'application/shared-library' |
|
278 |
) |
|
279 |
! |
|
280 |
||
1604 | 281 |
applicationProgLangTypeList |
1606 | 282 |
"applications for programm languages" |
713 | 283 |
|
1604 | 284 |
^ #( |
1609 | 285 |
('st' 'cls' 'rc') 'application/x-smalltalk-source' |
1604 | 286 |
'sif' 'application/x-smalltalk-source-sif' |
1668 | 287 |
'pac' 'application/x-smalltalk-dolphin-package' |
1604 | 288 |
'c' 'application/x-c-source' |
289 |
('cc' 'cpp') 'application/x-cpp-source' |
|
1609 | 290 |
('h' 'hi') 'application/x-c-header' |
1604 | 291 |
('js' 'mocha') 'application/x-javascript' |
292 |
('java' 'jav') 'application/x-java-source' |
|
293 |
'sh' 'application/x-sh' |
|
294 |
'csh' 'application/x-csh' |
|
295 |
'tcl' 'application/x-tcl' |
|
296 |
'pl' 'application/x-perl' |
|
297 |
'mak' 'application/x-make' |
|
298 |
'bat' 'application/x-batch-script' |
|
299 |
('asn1' 'x409' 'gdmo' 'gdm') 'application/x-asn1-source' |
|
300 |
) |
|
301 |
! |
|
1561 | 302 |
|
1604 | 303 |
applicationTextTypeList |
1606 | 304 |
"text applications" |
1604 | 305 |
|
306 |
^ #( |
|
307 |
('ps' 'eps') 'application/postscript' |
|
308 |
'pdf' 'application/pdf' |
|
309 |
'rtf' 'application/rtf' |
|
310 |
'doc' 'application/winword' |
|
311 |
) |
|
312 |
! |
|
313 |
||
314 |
applicationTypeList |
|
1606 | 315 |
"applications" |
1604 | 316 |
|
1729 | 317 |
|typeList| |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
318 |
|
1729 | 319 |
typeList := OrderedCollection new. |
320 |
typeList addAll:self applicationProgLangTypeList. |
|
321 |
typeList addAll:self applicationTextTypeList. |
|
322 |
typeList addAll:self applicationCompressorsAndArchiveTypeList. |
|
323 |
typeList addAll:self applicationMiscTypeList. |
|
1616 | 324 |
|
1729 | 325 |
^ typeList |
1604 | 326 |
! |
327 |
||
328 |
audioTypeList |
|
1606 | 329 |
"audio formats ..." |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
330 |
|
1604 | 331 |
^ #( |
1720 | 332 |
('au' 'snd') 'audio/basic' |
1604 | 333 |
('ra' 'ram') 'audio/x-pn-realaudio' |
1680 | 334 |
'rpm' 'audio/x-pn-realaudio-plugin' |
1720 | 335 |
('mpa' 'mpega') 'audio/mpeg' |
1680 | 336 |
'mp3' 'audio/x-mp3' |
1604 | 337 |
'wav' 'audio/x-wav' |
338 |
('aif' 'aiff' 'aifc') 'audio/x-aiff' |
|
339 |
) |
|
340 |
! |
|
341 |
||
342 |
imageTypeList |
|
343 |
||
344 |
^ #( |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
345 |
"/ image formats ... |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
346 |
|
1216 | 347 |
('jpg' 'jpeg') 'image/jpeg' |
1188 | 348 |
'gif' 'image/gif' |
349 |
('tif' 'tiff') 'image/tiff' |
|
350 |
'xbm' 'image/x-xbitmap' |
|
351 |
'xpm' 'image/x-xpixmap' |
|
1720 | 352 |
'png' 'image/png' |
1188 | 353 |
'pcd' 'image/x-photo-cd' |
354 |
'bmp' 'image/x-MS-bmp' |
|
355 |
'rgb' 'image/x-rgb' |
|
356 |
'ppm' 'image/x-portable-pixmap' |
|
357 |
'pgm' 'image/x-portable-graymap' |
|
358 |
'pbm' 'image/x-portable-bitmap' |
|
359 |
'pnm' 'image/x-portable-anymap' |
|
360 |
'xwd' 'image/x-xwindowdump' |
|
361 |
'ras' 'image/x-cmu-raster' |
|
1216 | 362 |
'tga' 'image/x-targa' |
1604 | 363 |
) |
364 |
! |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
365 |
|
1609 | 366 |
miscFilenameList |
367 |
"other formats (not by suffix, but by fileName isnstead) ..." |
|
368 |
||
369 |
^ #( |
|
370 |
('makefile' 'make.proto') 'application/x-make' |
|
1681 | 371 |
'swf' 'application/x-shockwave-flash' |
1609 | 372 |
) |
373 |
! |
|
374 |
||
1604 | 375 |
textTypeList |
376 |
"/ misc text ... |
|
377 |
||
378 |
^ #( |
|
379 |
('htm' 'html') 'text/html' |
|
1680 | 380 |
'shtml' 'text/html' |
1604 | 381 |
('txt' 'text') 'text/plain' |
1680 | 382 |
'xml' 'text/xml' |
1777 | 383 |
'css' 'text/css' |
1604 | 384 |
) |
385 |
! |
|
386 |
||
387 |
videoTypeList |
|
388 |
"/ video formats ... |
|
389 |
||
390 |
^ #( |
|
1720 | 391 |
('qt' 'mov' 'moov') 'video/quicktime' |
392 |
('mpv' 'mpegv' 'mpg' 'mpeg' 'mpe') 'video/mpeg' |
|
1604 | 393 |
'movie' 'video/x-sgi-movie' |
394 |
'avi' 'video/x-msvideo' |
|
395 |
('mpv2' 'mp2v' 'mp2' 'mpeg2') 'video/x-mpeg2' |
|
1680 | 396 |
'rm' 'application/vnd.rn-realmedia' |
397 |
'rv' 'video/x-pn-realvideo' |
|
1604 | 398 |
) |
643 | 399 |
! ! |
400 |
||
1729 | 401 |
!MIMETypes class methodsFor:'obsolete'! |
1489 | 402 |
|
1729 | 403 |
fontForCharset:aCharSetName |
404 |
"return the font-encoding for an iso-charset" |
|
1489 | 405 |
|
1729 | 406 |
self obsoleteMethodWarning:'use FontDescription >> fontNamePatternForCharset:'. |
407 |
^ FontDescription fontNamePatternForCharset:aCharSetName. |
|
1489 | 408 |
|
409 |
" |
|
1729 | 410 |
MIMETypes fontForCharset:'iso2022-jp' |
411 |
MIMETypes fontForCharset:'euc-jp' |
|
1472 | 412 |
" |
413 |
||
1729 | 414 |
"Modified: / 1.8.1998 / 17:00:57 / cg" |
415 |
! ! |
|
1472 | 416 |
|
1729 | 417 |
!MIMETypes class methodsFor:'queries'! |
1472 | 418 |
|
1691
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
419 |
defaultCommandPerMIME |
1729 | 420 |
"TODO: move this to OS/UserPreferences" |
1691
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
421 |
|
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
422 |
DefaultCommandPerMIMEPerOS isNil ifTrue:[ |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
423 |
self initializeDefaultCommands |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
424 |
]. |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
425 |
OperatingSystem isUNIXlike ifTrue:[ |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
426 |
^ DefaultCommandPerMIMEPerOS at:#unix |
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 |
^ DefaultCommandPerMIMEPerOS at:#win32 |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
429 |
! |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
430 |
|
647 | 431 |
defineImageType:mimeType suffix:aSuffix reader:aReaderClass |
432 |
"register an image reader." |
|
433 |
||
434 |
aSuffix notNil ifTrue:[ |
|
435 |
self imageReaderForSuffix:aSuffix put:aReaderClass. |
|
436 |
]. |
|
437 |
||
438 |
mimeType notNil ifTrue:[ |
|
439 |
self imageReaderForType:mimeType put:aReaderClass |
|
440 |
]. |
|
441 |
||
442 |
(aSuffix notNil and:[mimeType notNil]) ifTrue:[ |
|
443 |
self mimeTypeForSuffix:aSuffix put:mimeType |
|
444 |
]. |
|
445 |
! |
|
446 |
||
643 | 447 |
fileSuffixToImageReaderMapping |
1021 | 448 |
"return the suffix-to-imageReader mapping" |
449 |
||
643 | 450 |
^ FileSuffixToImageReaderClassMapping ? #() |
451 |
||
1021 | 452 |
"Modified: / 1.8.1998 / 17:00:11 / cg" |
643 | 453 |
! |
454 |
||
455 |
imageFileSuffixes |
|
1021 | 456 |
"return a collection with known file suffixes" |
457 |
||
643 | 458 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[^ #()]. |
459 |
^ FileSuffixToImageReaderClassMapping keys |
|
460 |
||
1021 | 461 |
"Created: / 30.6.1997 / 22:04:48 / cg" |
462 |
"Modified: / 1.8.1998 / 17:01:26 / cg" |
|
643 | 463 |
! |
464 |
||
1473 | 465 |
mimeTypeForFilename:filenameArg |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
466 |
"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
|
467 |
|
1473 | 468 |
|type filename lcFilename suff| |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
469 |
|
1473 | 470 |
filename := filenameArg asFilename. |
1474 | 471 |
|
472 |
lcFilename := filename baseName asLowercase. |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
473 |
type := FilenameToTypeMapping at:lcFilename ifAbsent:nil. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
474 |
type isNil ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
475 |
"/ allow for fallback ... |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
476 |
type := OperatingSystem mimeTypeForFilename:lcFilename. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
477 |
"/ 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
|
478 |
"/ 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
|
479 |
"/ the OS. |
1275 | 480 |
"/ type isNil ifTrue:[ |
481 |
"/ FilenameToTypeMapping at:lcFilename put:#unknown |
|
482 |
"/ ]. |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
483 |
]. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
484 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
485 |
type == #unknown ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
486 |
type := nil. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
487 |
]. |
1273
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
488 |
|
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
489 |
type isNil ifTrue:[ |
1473 | 490 |
suff := filename suffix. |
1273
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
491 |
suff size ~~ 0 ifTrue:[ |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
492 |
^ self mimeTypeForSuffix:suff |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
493 |
] |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
494 |
]. |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
495 |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
496 |
^ type |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
497 |
! |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
498 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
499 |
mimeTypeForFilename:filename put:mimeType |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
500 |
"register a mime type for a filename" |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
501 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
502 |
FilenameToTypeMapping isNil ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
503 |
FilenameToTypeMapping := Dictionary new |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
504 |
]. |
1612 | 505 |
FilenameToTypeMapping at:filename put:(MIMEType fromString:mimeType asLowercase) |
1611 | 506 |
! |
507 |
||
643 | 508 |
mimeTypeForSuffix:suffix |
1021 | 509 |
"given a file suffix, return the mime-type" |
510 |
||
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
511 |
|type lcSuffix| |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
512 |
|
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
513 |
lcSuffix := suffix asLowercase. |
1300 | 514 |
lcSuffix = LastSuffix ifTrue:[ |
515 |
type := LastType |
|
516 |
] ifFalse:[ |
|
517 |
type := FileSuffixToTypeMapping at:lcSuffix ifAbsent:nil. |
|
518 |
type isNil ifTrue:[ |
|
519 |
"/ allow for fallback ... |
|
520 |
type := OperatingSystem mimeTypeForSuffix:lcSuffix. |
|
521 |
"/ the special value #unknown is returned as nil; |
|
522 |
"/ this avoids constant retry if a mimeType is not known in |
|
523 |
"/ the OS. |
|
524 |
"/ type isNil ifTrue:[ |
|
525 |
"/ FileSuffixToTypeMapping at:lcSuffix put:#unknown |
|
526 |
"/ ]. |
|
527 |
]. |
|
528 |
LastSuffix := lcSuffix. |
|
529 |
LastType := type. |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
530 |
]. |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
531 |
type == #unknown ifTrue:[ |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
532 |
type := nil |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
533 |
]. |
1612 | 534 |
type notNil ifTrue:[ |
535 |
^ MIMEType fromString:type |
|
536 |
]. |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
537 |
^ type |
643 | 538 |
|
1666 | 539 |
" |
540 |
self mimeTypeForSuffix:'xml' |
|
541 |
" |
|
542 |
||
1021 | 543 |
"Created: / 30.6.1997 / 21:55:51 / cg" |
1300 | 544 |
"Modified: / 23.12.1999 / 22:30:55 / cg" |
643 | 545 |
! |
546 |
||
547 |
mimeTypeForSuffix:suffix put:mimeType |
|
1021 | 548 |
"register a mime type for a file suffix" |
549 |
||
643 | 550 |
FileSuffixToTypeMapping isNil ifTrue:[ |
551 |
FileSuffixToTypeMapping := Dictionary new |
|
552 |
]. |
|
553 |
FileSuffixToTypeMapping at:suffix put:mimeType asLowercase |
|
554 |
||
1021 | 555 |
"Created: / 30.6.1997 / 21:56:20 / cg" |
556 |
"Modified: / 1.8.1998 / 17:03:18 / cg" |
|
1593 | 557 |
! |
558 |
||
559 |
mimeTypeForSuffixMapping |
|
560 |
||
561 |
^ FileSuffixToTypeMapping |
|
1611 | 562 |
! |
563 |
||
564 |
mimeTypeOfContents:filename |
|
565 |
"given a filename, scan the contents, return the mime-type or nil, if unknown" |
|
566 |
||
1612 | 567 |
|typeString| |
568 |
||
569 |
typeString := filename mimeTypeOfContents. |
|
570 |
typeString isNil ifTrue:[^ nil]. |
|
571 |
^ MIMEType fromString:typeString. |
|
572 |
! ! |
|
573 |
||
1729 | 574 |
!MIMETypes class methodsFor:'queries-image formats'! |
575 |
||
576 |
imageReaderClasses |
|
577 |
"return a collection of registered image reader classes" |
|
578 |
||
579 |
|setOfClasses| |
|
580 |
||
581 |
setOfClasses := IdentitySet new. |
|
582 |
FileSuffixToImageReaderClassMapping notNil ifTrue:[ |
|
583 |
FileSuffixToImageReaderClassMapping keysAndValuesDo:[:suff :cls | |
|
584 |
setOfClasses add:cls |
|
585 |
]. |
|
586 |
]. |
|
587 |
TypeToImageReaderClassMapping notNil ifTrue:[ |
|
588 |
TypeToImageReaderClassMapping keysAndValuesDo:[:suff :cls | |
|
589 |
setOfClasses add:cls |
|
590 |
]. |
|
591 |
]. |
|
592 |
^ setOfClasses |
|
593 |
||
594 |
"Created: / 30.6.1997 / 22:03:42 / cg" |
|
595 |
"Modified: / 1.8.1998 / 16:59:52 / cg" |
|
596 |
! |
|
597 |
||
598 |
imageReaderForSuffix:aSuffix |
|
599 |
"given a file suffix, return an approriate image reader class" |
|
600 |
||
601 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[^ nil]. |
|
602 |
^ FileSuffixToImageReaderClassMapping at:aSuffix asLowercase ifAbsent:nil |
|
603 |
||
604 |
"Created: / 30.6.1997 / 21:59:11 / cg" |
|
605 |
"Modified: / 1.8.1998 / 17:01:58 / cg" |
|
606 |
! |
|
607 |
||
608 |
imageReaderForSuffix:aSuffix put:aReaderClass |
|
609 |
"register an image reader for a file suffix" |
|
610 |
||
611 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[ |
|
612 |
FileSuffixToImageReaderClassMapping := Dictionary new. |
|
613 |
]. |
|
614 |
FileSuffixToImageReaderClassMapping at:aSuffix asLowercase put:aReaderClass |
|
615 |
||
616 |
"Created: / 30.6.1997 / 21:59:43 / cg" |
|
617 |
"Modified: / 1.8.1998 / 17:02:14 / cg" |
|
618 |
! |
|
619 |
||
620 |
imageReaderForType:mimeTypeString |
|
621 |
"given a mime-type, return an approriate image reader class" |
|
622 |
||
623 |
TypeToImageReaderClassMapping isNil ifTrue:[^ nil]. |
|
624 |
^ TypeToImageReaderClassMapping at:mimeTypeString asLowercase ifAbsent:nil |
|
625 |
||
626 |
"Created: / 30.6.1997 / 21:56:01 / cg" |
|
627 |
"Modified: / 1.8.1998 / 17:02:28 / cg" |
|
628 |
! |
|
629 |
||
630 |
imageReaderForType:mimeTypeString put:aReaderClass |
|
631 |
"register an image reader for a mime-type" |
|
632 |
||
633 |
TypeToImageReaderClassMapping isNil ifTrue:[ |
|
634 |
TypeToImageReaderClassMapping := Dictionary new. |
|
635 |
]. |
|
636 |
TypeToImageReaderClassMapping at:mimeTypeString asLowercase put:aReaderClass |
|
637 |
||
638 |
"Created: / 30.6.1997 / 21:56:11 / cg" |
|
639 |
"Modified: / 1.8.1998 / 17:02:40 / cg" |
|
640 |
! ! |
|
641 |
||
642 |
!MIMETypes class methodsFor:'queries-language syntax'! |
|
643 |
||
644 |
commentStringsForFilename:aFilename |
|
645 |
"return a useful comment definition; heuristics for now. |
|
646 |
The returned value is an array of 2 elements; |
|
647 |
the first is the end-of-line comment string (or nil); |
|
648 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
649 |
||
650 |
|mime| |
|
651 |
||
652 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
653 |
^ self commentStringsForMimeType:mime suffix:(aFilename asFilename suffix) |
|
654 |
||
655 |
" |
|
656 |
MIMETypes commentStringsForFilename:'Makefile'. |
|
657 |
MIMETypes commentStringsForFilename:'Object.st'. |
|
658 |
MIMETypes commentStringsForFilename:'Foo.java'. |
|
659 |
" |
|
660 |
! |
|
661 |
||
662 |
commentStringsForFilename:aFilename ifUnknown:alternativeBlockReturningCommentString |
|
663 |
"return a useful comment definition; heuristics for now. |
|
664 |
The returned value is an array of 2 elements; |
|
665 |
the first is the end-of-line comment string (or nil); |
|
666 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
667 |
||
668 |
|mime| |
|
669 |
||
670 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
671 |
^ self commentStringsForMimeType:mime suffix:(aFilename asFilename suffix) ifUnknown:alternativeBlockReturningCommentString |
|
672 |
||
673 |
" |
|
674 |
MIMETypes commentStringsForFilename:'Makefile'. |
|
675 |
MIMETypes commentStringsForFilename:'Object.st'. |
|
676 |
MIMETypes commentStringsForFilename:'Foo.java'. |
|
677 |
" |
|
678 |
! |
|
679 |
||
680 |
commentStringsForMimeType:mime suffix:suff |
|
681 |
"return a useful comment definition; heuristics for now. |
|
682 |
The returned value is an array of 2 elements; |
|
683 |
the first is the end-of-line comment string (or nil); |
|
684 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
685 |
||
686 |
^ self |
|
687 |
commentStringsForMimeType:mime suffix:suff |
|
688 |
ifUnknown: #(';' (nil nil)) |
|
689 |
||
690 |
" |
|
691 |
|mime| |
|
692 |
||
693 |
mime := MIMETypes mimeTypeForFilename:'Makefile'. |
|
694 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
695 |
" |
|
696 |
||
697 |
" |
|
698 |
|mime| |
|
699 |
||
700 |
mime := MIMETypes mimeTypeForFilename:'Object.st'. |
|
701 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
702 |
" |
|
703 |
! |
|
704 |
||
705 |
commentStringsForMimeType:mime suffix:suff ifUnknown:alternativeBlockReturningCommentString |
|
706 |
"return a useful comment definition; heuristics for now. |
|
707 |
The returned value is an array of 2 elements; |
|
708 |
the first is the end-of-line comment string (or nil); |
|
709 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
710 |
||
711 |
|commentSpec| |
|
712 |
||
713 |
commentSpec := TypeToCommentStringMapping at:mime ifAbsent:nil. |
|
714 |
commentSpec notNil ifTrue:[ |
|
715 |
^ commentSpec |
|
716 |
]. |
|
717 |
||
718 |
commentSpec := SuffixToCommentStringMapping at:suff ifAbsent:nil. |
|
719 |
commentSpec notNil ifTrue:[ |
|
720 |
^ commentSpec |
|
721 |
]. |
|
722 |
||
723 |
^ alternativeBlockReturningCommentString value |
|
724 |
||
725 |
" |
|
726 |
|mime| |
|
727 |
||
728 |
mime := MIMETypes mimeTypeForFilename:'Makefile'. |
|
729 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
730 |
" |
|
731 |
||
732 |
" |
|
733 |
|mime| |
|
734 |
||
735 |
mime := MIMETypes mimeTypeForFilename:'Object.st'. |
|
736 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
737 |
" |
|
738 |
! ! |
|
739 |
||
1612 | 740 |
!MIMETypes::MIMEType class methodsFor:'documentation'! |
741 |
||
742 |
documentation |
|
743 |
" |
|
744 |
like a string, but knows that it represents a mimeType |
|
745 |
" |
|
746 |
! ! |
|
747 |
||
748 |
!MIMETypes::MIMEType class methodsFor:'initialization'! |
|
749 |
||
750 |
initialize |
|
751 |
CachedTypes := CacheDictionary new:30. |
|
752 |
||
753 |
" |
|
754 |
self initialize |
|
755 |
" |
|
756 |
! ! |
|
757 |
||
758 |
!MIMETypes::MIMEType class methodsFor:'instance creation'! |
|
759 |
||
760 |
fromString:aString |
|
761 |
|cachedType newType| |
|
762 |
||
763 |
aString class == self ifTrue:[^ aString]. |
|
764 |
||
765 |
cachedType := CachedTypes at:aString ifAbsent:nil. |
|
766 |
cachedType notNil ifTrue:[^ cachedType]. |
|
767 |
newType := aString copy changeClassTo:self. |
|
768 |
CachedTypes at:aString put:newType. |
|
769 |
^ newType |
|
770 |
||
771 |
" |
|
772 |
self fromString:'text/html' |
|
773 |
" |
|
774 |
! ! |
|
775 |
||
776 |
!MIMETypes::MIMEType methodsFor:'queries'! |
|
777 |
||
1693 | 778 |
isArchive |
1612 | 779 |
|archivTypes| |
780 |
||
1729 | 781 |
archivTypes := MIMETypes applicationCompressorsAndArchiveTypeList. |
1612 | 782 |
archivTypes pairWiseDo:[: ext : type | |
783 |
self = type ifTrue:[ ^ true]. |
|
784 |
]. |
|
785 |
^ false |
|
786 |
! |
|
787 |
||
788 |
isHtml |
|
789 |
||
790 |
^ (self = 'text/html') |
|
791 |
! |
|
792 |
||
793 |
isImage |
|
794 |
||
1693 | 795 |
^ (self startsWith:'image/') |
1612 | 796 |
! |
797 |
||
798 |
isPdf |
|
799 |
^ (self = 'application/pdf') |
|
800 |
! |
|
801 |
||
802 |
isSmalltalkSource |
|
803 |
^ (self = 'application/x-smalltalk-source') |
|
643 | 804 |
! ! |
805 |
||
806 |
!MIMETypes class methodsFor:'documentation'! |
|
807 |
||
808 |
version |
|
1777 | 809 |
^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.54 2003-05-19 20:18:02 cg Exp $' |
643 | 810 |
! ! |
1666 | 811 |
|
643 | 812 |
MIMETypes initialize! |
1666 | 813 |
MIMETypes::MIMEType initialize! |