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