author | Claus Gittinger <cg@exept.de> |
Tue, 20 Jan 2004 15:07:01 +0100 | |
changeset 1891 | 1b53c21c64c5 |
parent 1890 | ccf118af49ce |
child 1925 | 9f5e4568529f |
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 |
|
1887 | 21 |
TypeToFileSuffixMapping FilenameToTypeMapping |
22 |
FileSuffixToImageReaderClassMapping CharSetToFontMapping |
|
23 |
LastSuffix LastType DefaultCommandPerMIMEPerOS' |
|
1612 | 24 |
poolDictionaries:'' |
1800 | 25 |
category:'Net-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 |
]. |
|
1887 | 201 |
TypeToFileSuffixMapping isNil ifTrue:[ |
202 |
TypeToFileSuffixMapping := Dictionary new |
|
203 |
]. |
|
1729 | 204 |
FilenameToTypeMapping isNil ifTrue:[ |
205 |
FilenameToTypeMapping := Dictionary new. |
|
206 |
]. |
|
207 |
||
208 |
types := OrderedCollection new. |
|
209 |
types addAll:self textTypeList. |
|
210 |
types addAll:self imageTypeList. |
|
211 |
types addAll:self videoTypeList. |
|
212 |
types addAll:self audioTypeList. |
|
213 |
types addAll:self applicationTypeList. |
|
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
214 |
types addAll:self osSpecificTypeList. |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
215 |
|
1729 | 216 |
types pairWiseDo:[:suff :typeString| |
217 |
|type| |
|
218 |
||
219 |
type := MIMEType fromString:typeString. |
|
220 |
suff isArray ifTrue:[ |
|
1887 | 221 |
suff do:[:s | FileSuffixToTypeMapping at:s put:type]. |
222 |
TypeToFileSuffixMapping at:type put:suff first. |
|
1729 | 223 |
] ifFalse:[ |
1887 | 224 |
FileSuffixToTypeMapping at:suff put:type. |
225 |
TypeToFileSuffixMapping at:type put:suff. |
|
226 |
]. |
|
1729 | 227 |
]. |
228 |
||
229 |
self miscFilenameList pairWiseDo:[:nm :typeString| |
|
230 |
|type| |
|
231 |
||
232 |
type := MIMEType fromString:typeString. |
|
233 |
nm isArray ifTrue:[ |
|
234 |
nm do:[:s | FilenameToTypeMapping at:s put:type] |
|
235 |
] ifFalse:[ |
|
236 |
FilenameToTypeMapping at:nm put:type |
|
237 |
] |
|
238 |
]. |
|
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
239 |
|
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
240 |
" |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
241 |
self initializeFileNameToMimeTypeMapping |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
242 |
" |
1729 | 243 |
! |
244 |
||
245 |
initializeImageReaderMappings |
|
246 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[ |
|
247 |
FileSuffixToImageReaderClassMapping := Dictionary new |
|
248 |
]. |
|
249 |
"MIME" TypeToImageReaderClassMapping isNil ifTrue:[ |
|
250 |
TypeToImageReaderClassMapping := Dictionary new |
|
251 |
]. |
|
252 |
||
253 |
"/ setup mimeType to image reader class mapping ... |
|
254 |
||
255 |
TypeToImageReaderClassMapping at:'image/jpeg' put:JPEGReader. |
|
256 |
TypeToImageReaderClassMapping at:'image/gif' put:GIFReader. |
|
257 |
TypeToImageReaderClassMapping at:'image/tiff' put:TIFFReader. |
|
258 |
||
259 |
"/ setup suffix to image reader class mapping ... |
|
260 |
||
261 |
FileSuffixToImageReaderClassMapping at:'jpg' put:JPEGReader. |
|
262 |
FileSuffixToImageReaderClassMapping at:'gif' put:GIFReader. |
|
263 |
FileSuffixToImageReaderClassMapping at:'tif' put:TIFFReader. |
|
264 |
! ! |
|
265 |
||
266 |
!MIMETypes class methodsFor:'initialization-lists'! |
|
267 |
||
268 |
applicationCompressorsAndArchiveTypeList |
|
1604 | 269 |
^ #( |
1890 | 270 |
'tar' 'application/x-tar' |
271 |
'gtar' 'application/x-gtar' |
|
1891 | 272 |
('tgz' 'tar.gz') 'application/x-tar-gzip-compressed' "/ 'application/x-tar-compressed' |
273 |
('tar.bz2') 'application/x-tar-bzip2-compressed' |
|
1890 | 274 |
'zip' 'application/x-zip-compressed' |
275 |
'bz2' 'application/x-bzip2-compressed' |
|
276 |
('gz' 'z') 'application/x-gzip-compressed' |
|
277 |
'cpio' 'application/x-cpio' |
|
278 |
'shar' 'application/x-shar' |
|
279 |
'jar' 'application/java-archive' |
|
280 |
'sar' 'application/x-squeak-archive' |
|
281 |
'sit' 'application/x-stuffit' |
|
282 |
'hqx' 'application/mac-binhex40' |
|
283 |
'cpt' 'application/mac-compactpro' |
|
1604 | 284 |
) |
285 |
! |
|
645 | 286 |
|
1609 | 287 |
applicationMiscTypeList |
288 |
"misc applications" |
|
289 |
||
290 |
^ #( |
|
291 |
('a' 'o' 'obj' ) 'application/binary' |
|
292 |
'a' 'application/library' |
|
293 |
('dll' 'so') 'application/shared-library' |
|
294 |
) |
|
295 |
! |
|
296 |
||
1604 | 297 |
applicationProgLangTypeList |
1606 | 298 |
"applications for programm languages" |
713 | 299 |
|
1604 | 300 |
^ #( |
1609 | 301 |
('st' 'cls' 'rc') 'application/x-smalltalk-source' |
1604 | 302 |
'sif' 'application/x-smalltalk-source-sif' |
1668 | 303 |
'pac' 'application/x-smalltalk-dolphin-package' |
1778 | 304 |
|
305 |
'sts' 'application/x-squeak-source' |
|
306 |
'pr' 'application/x-squeak-project' |
|
307 |
||
1604 | 308 |
'c' 'application/x-c-source' |
309 |
('cc' 'cpp') 'application/x-cpp-source' |
|
1609 | 310 |
('h' 'hi') 'application/x-c-header' |
1604 | 311 |
('js' 'mocha') 'application/x-javascript' |
312 |
('java' 'jav') 'application/x-java-source' |
|
313 |
'sh' 'application/x-sh' |
|
314 |
'csh' 'application/x-csh' |
|
315 |
'tcl' 'application/x-tcl' |
|
316 |
'pl' 'application/x-perl' |
|
317 |
'mak' 'application/x-make' |
|
318 |
'bat' 'application/x-batch-script' |
|
319 |
('asn1' 'x409' 'gdmo' 'gdm') 'application/x-asn1-source' |
|
320 |
) |
|
321 |
! |
|
1561 | 322 |
|
1604 | 323 |
applicationTextTypeList |
1606 | 324 |
"text applications" |
1604 | 325 |
|
326 |
^ #( |
|
327 |
('ps' 'eps') 'application/postscript' |
|
1778 | 328 |
"/ 'ai' 'application/postscript' |
1604 | 329 |
'pdf' 'application/pdf' |
330 |
'rtf' 'application/rtf' |
|
1778 | 331 |
"/ 'rtf' 'text/rtf' ???? |
332 |
"/ 'doc' 'application/winword' |
|
1779 | 333 |
'doc' 'application/ms-word-document' |
1778 | 334 |
'swf' 'application/x-shockwave-flash' |
335 |
('ppt' 'ppz' 'pot' 'pps') 'application/mspowerpoint' |
|
336 |
'xls' 'application/x-excel' |
|
1604 | 337 |
) |
338 |
! |
|
339 |
||
340 |
applicationTypeList |
|
1606 | 341 |
"applications" |
1604 | 342 |
|
1729 | 343 |
|typeList| |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
344 |
|
1729 | 345 |
typeList := OrderedCollection new. |
346 |
typeList addAll:self applicationProgLangTypeList. |
|
347 |
typeList addAll:self applicationTextTypeList. |
|
348 |
typeList addAll:self applicationCompressorsAndArchiveTypeList. |
|
349 |
typeList addAll:self applicationMiscTypeList. |
|
1616 | 350 |
|
1729 | 351 |
^ typeList |
1604 | 352 |
! |
353 |
||
354 |
audioTypeList |
|
1606 | 355 |
"audio formats ..." |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
356 |
|
1604 | 357 |
^ #( |
1720 | 358 |
('au' 'snd') 'audio/basic' |
1778 | 359 |
('ra') 'audio/x-realaudio' |
360 |
('ram' 'rm') 'audio/x-pn-realaudio' |
|
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
361 |
"/ cg: see unixSpecific / windowsSpecific |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
362 |
"/ 'rpm' 'audio/x-pn-realaudio-plugin' |
1720 | 363 |
('mpa' 'mpega') 'audio/mpeg' |
1778 | 364 |
"/ 'mp3' 'audio/x-mp3' |
365 |
('mp3' 'mp2') 'audio/mpeg' |
|
1604 | 366 |
'wav' 'audio/x-wav' |
367 |
('aif' 'aiff' 'aifc') 'audio/x-aiff' |
|
1778 | 368 |
('midi' 'mid') 'audio/midi' |
1604 | 369 |
) |
370 |
! |
|
371 |
||
372 |
imageTypeList |
|
373 |
||
374 |
^ #( |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
375 |
"/ image formats ... |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
376 |
|
1216 | 377 |
('jpg' 'jpeg') 'image/jpeg' |
1188 | 378 |
'gif' 'image/gif' |
379 |
('tif' 'tiff') 'image/tiff' |
|
380 |
'xbm' 'image/x-xbitmap' |
|
381 |
'xpm' 'image/x-xpixmap' |
|
1720 | 382 |
'png' 'image/png' |
1188 | 383 |
'pcd' 'image/x-photo-cd' |
384 |
'bmp' 'image/x-MS-bmp' |
|
385 |
'rgb' 'image/x-rgb' |
|
386 |
'ppm' 'image/x-portable-pixmap' |
|
387 |
'pgm' 'image/x-portable-graymap' |
|
388 |
'pbm' 'image/x-portable-bitmap' |
|
389 |
'pnm' 'image/x-portable-anymap' |
|
390 |
'xwd' 'image/x-xwindowdump' |
|
391 |
'ras' 'image/x-cmu-raster' |
|
1216 | 392 |
'tga' 'image/x-targa' |
1604 | 393 |
) |
394 |
! |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
395 |
|
1609 | 396 |
miscFilenameList |
397 |
"other formats (not by suffix, but by fileName isnstead) ..." |
|
398 |
||
399 |
^ #( |
|
400 |
('makefile' 'make.proto') 'application/x-make' |
|
1778 | 401 |
('exe' 'bin') 'application/octet-stream' |
402 |
('class') 'application/octet-stream' |
|
1609 | 403 |
) |
404 |
! |
|
405 |
||
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
406 |
osSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
407 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
408 |
^ self windowsSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
409 |
]. |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
410 |
^ self unixSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
411 |
! |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
412 |
|
1604 | 413 |
textTypeList |
414 |
"/ misc text ... |
|
415 |
||
416 |
^ #( |
|
1887 | 417 |
('html' 'htm' 'shtml') 'text/html' |
1604 | 418 |
('txt' 'text') 'text/plain' |
1680 | 419 |
'xml' 'text/xml' |
1777 | 420 |
'css' 'text/css' |
1604 | 421 |
) |
422 |
! |
|
423 |
||
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
424 |
unixSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
425 |
|
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
426 |
^ #( |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
427 |
"/ cg: RPM is 'audio/x-pn-realaudio-plugin' for WIN32 |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
428 |
"/ and 'application/x-rpm' for Unix |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
429 |
'rpm' 'application/x-rpm' |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
430 |
) |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
431 |
! |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
432 |
|
1604 | 433 |
videoTypeList |
434 |
"/ video formats ... |
|
435 |
||
436 |
^ #( |
|
1720 | 437 |
('qt' 'mov' 'moov') 'video/quicktime' |
438 |
('mpv' 'mpegv' 'mpg' 'mpeg' 'mpe') 'video/mpeg' |
|
1604 | 439 |
'movie' 'video/x-sgi-movie' |
1820 | 440 |
('avi' 'wmv' 'asf') 'video/x-msvideo' |
1604 | 441 |
('mpv2' 'mp2v' 'mp2' 'mpeg2') 'video/x-mpeg2' |
1680 | 442 |
'rm' 'application/vnd.rn-realmedia' |
443 |
'rv' 'video/x-pn-realvideo' |
|
1778 | 444 |
) |
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
445 |
! |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
446 |
|
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
447 |
windowsSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
448 |
^ #( |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
449 |
"/ cg: RPM is 'audio/x-pn-realaudio-plugin' for WIN32 |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
450 |
"/ and 'application/x-rpm' for Unix |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
451 |
'rpm' 'audio/x-pn-realaudio-plugin' |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
452 |
) |
643 | 453 |
! ! |
454 |
||
1729 | 455 |
!MIMETypes class methodsFor:'obsolete'! |
1489 | 456 |
|
1729 | 457 |
fontForCharset:aCharSetName |
458 |
"return the font-encoding for an iso-charset" |
|
1489 | 459 |
|
1729 | 460 |
self obsoleteMethodWarning:'use FontDescription >> fontNamePatternForCharset:'. |
461 |
^ FontDescription fontNamePatternForCharset:aCharSetName. |
|
1489 | 462 |
|
463 |
" |
|
1729 | 464 |
MIMETypes fontForCharset:'iso2022-jp' |
465 |
MIMETypes fontForCharset:'euc-jp' |
|
1472 | 466 |
" |
467 |
||
1729 | 468 |
"Modified: / 1.8.1998 / 17:00:57 / cg" |
469 |
! ! |
|
1472 | 470 |
|
1729 | 471 |
!MIMETypes class methodsFor:'queries'! |
1472 | 472 |
|
1691
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
473 |
defaultCommandPerMIME |
1729 | 474 |
"TODO: move this to OS/UserPreferences" |
1691
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
475 |
|
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
476 |
DefaultCommandPerMIMEPerOS isNil ifTrue:[ |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
477 |
self initializeDefaultCommands |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
478 |
]. |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
479 |
OperatingSystem isUNIXlike ifTrue:[ |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
480 |
^ DefaultCommandPerMIMEPerOS at:#unix |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
481 |
]. |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
482 |
^ DefaultCommandPerMIMEPerOS at:#win32 |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
483 |
! |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
484 |
|
647 | 485 |
defineImageType:mimeType suffix:aSuffix reader:aReaderClass |
486 |
"register an image reader." |
|
487 |
||
488 |
aSuffix notNil ifTrue:[ |
|
489 |
self imageReaderForSuffix:aSuffix put:aReaderClass. |
|
490 |
]. |
|
491 |
||
492 |
mimeType notNil ifTrue:[ |
|
493 |
self imageReaderForType:mimeType put:aReaderClass |
|
494 |
]. |
|
495 |
||
496 |
(aSuffix notNil and:[mimeType notNil]) ifTrue:[ |
|
497 |
self mimeTypeForSuffix:aSuffix put:mimeType |
|
498 |
]. |
|
499 |
! |
|
500 |
||
643 | 501 |
fileSuffixToImageReaderMapping |
1021 | 502 |
"return the suffix-to-imageReader mapping" |
503 |
||
643 | 504 |
^ FileSuffixToImageReaderClassMapping ? #() |
505 |
||
1021 | 506 |
"Modified: / 1.8.1998 / 17:00:11 / cg" |
643 | 507 |
! |
508 |
||
509 |
imageFileSuffixes |
|
1021 | 510 |
"return a collection with known file suffixes" |
511 |
||
643 | 512 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[^ #()]. |
513 |
^ FileSuffixToImageReaderClassMapping keys |
|
514 |
||
1021 | 515 |
"Created: / 30.6.1997 / 22:04:48 / cg" |
516 |
"Modified: / 1.8.1998 / 17:01:26 / cg" |
|
643 | 517 |
! |
518 |
||
1473 | 519 |
mimeTypeForFilename:filenameArg |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
520 |
"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
|
521 |
|
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
522 |
|type filename lcFilename suff suff2| |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
523 |
|
1473 | 524 |
filename := filenameArg asFilename. |
1474 | 525 |
|
526 |
lcFilename := filename baseName asLowercase. |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
527 |
type := FilenameToTypeMapping at:lcFilename ifAbsent:nil. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
528 |
type isNil ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
529 |
"/ allow for fallback ... |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
530 |
type := OperatingSystem mimeTypeForFilename:lcFilename. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
531 |
"/ 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
|
532 |
"/ 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
|
533 |
"/ the OS. |
1275 | 534 |
"/ type isNil ifTrue:[ |
535 |
"/ FilenameToTypeMapping at:lcFilename put:#unknown |
|
536 |
"/ ]. |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
537 |
]. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
538 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
539 |
type == #unknown ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
540 |
type := nil. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
541 |
]. |
1273
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
542 |
|
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
543 |
type isNil ifTrue:[ |
1473 | 544 |
suff := filename suffix. |
1273
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
545 |
suff size ~~ 0 ifTrue:[ |
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
546 |
"/ sigh - special code for multiple-suffices... |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
547 |
"/ .tar.gz -> tgz |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
548 |
suff2 := filename withoutSuffix suffix. |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
549 |
suff2 size > 0 ifTrue:[ |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
550 |
type := self mimeTypeForSuffix:(suff2 , '.' , suff). |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
551 |
]. |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
552 |
type isNil ifTrue:[ |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
553 |
type := self mimeTypeForSuffix:suff |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
554 |
]. |
1273
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
555 |
] |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
556 |
]. |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
557 |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
558 |
^ type |
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
559 |
|
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
560 |
" |
1841 | 561 |
self mimeTypeForFilename:'typeinst.dvi' |
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
562 |
self mimeTypeForFilename:'foo.tar' |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
563 |
self mimeTypeForFilename:'foo.tgz' |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
564 |
self mimeTypeForFilename:'foo.tar.gz' |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
565 |
" |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
566 |
! |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
567 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
568 |
mimeTypeForFilename:filename put:mimeType |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
569 |
"register a mime type for a filename" |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
570 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
571 |
FilenameToTypeMapping isNil ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
572 |
FilenameToTypeMapping := Dictionary new |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
573 |
]. |
1612 | 574 |
FilenameToTypeMapping at:filename put:(MIMEType fromString:mimeType asLowercase) |
1611 | 575 |
! |
576 |
||
643 | 577 |
mimeTypeForSuffix:suffix |
1021 | 578 |
"given a file suffix, return the mime-type" |
579 |
||
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
580 |
|type lcSuffix| |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
581 |
|
1837 | 582 |
suffix = LastSuffix ifTrue:[ |
583 |
^ LastType |
|
584 |
]. |
|
585 |
||
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
586 |
lcSuffix := suffix asLowercase. |
1837 | 587 |
type := FileSuffixToTypeMapping at:lcSuffix ifAbsent:nil. |
588 |
type isNil ifTrue:[ |
|
589 |
"/ allow for fallback ... |
|
590 |
type := OperatingSystem mimeTypeForSuffix:lcSuffix. |
|
591 |
"/ the special value #unknown is returned as nil; |
|
592 |
"/ this avoids constant retry if a mimeType is not known in the OS. |
|
593 |
||
594 |
type := type ? #unknown. |
|
595 |
FileSuffixToTypeMapping at:lcSuffix put:type. |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
596 |
]. |
1837 | 597 |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
598 |
type == #unknown ifTrue:[ |
1837 | 599 |
type := nil. |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
600 |
]. |
1840 | 601 |
type notNil ifTrue:[ |
602 |
LastSuffix := suffix. |
|
603 |
LastType := MIMEType fromString:type. |
|
604 |
^ LastType |
|
605 |
]. |
|
1841 | 606 |
^ type |
643 | 607 |
|
1666 | 608 |
" |
1840 | 609 |
self mimeTypeForSuffix:'gif' |
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
610 |
self mimeTypeForSuffix:'rpm' |
1666 | 611 |
" |
612 |
||
1021 | 613 |
"Created: / 30.6.1997 / 21:55:51 / cg" |
1300 | 614 |
"Modified: / 23.12.1999 / 22:30:55 / cg" |
643 | 615 |
! |
616 |
||
617 |
mimeTypeForSuffix:suffix put:mimeType |
|
1021 | 618 |
"register a mime type for a file suffix" |
619 |
||
643 | 620 |
FileSuffixToTypeMapping isNil ifTrue:[ |
621 |
FileSuffixToTypeMapping := Dictionary new |
|
622 |
]. |
|
623 |
FileSuffixToTypeMapping at:suffix put:mimeType asLowercase |
|
624 |
||
1021 | 625 |
"Created: / 30.6.1997 / 21:56:20 / cg" |
626 |
"Modified: / 1.8.1998 / 17:03:18 / cg" |
|
1593 | 627 |
! |
628 |
||
629 |
mimeTypeForSuffixMapping |
|
630 |
||
631 |
^ FileSuffixToTypeMapping |
|
1611 | 632 |
! |
633 |
||
634 |
mimeTypeOfContents:filename |
|
635 |
"given a filename, scan the contents, return the mime-type or nil, if unknown" |
|
636 |
||
1612 | 637 |
|typeString| |
638 |
||
639 |
typeString := filename mimeTypeOfContents. |
|
640 |
typeString isNil ifTrue:[^ nil]. |
|
641 |
^ MIMEType fromString:typeString. |
|
1887 | 642 |
! |
643 |
||
644 |
suffixForMimeType:mimeType |
|
645 |
"given a file suffix, return the mime-type" |
|
646 |
||
647 |
^ TypeToFileSuffixMapping at:mimeType ifAbsent:nil |
|
648 |
||
649 |
" |
|
650 |
self suffixForMimeType:(MIMEType fromString:'image/gif') |
|
651 |
" |
|
652 |
||
653 |
"Created: / 30.6.1997 / 21:55:51 / cg" |
|
654 |
"Modified: / 23.12.1999 / 22:30:55 / cg" |
|
655 |
! |
|
656 |
||
657 |
suffixForMimeTypeString:mimeTypeString |
|
658 |
"given a file suffix, return the mime-type" |
|
659 |
||
660 |
^ self suffixForMimeType:(MIMEType fromString:mimeTypeString) |
|
661 |
||
662 |
" |
|
663 |
self suffixForMimeTypeString:'image/gif' |
|
664 |
" |
|
665 |
||
666 |
"Created: / 30.6.1997 / 21:55:51 / cg" |
|
667 |
"Modified: / 23.12.1999 / 22:30:55 / cg" |
|
1612 | 668 |
! ! |
669 |
||
1729 | 670 |
!MIMETypes class methodsFor:'queries-image formats'! |
671 |
||
672 |
imageReaderClasses |
|
673 |
"return a collection of registered image reader classes" |
|
674 |
||
675 |
|setOfClasses| |
|
676 |
||
677 |
setOfClasses := IdentitySet new. |
|
678 |
FileSuffixToImageReaderClassMapping notNil ifTrue:[ |
|
679 |
FileSuffixToImageReaderClassMapping keysAndValuesDo:[:suff :cls | |
|
680 |
setOfClasses add:cls |
|
681 |
]. |
|
682 |
]. |
|
683 |
TypeToImageReaderClassMapping notNil ifTrue:[ |
|
684 |
TypeToImageReaderClassMapping keysAndValuesDo:[:suff :cls | |
|
685 |
setOfClasses add:cls |
|
686 |
]. |
|
687 |
]. |
|
688 |
^ setOfClasses |
|
689 |
||
690 |
"Created: / 30.6.1997 / 22:03:42 / cg" |
|
691 |
"Modified: / 1.8.1998 / 16:59:52 / cg" |
|
692 |
! |
|
693 |
||
694 |
imageReaderForSuffix:aSuffix |
|
695 |
"given a file suffix, return an approriate image reader class" |
|
696 |
||
697 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[^ nil]. |
|
698 |
^ FileSuffixToImageReaderClassMapping at:aSuffix asLowercase ifAbsent:nil |
|
699 |
||
700 |
"Created: / 30.6.1997 / 21:59:11 / cg" |
|
701 |
"Modified: / 1.8.1998 / 17:01:58 / cg" |
|
702 |
! |
|
703 |
||
704 |
imageReaderForSuffix:aSuffix put:aReaderClass |
|
705 |
"register an image reader for a file suffix" |
|
706 |
||
707 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[ |
|
708 |
FileSuffixToImageReaderClassMapping := Dictionary new. |
|
709 |
]. |
|
710 |
FileSuffixToImageReaderClassMapping at:aSuffix asLowercase put:aReaderClass |
|
711 |
||
712 |
"Created: / 30.6.1997 / 21:59:43 / cg" |
|
713 |
"Modified: / 1.8.1998 / 17:02:14 / cg" |
|
714 |
! |
|
715 |
||
716 |
imageReaderForType:mimeTypeString |
|
717 |
"given a mime-type, return an approriate image reader class" |
|
718 |
||
719 |
TypeToImageReaderClassMapping isNil ifTrue:[^ nil]. |
|
720 |
^ TypeToImageReaderClassMapping at:mimeTypeString asLowercase ifAbsent:nil |
|
721 |
||
722 |
"Created: / 30.6.1997 / 21:56:01 / cg" |
|
723 |
"Modified: / 1.8.1998 / 17:02:28 / cg" |
|
724 |
! |
|
725 |
||
726 |
imageReaderForType:mimeTypeString put:aReaderClass |
|
727 |
"register an image reader for a mime-type" |
|
728 |
||
729 |
TypeToImageReaderClassMapping isNil ifTrue:[ |
|
730 |
TypeToImageReaderClassMapping := Dictionary new. |
|
731 |
]. |
|
732 |
TypeToImageReaderClassMapping at:mimeTypeString asLowercase put:aReaderClass |
|
733 |
||
734 |
"Created: / 30.6.1997 / 21:56:11 / cg" |
|
735 |
"Modified: / 1.8.1998 / 17:02:40 / cg" |
|
736 |
! ! |
|
737 |
||
738 |
!MIMETypes class methodsFor:'queries-language syntax'! |
|
739 |
||
740 |
commentStringsForFilename:aFilename |
|
741 |
"return a useful comment definition; heuristics for now. |
|
742 |
The returned value is an array of 2 elements; |
|
743 |
the first is the end-of-line comment string (or nil); |
|
744 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
745 |
||
746 |
|mime| |
|
747 |
||
748 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
749 |
^ self commentStringsForMimeType:mime suffix:(aFilename asFilename suffix) |
|
750 |
||
751 |
" |
|
752 |
MIMETypes commentStringsForFilename:'Makefile'. |
|
753 |
MIMETypes commentStringsForFilename:'Object.st'. |
|
754 |
MIMETypes commentStringsForFilename:'Foo.java'. |
|
755 |
" |
|
756 |
! |
|
757 |
||
758 |
commentStringsForFilename:aFilename ifUnknown:alternativeBlockReturningCommentString |
|
759 |
"return a useful comment definition; heuristics for now. |
|
760 |
The returned value is an array of 2 elements; |
|
761 |
the first is the end-of-line comment string (or nil); |
|
762 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
763 |
||
764 |
|mime| |
|
765 |
||
766 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
767 |
^ self commentStringsForMimeType:mime suffix:(aFilename asFilename suffix) ifUnknown:alternativeBlockReturningCommentString |
|
768 |
||
769 |
" |
|
770 |
MIMETypes commentStringsForFilename:'Makefile'. |
|
771 |
MIMETypes commentStringsForFilename:'Object.st'. |
|
772 |
MIMETypes commentStringsForFilename:'Foo.java'. |
|
773 |
" |
|
774 |
! |
|
775 |
||
776 |
commentStringsForMimeType:mime suffix:suff |
|
777 |
"return a useful comment definition; heuristics for now. |
|
778 |
The returned value is an array of 2 elements; |
|
779 |
the first is the end-of-line comment string (or nil); |
|
780 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
781 |
||
782 |
^ self |
|
783 |
commentStringsForMimeType:mime suffix:suff |
|
784 |
ifUnknown: #(';' (nil nil)) |
|
785 |
||
786 |
" |
|
787 |
|mime| |
|
788 |
||
789 |
mime := MIMETypes mimeTypeForFilename:'Makefile'. |
|
790 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
791 |
" |
|
792 |
||
793 |
" |
|
794 |
|mime| |
|
795 |
||
796 |
mime := MIMETypes mimeTypeForFilename:'Object.st'. |
|
797 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
798 |
" |
|
799 |
! |
|
800 |
||
801 |
commentStringsForMimeType:mime suffix:suff ifUnknown:alternativeBlockReturningCommentString |
|
802 |
"return a useful comment definition; heuristics for now. |
|
803 |
The returned value is an array of 2 elements; |
|
804 |
the first is the end-of-line comment string (or nil); |
|
805 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
806 |
||
807 |
|commentSpec| |
|
808 |
||
809 |
commentSpec := TypeToCommentStringMapping at:mime ifAbsent:nil. |
|
810 |
commentSpec notNil ifTrue:[ |
|
811 |
^ commentSpec |
|
812 |
]. |
|
813 |
||
814 |
commentSpec := SuffixToCommentStringMapping at:suff ifAbsent:nil. |
|
815 |
commentSpec notNil ifTrue:[ |
|
816 |
^ commentSpec |
|
817 |
]. |
|
818 |
||
819 |
^ alternativeBlockReturningCommentString value |
|
820 |
||
821 |
" |
|
822 |
|mime| |
|
823 |
||
824 |
mime := MIMETypes mimeTypeForFilename:'Makefile'. |
|
825 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
826 |
" |
|
827 |
||
828 |
" |
|
829 |
|mime| |
|
830 |
||
831 |
mime := MIMETypes mimeTypeForFilename:'Object.st'. |
|
832 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
833 |
" |
|
834 |
! ! |
|
835 |
||
1612 | 836 |
!MIMETypes::MIMEType class methodsFor:'documentation'! |
837 |
||
838 |
documentation |
|
839 |
" |
|
1864 | 840 |
like a string, but knows that it represents a mimeType. |
1612 | 841 |
" |
842 |
! ! |
|
843 |
||
844 |
!MIMETypes::MIMEType class methodsFor:'initialization'! |
|
845 |
||
846 |
initialize |
|
847 |
CachedTypes := CacheDictionary new:30. |
|
848 |
||
849 |
" |
|
850 |
self initialize |
|
851 |
" |
|
852 |
! ! |
|
853 |
||
854 |
!MIMETypes::MIMEType class methodsFor:'instance creation'! |
|
855 |
||
856 |
fromString:aString |
|
857 |
|cachedType newType| |
|
858 |
||
859 |
aString class == self ifTrue:[^ aString]. |
|
860 |
||
861 |
cachedType := CachedTypes at:aString ifAbsent:nil. |
|
862 |
cachedType notNil ifTrue:[^ cachedType]. |
|
863 |
newType := aString copy changeClassTo:self. |
|
864 |
CachedTypes at:aString put:newType. |
|
865 |
^ newType |
|
866 |
||
867 |
" |
|
868 |
self fromString:'text/html' |
|
869 |
" |
|
870 |
! ! |
|
871 |
||
872 |
!MIMETypes::MIMEType methodsFor:'queries'! |
|
873 |
||
1693 | 874 |
isArchive |
1864 | 875 |
"return true, if I represent an archive type (such as zip or tar)" |
876 |
||
1612 | 877 |
|archivTypes| |
878 |
||
1729 | 879 |
archivTypes := MIMETypes applicationCompressorsAndArchiveTypeList. |
1612 | 880 |
archivTypes pairWiseDo:[: ext : type | |
881 |
self = type ifTrue:[ ^ true]. |
|
882 |
]. |
|
883 |
^ false |
|
884 |
! |
|
885 |
||
886 |
isHtml |
|
1864 | 887 |
"return true, if I represent the html text type" |
1612 | 888 |
|
889 |
^ (self = 'text/html') |
|
890 |
! |
|
891 |
||
892 |
isImage |
|
1864 | 893 |
"return true, if I represent an image type (such as gif or jpg)" |
1612 | 894 |
|
1693 | 895 |
^ (self startsWith:'image/') |
1612 | 896 |
! |
897 |
||
898 |
isPdf |
|
1864 | 899 |
"return true, if I represent the pdf type" |
900 |
||
1612 | 901 |
^ (self = 'application/pdf') |
902 |
! |
|
903 |
||
904 |
isSmalltalkSource |
|
1864 | 905 |
"return true, if I represent the smalltalk sourcecode type" |
906 |
||
1612 | 907 |
^ (self = 'application/x-smalltalk-source') |
1783 | 908 |
! |
909 |
||
910 |
isXml |
|
1864 | 911 |
"return true, if I represent the xml text type" |
912 |
||
1783 | 913 |
^ (self = 'text/xml') |
643 | 914 |
! ! |
915 |
||
916 |
!MIMETypes class methodsFor:'documentation'! |
|
917 |
||
918 |
version |
|
1891 | 919 |
^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.71 2004-01-20 14:07:01 cg Exp $' |
643 | 920 |
! ! |
1666 | 921 |
|
643 | 922 |
MIMETypes initialize! |
1666 | 923 |
MIMETypes::MIMEType initialize! |