author | Claus Gittinger <cg@exept.de> |
Mon, 26 May 2008 10:36:40 +0200 | |
changeset 2479 | 40a05c259915 |
parent 2432 | 8dcb56eb1e89 |
child 2486 | 42063a7fc3db |
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 |
" |
|
1410 | 12 |
"{ Package: 'stx:libview2' }" |
13 |
||
643 | 14 |
Object subclass:#MIMETypes |
1612 | 15 |
instanceVariableNames:'' |
1729 | 16 |
classVariableNames:'TypeToImageReaderClassMapping TypeToCommentStringMapping |
1979
0612875a95c1
acroread command from registry (win32)
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
17 |
TypeToFileSuffixMapping TypeToViewerApplicationMapping |
1729 | 18 |
SuffixToCommentStringMapping FileSuffixToTypeMapping |
1979
0612875a95c1
acroread command from registry (win32)
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
19 |
FilenameToTypeMapping FileSuffixToImageReaderClassMapping |
0612875a95c1
acroread command from registry (win32)
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
20 |
CharSetToFontMapping LastSuffix LastType |
2298 | 21 |
DefaultCommandPerMIMEPerOS DefaultPrintCommandPerMIMEPerOS |
22 |
TypeToParentesisSpecMapping SuffixToParentesisSpecMapping' |
|
1612 | 23 |
poolDictionaries:'' |
1800 | 24 |
category:'Net-Communication-Support' |
1612 | 25 |
! |
26 |
||
27 |
String variableByteSubclass:#MIMEType |
|
28 |
instanceVariableNames:'' |
|
29 |
classVariableNames:'CachedTypes' |
|
30 |
poolDictionaries:'' |
|
31 |
privateIn:MIMETypes |
|
643 | 32 |
! |
33 |
||
34 |
!MIMETypes class methodsFor:'documentation'! |
|
35 |
||
36 |
copyright |
|
37 |
" |
|
38 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
1612 | 39 |
All Rights Reserved |
643 | 40 |
|
41 |
This software is furnished under a license and may be used |
|
42 |
only in accordance with the terms of that license and with the |
|
43 |
inclusion of the above copyright notice. This software may not |
|
44 |
be provided or otherwise made available to, or used by, any |
|
45 |
other person. No title to or ownership of the software is |
|
46 |
hereby transferred. |
|
47 |
||
48 |
||
49 |
" |
|
50 |
! |
|
51 |
||
52 |
documentation |
|
53 |
" |
|
54 |
just a place to keep MIME information |
|
55 |
(avoid spreading things at many places) |
|
56 |
||
1021 | 57 |
MIMETypes is abstract and functional. |
58 |
Actually, in some OperatingSystems, this information may |
|
59 |
be found in some config files (or registries). |
|
60 |
Therefore, this class may have to be extended to support this |
|
61 |
and fetch the information from there eventually. |
|
62 |
||
643 | 63 |
[author:] |
64 |
Claus Gittinger |
|
65 |
" |
|
1311 | 66 |
! |
67 |
||
68 |
knownTypes |
|
69 |
" |
|
70 |
simply a reminder for me ... |
|
71 |
||
72 |
application mime file extentsions |
|
73 |
||
74 |
powerpoint application/ms-powerpoint .pot, .ppz, .ppt, .pps, |
|
75 |
application/mspowerpoint |
|
76 |
application/vnd.ms-powerpoint |
|
77 |
application/x-mspowerpoint |
|
78 |
||
1312 | 79 |
shockwave application/x-shockwave-flash .swf |
1311 | 80 |
|
1312 | 81 |
futuresplash application/futuresplash .spl |
1311 | 82 |
" |
643 | 83 |
! ! |
84 |
||
85 |
!MIMETypes class methodsFor:'initialization'! |
|
86 |
||
1729 | 87 |
initialize |
88 |
"initialize wellKnown facts" |
|
89 |
||
90 |
MIMEType initialize. "must be initialized first" |
|
91 |
LastSuffix := LastType := nil. |
|
92 |
||
93 |
self initializeFileNameToMimeTypeMapping. |
|
94 |
self initializeImageReaderMappings. |
|
95 |
self initializeCommentStringMappings. |
|
2298 | 96 |
self initializeParentesisSpecMappings. |
1729 | 97 |
|
98 |
" |
|
99 |
self initialize |
|
100 |
" |
|
101 |
||
2298 | 102 |
"Modified: / 10-04-2007 / 15:16:44 / cg" |
1729 | 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 |
|
2055 | 125 |
at:'text/css' |
126 |
put:#('//' ('/*' '*/')). |
|
127 |
||
128 |
TypeToCommentStringMapping |
|
1729 | 129 |
at:'application/x-batch-script' |
130 |
put:#('rem ' (nil nil)). "/ 'rem ' for EOL comments only |
|
131 |
||
132 |
"/ the following is ST/X specific |
|
133 |
TypeToCommentStringMapping |
|
134 |
at:'application/x-smalltalk-source' |
|
135 |
put:#('"/' ('"' '"')). "/ '"/ ' for EOL; ".." for delimited comments |
|
136 |
||
2055 | 137 |
|
1729 | 138 |
"/ this is for standard smalltalk |
139 |
"/ TypeToCommentStringMapping |
|
140 |
"/ at:'application/x-smalltalk-source' |
|
141 |
"/ put:#(nil ('"' '"')). "/ ".." for delimited comments only |
|
142 |
||
143 |
||
144 |
TypeToCommentStringMapping |
|
145 |
at:'application/x-pascal-source' |
|
146 |
put:#(nil ('{' '}')). "/ '{'..'}' for delimited comments |
|
147 |
||
2055 | 148 |
|
2048
dbb361dd9c5f
comment strings for javascript files
Claus Gittinger <cg@exept.de>
parents:
2028
diff
changeset
|
149 |
"/ "/ the following is k&r |
dbb361dd9c5f
comment strings for javascript files
Claus Gittinger <cg@exept.de>
parents:
2028
diff
changeset
|
150 |
"/ TypeToCommentStringMapping |
dbb361dd9c5f
comment strings for javascript files
Claus Gittinger <cg@exept.de>
parents:
2028
diff
changeset
|
151 |
"/ at:'application/x-c-source' |
dbb361dd9c5f
comment strings for javascript files
Claus Gittinger <cg@exept.de>
parents:
2028
diff
changeset
|
152 |
"/ put:#(nil ('/*' '*/')). "/ '/*'..'*/' for delimited comments |
1729 | 153 |
"/ this is ANSI-c |
154 |
TypeToCommentStringMapping |
|
155 |
at:'application/x-c-source' |
|
156 |
put:#('//' ('/*' '*/')). |
|
157 |
||
158 |
TypeToCommentStringMapping |
|
159 |
at:'application/x-cpp-source' |
|
160 |
put:#('//' ('/*' '*/')). |
|
161 |
||
162 |
TypeToCommentStringMapping |
|
2479 | 163 |
at:'application/x-csharp-source' |
164 |
put:#('//' ('/*' '*/')). |
|
165 |
||
166 |
TypeToCommentStringMapping |
|
1729 | 167 |
at:'application/x-java-source' |
168 |
put:#('//' ('/*' '*/')). |
|
169 |
||
170 |
TypeToCommentStringMapping |
|
2048
dbb361dd9c5f
comment strings for javascript files
Claus Gittinger <cg@exept.de>
parents:
2028
diff
changeset
|
171 |
at:'application/x-javascript' |
dbb361dd9c5f
comment strings for javascript files
Claus Gittinger <cg@exept.de>
parents:
2028
diff
changeset
|
172 |
put:#('//' ('/*' '*/')). |
dbb361dd9c5f
comment strings for javascript files
Claus Gittinger <cg@exept.de>
parents:
2028
diff
changeset
|
173 |
|
dbb361dd9c5f
comment strings for javascript files
Claus Gittinger <cg@exept.de>
parents:
2028
diff
changeset
|
174 |
TypeToCommentStringMapping |
2298 | 175 |
at:'application/x-lisp-source' |
176 |
put:#(';' (nil nil)). "/ '#' for EOL comments only |
|
177 |
||
178 |
TypeToCommentStringMapping |
|
1729 | 179 |
at:'application/x-asn1-source' |
180 |
put:#('--' ('--' '--')). |
|
181 |
||
182 |
||
183 |
"/ st/x support files |
|
184 |
SuffixToCommentStringMapping |
|
185 |
at:'style' |
|
186 |
put:#(';' (nil nil)). |
|
1604 | 187 |
|
1729 | 188 |
SuffixToCommentStringMapping |
189 |
at:'rs' |
|
2298 | 190 |
put:#(';' (nil nil)). |
191 |
||
192 |
"Modified: / 07-04-2007 / 16:12:05 / cg" |
|
1729 | 193 |
! |
194 |
||
195 |
initializeDefaultCommands |
|
196 |
"TODO: move this to OS" |
|
197 |
||
2116 | 198 |
|unixCommands win32Commands unixPrintCommands win32PrintCommands| |
1729 | 199 |
|
200 |
DefaultCommandPerMIMEPerOS := Dictionary new. |
|
201 |
DefaultCommandPerMIMEPerOS at:#unix put:(unixCommands := Dictionary new). |
|
202 |
DefaultCommandPerMIMEPerOS at:#win32 put:(win32Commands := Dictionary new). |
|
203 |
||
204 |
unixCommands at:'application/x-tar-compressed' put:'gunzip < %1 | tar tvf -'. |
|
205 |
unixCommands at:'application/pdf' put:'acroread -display %2 %1'. |
|
206 |
||
2141 | 207 |
OperatingSystem isMSWINDOWSlike ifFalse:[ |cmd| |
2142 | 208 |
cmd := #( firefox konqueror mozilla netscape opera ) |
2141 | 209 |
detect:[:aCmd| (OperatingSystem pathOfCommand:aCmd) notEmptyOrNil ] |
210 |
ifNone:nil. |
|
211 |
||
212 |
cmd notNil ifTrue:[ |
|
2142 | 213 |
unixCommands at:'text/html' put:(cmd, ' "%1"') |
2141 | 214 |
]. |
215 |
]. |
|
216 |
||
217 |
||
2116 | 218 |
DefaultPrintCommandPerMIMEPerOS := Dictionary new. |
219 |
DefaultPrintCommandPerMIMEPerOS at:#unix put:(unixPrintCommands := Dictionary new). |
|
220 |
DefaultPrintCommandPerMIMEPerOS at:#win32 put:(win32PrintCommands := Dictionary new). |
|
221 |
||
222 |
"/ if you have a good (intelligent) spooler ;-) |
|
223 |
unixPrintCommands at:'application/pdf' put:'lpr %1'. |
|
224 |
"/ if not, you may need more... |
|
225 |
"/ unixPrintCommands at:'application/pdf' put:'pdfToPS %1 | lpr'. |
|
226 |
||
227 |
"/ WIN32 setup is now obsolete - now read through the registry |
|
2096 | 228 |
"/ OperatingSystem isMSWINDOWSlike ifTrue:[ |
229 |
"/ #( |
|
230 |
"/ "suffix" "default" "mime" |
|
231 |
"/ ( 'pdf' 'acrord32 %1' 'application/pdf' ) |
|
232 |
"/ ) triplesDo:[:suffix :default :mime| |
|
233 |
"/ |cmd| |
|
234 |
"/ |
|
235 |
"/ cmd := Win32OperatingSystem::RegistryEntry executableForSuffix:suffix. |
|
236 |
"/ cmd isNil ifTrue:[ |
|
237 |
"/ "assume its in the path" |
|
238 |
"/ cmd := default. |
|
239 |
"/ ]. |
|
240 |
"/ win32Commands at:mime put:cmd. |
|
241 |
"/ ]. |
|
242 |
"/ ]. |
|
1979
0612875a95c1
acroread command from registry (win32)
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
243 |
|
1729 | 244 |
" |
245 |
self initializeDefaultCommands |
|
246 |
" |
|
1979
0612875a95c1
acroread command from registry (win32)
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
247 |
|
0612875a95c1
acroread command from registry (win32)
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
248 |
"Modified: / 12-05-2004 / 11:43:23 / cg" |
1729 | 249 |
! |
250 |
||
251 |
initializeFileNameToMimeTypeMapping |
|
252 |
"initialize wellKnown facts" |
|
253 |
||
254 |
|types| |
|
255 |
||
256 |
FileSuffixToTypeMapping isNil ifTrue:[ |
|
257 |
FileSuffixToTypeMapping := Dictionary new |
|
258 |
]. |
|
1887 | 259 |
TypeToFileSuffixMapping isNil ifTrue:[ |
260 |
TypeToFileSuffixMapping := Dictionary new |
|
261 |
]. |
|
1729 | 262 |
FilenameToTypeMapping isNil ifTrue:[ |
263 |
FilenameToTypeMapping := Dictionary new. |
|
264 |
]. |
|
265 |
||
266 |
types := OrderedCollection new. |
|
267 |
types addAll:self textTypeList. |
|
268 |
types addAll:self imageTypeList. |
|
269 |
types addAll:self videoTypeList. |
|
270 |
types addAll:self audioTypeList. |
|
271 |
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
|
272 |
types addAll:self osSpecificTypeList. |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
273 |
|
1729 | 274 |
types pairWiseDo:[:suff :typeString| |
275 |
|type| |
|
276 |
||
277 |
type := MIMEType fromString:typeString. |
|
278 |
suff isArray ifTrue:[ |
|
1887 | 279 |
suff do:[:s | FileSuffixToTypeMapping at:s put:type]. |
280 |
TypeToFileSuffixMapping at:type put:suff first. |
|
1729 | 281 |
] ifFalse:[ |
1887 | 282 |
FileSuffixToTypeMapping at:suff put:type. |
283 |
TypeToFileSuffixMapping at:type put:suff. |
|
284 |
]. |
|
1729 | 285 |
]. |
286 |
||
287 |
self miscFilenameList pairWiseDo:[:nm :typeString| |
|
288 |
|type| |
|
289 |
||
290 |
type := MIMEType fromString:typeString. |
|
291 |
nm isArray ifTrue:[ |
|
292 |
nm do:[:s | FilenameToTypeMapping at:s put:type] |
|
293 |
] ifFalse:[ |
|
294 |
FilenameToTypeMapping at:nm put:type |
|
295 |
] |
|
296 |
]. |
|
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
297 |
|
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
298 |
" |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
299 |
self initializeFileNameToMimeTypeMapping |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
300 |
" |
1729 | 301 |
! |
302 |
||
303 |
initializeImageReaderMappings |
|
304 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[ |
|
305 |
FileSuffixToImageReaderClassMapping := Dictionary new |
|
306 |
]. |
|
307 |
"MIME" TypeToImageReaderClassMapping isNil ifTrue:[ |
|
308 |
TypeToImageReaderClassMapping := Dictionary new |
|
309 |
]. |
|
310 |
||
311 |
"/ setup mimeType to image reader class mapping ... |
|
312 |
||
313 |
TypeToImageReaderClassMapping at:'image/jpeg' put:JPEGReader. |
|
314 |
TypeToImageReaderClassMapping at:'image/gif' put:GIFReader. |
|
315 |
TypeToImageReaderClassMapping at:'image/tiff' put:TIFFReader. |
|
316 |
||
317 |
"/ setup suffix to image reader class mapping ... |
|
318 |
||
319 |
FileSuffixToImageReaderClassMapping at:'jpg' put:JPEGReader. |
|
320 |
FileSuffixToImageReaderClassMapping at:'gif' put:GIFReader. |
|
321 |
FileSuffixToImageReaderClassMapping at:'tif' put:TIFFReader. |
|
2298 | 322 |
! |
323 |
||
324 |
initializeParentesisSpecMappings |
|
325 |
|spec| |
|
326 |
||
327 |
TypeToParentesisSpecMapping := Dictionary new. |
|
328 |
SuffixToParentesisSpecMapping := Dictionary new. |
|
329 |
||
330 |
"/ ST/X spec |
|
331 |
spec := IdentityDictionary new. |
|
332 |
spec at:#open put:#( $( $[ ${ "$> $<") . |
|
333 |
spec at:#close put:#( $) $] $} "$> $<"). |
|
334 |
spec at:#ignore put:#( $' $" '$[' '$]' '${' '$)' ). |
|
335 |
spec at:#eolComment put:'"/'. |
|
336 |
||
337 |
TypeToParentesisSpecMapping |
|
338 |
at:'application/x-smalltalk-source' |
|
339 |
put:spec. |
|
340 |
||
2479 | 341 |
"/ XML & HTML |
2298 | 342 |
spec := IdentityDictionary new. |
343 |
spec at:#open put:#( $< ) . |
|
2479 | 344 |
spec at:#close put:#( $> ). |
2298 | 345 |
spec at:#ignore put:#( $' $" '$[' '$]' '${' '$)' ). |
346 |
||
347 |
#('text/html' 'text/xml' 'application/xml') |
|
348 |
do:[:eachXMLType | |
|
349 |
TypeToParentesisSpecMapping |
|
350 |
at:eachXMLType |
|
351 |
put:spec |
|
352 |
]. |
|
353 |
||
2479 | 354 |
"/ ANSI-c, Java, C# |
2298 | 355 |
spec := IdentityDictionary new. |
356 |
spec at:#open put:#( $( $[ ${ ) . |
|
357 |
spec at:#close put:#( $) $] $} ). |
|
358 |
spec at:#ignore put:#( $' $" ). |
|
359 |
spec at:#eolComment put:'//'. |
|
360 |
||
361 |
TypeToParentesisSpecMapping |
|
362 |
at:'application/x-c-source' |
|
363 |
put:spec. |
|
364 |
||
365 |
TypeToParentesisSpecMapping |
|
366 |
at:'application/x-cpp-source' |
|
367 |
put:spec. |
|
368 |
||
369 |
TypeToParentesisSpecMapping |
|
2479 | 370 |
at:'application/x-csharp-source' |
371 |
put:spec. |
|
372 |
||
373 |
TypeToParentesisSpecMapping |
|
2298 | 374 |
at:'application/x-java-source' |
375 |
put:spec. |
|
376 |
||
377 |
TypeToParentesisSpecMapping |
|
378 |
at:'application/x-javascript' |
|
379 |
put:spec. |
|
380 |
||
381 |
"/ Lisp |
|
382 |
spec := IdentityDictionary new. |
|
383 |
spec at:#open put:#( $( ) . |
|
384 |
spec at:#close put:#( $) ). |
|
385 |
spec at:#ignore put:#( $" ). |
|
386 |
spec at:#eolComment put:';'. |
|
387 |
||
388 |
TypeToParentesisSpecMapping |
|
389 |
at:'application/x-lisp-source' |
|
390 |
put:spec. |
|
391 |
||
392 |
"Created: / 10-04-2007 / 15:16:37 / cg" |
|
1729 | 393 |
! ! |
394 |
||
395 |
!MIMETypes class methodsFor:'initialization-lists'! |
|
396 |
||
397 |
applicationCompressorsAndArchiveTypeList |
|
1604 | 398 |
^ #( |
1890 | 399 |
'tar' 'application/x-tar' |
400 |
'gtar' 'application/x-gtar' |
|
1891 | 401 |
('tgz' 'tar.gz') 'application/x-tar-gzip-compressed' "/ 'application/x-tar-compressed' |
402 |
('tar.bz2') 'application/x-tar-bzip2-compressed' |
|
1890 | 403 |
'zip' 'application/x-zip-compressed' |
404 |
'bz2' 'application/x-bzip2-compressed' |
|
405 |
('gz' 'z') 'application/x-gzip-compressed' |
|
406 |
'cpio' 'application/x-cpio' |
|
407 |
'shar' 'application/x-shar' |
|
408 |
'jar' 'application/java-archive' |
|
409 |
'sar' 'application/x-squeak-archive' |
|
410 |
'sit' 'application/x-stuffit' |
|
411 |
'hqx' 'application/mac-binhex40' |
|
412 |
'cpt' 'application/mac-compactpro' |
|
1604 | 413 |
) |
414 |
! |
|
645 | 415 |
|
1609 | 416 |
applicationMiscTypeList |
417 |
"misc applications" |
|
418 |
||
419 |
^ #( |
|
420 |
('a' 'o' 'obj' ) 'application/binary' |
|
421 |
'a' 'application/library' |
|
422 |
('dll' 'so') 'application/shared-library' |
|
423 |
) |
|
424 |
! |
|
425 |
||
1604 | 426 |
applicationProgLangTypeList |
1606 | 427 |
"applications for programm languages" |
713 | 428 |
|
1604 | 429 |
^ #( |
1609 | 430 |
('st' 'cls' 'rc') 'application/x-smalltalk-source' |
1604 | 431 |
'sif' 'application/x-smalltalk-source-sif' |
1668 | 432 |
'pac' 'application/x-smalltalk-dolphin-package' |
1778 | 433 |
|
434 |
'sts' 'application/x-squeak-source' |
|
435 |
'pr' 'application/x-squeak-project' |
|
436 |
||
1604 | 437 |
'c' 'application/x-c-source' |
438 |
('cc' 'cpp') 'application/x-cpp-source' |
|
2479 | 439 |
'cs' 'application/x-csharp-source' |
1609 | 440 |
('h' 'hi') 'application/x-c-header' |
1604 | 441 |
('js' 'mocha') 'application/x-javascript' |
442 |
('java' 'jav') 'application/x-java-source' |
|
443 |
'sh' 'application/x-sh' |
|
444 |
'csh' 'application/x-csh' |
|
445 |
'tcl' 'application/x-tcl' |
|
446 |
'pl' 'application/x-perl' |
|
447 |
'mak' 'application/x-make' |
|
448 |
'bat' 'application/x-batch-script' |
|
449 |
('asn1' 'x409' 'gdmo' 'gdm') 'application/x-asn1-source' |
|
2298 | 450 |
('lisp' 'lsp' 'scm' 'ss') 'application/x-lisp-source' |
1604 | 451 |
) |
2298 | 452 |
|
453 |
"Modified: / 09-04-2007 / 09:46:04 / cg" |
|
1604 | 454 |
! |
1561 | 455 |
|
1604 | 456 |
applicationTextTypeList |
1606 | 457 |
"text applications" |
1604 | 458 |
|
459 |
^ #( |
|
460 |
('ps' 'eps') 'application/postscript' |
|
1778 | 461 |
"/ 'ai' 'application/postscript' |
1604 | 462 |
'pdf' 'application/pdf' |
463 |
'rtf' 'application/rtf' |
|
1778 | 464 |
"/ 'rtf' 'text/rtf' ???? |
465 |
"/ 'doc' 'application/winword' |
|
1779 | 466 |
'doc' 'application/ms-word-document' |
1778 | 467 |
'swf' 'application/x-shockwave-flash' |
468 |
('ppt' 'ppz' 'pot' 'pps') 'application/mspowerpoint' |
|
2028 | 469 |
'xls' 'application/x-excel' |
470 |
'slk' 'application/vnd.ms-excel' |
|
1604 | 471 |
) |
472 |
! |
|
473 |
||
474 |
applicationTypeList |
|
1606 | 475 |
"applications" |
1604 | 476 |
|
1729 | 477 |
|typeList| |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
478 |
|
1729 | 479 |
typeList := OrderedCollection new. |
480 |
typeList addAll:self applicationProgLangTypeList. |
|
481 |
typeList addAll:self applicationTextTypeList. |
|
482 |
typeList addAll:self applicationCompressorsAndArchiveTypeList. |
|
483 |
typeList addAll:self applicationMiscTypeList. |
|
1616 | 484 |
|
1729 | 485 |
^ typeList |
1604 | 486 |
! |
487 |
||
488 |
audioTypeList |
|
1606 | 489 |
"audio formats ..." |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
490 |
|
1604 | 491 |
^ #( |
1720 | 492 |
('au' 'snd') 'audio/basic' |
1778 | 493 |
('ra') 'audio/x-realaudio' |
494 |
('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
|
495 |
"/ cg: see unixSpecific / windowsSpecific |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
496 |
"/ 'rpm' 'audio/x-pn-realaudio-plugin' |
1720 | 497 |
('mpa' 'mpega') 'audio/mpeg' |
1778 | 498 |
"/ 'mp3' 'audio/x-mp3' |
499 |
('mp3' 'mp2') 'audio/mpeg' |
|
1604 | 500 |
'wav' 'audio/x-wav' |
501 |
('aif' 'aiff' 'aifc') 'audio/x-aiff' |
|
1778 | 502 |
('midi' 'mid') 'audio/midi' |
1604 | 503 |
) |
504 |
! |
|
505 |
||
506 |
imageTypeList |
|
507 |
||
508 |
^ #( |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
509 |
"/ image formats ... |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
510 |
|
1216 | 511 |
('jpg' 'jpeg') 'image/jpeg' |
1188 | 512 |
'gif' 'image/gif' |
513 |
('tif' 'tiff') 'image/tiff' |
|
514 |
'xbm' 'image/x-xbitmap' |
|
515 |
'xpm' 'image/x-xpixmap' |
|
1720 | 516 |
'png' 'image/png' |
1188 | 517 |
'pcd' 'image/x-photo-cd' |
518 |
'bmp' 'image/x-MS-bmp' |
|
519 |
'rgb' 'image/x-rgb' |
|
520 |
'ppm' 'image/x-portable-pixmap' |
|
521 |
'pgm' 'image/x-portable-graymap' |
|
522 |
'pbm' 'image/x-portable-bitmap' |
|
523 |
'pnm' 'image/x-portable-anymap' |
|
524 |
'xwd' 'image/x-xwindowdump' |
|
525 |
'ras' 'image/x-cmu-raster' |
|
1216 | 526 |
'tga' 'image/x-targa' |
2020 | 527 |
'ico' 'image/x-ico' |
1604 | 528 |
) |
529 |
! |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
530 |
|
1609 | 531 |
miscFilenameList |
532 |
"other formats (not by suffix, but by fileName isnstead) ..." |
|
533 |
||
534 |
^ #( |
|
2113 | 535 |
('makefile' 'make.proto' 'make.spec' 'nt.mak') 'application/x-make' |
536 |
('exe' 'bin') 'application/octet-stream' |
|
537 |
('class') 'application/octet-stream' |
|
2375 | 538 |
('top') 'application/x-waltop-digital-notepad' |
1609 | 539 |
) |
540 |
! |
|
541 |
||
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
542 |
osSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
543 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
544 |
^ self windowsSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
545 |
]. |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
546 |
^ self unixSpecificTypeList |
2023 | 547 |
|
548 |
" |
|
549 |
self osSpecificTypeList |
|
550 |
" |
|
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
551 |
! |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
552 |
|
1604 | 553 |
textTypeList |
554 |
"/ misc text ... |
|
555 |
||
556 |
^ #( |
|
1887 | 557 |
('html' 'htm' 'shtml') 'text/html' |
1604 | 558 |
('txt' 'text') 'text/plain' |
1680 | 559 |
'xml' 'text/xml' |
1777 | 560 |
'css' 'text/css' |
2432 | 561 |
'csv' 'text/csv' |
1604 | 562 |
) |
563 |
! |
|
564 |
||
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
565 |
unixSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
566 |
|
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
567 |
^ #( |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
568 |
"/ 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
|
569 |
"/ 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
|
570 |
'rpm' 'application/x-rpm' |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
571 |
) |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
572 |
! |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
573 |
|
1604 | 574 |
videoTypeList |
575 |
"/ video formats ... |
|
576 |
||
577 |
^ #( |
|
1720 | 578 |
('qt' 'mov' 'moov') 'video/quicktime' |
579 |
('mpv' 'mpegv' 'mpg' 'mpeg' 'mpe') 'video/mpeg' |
|
1604 | 580 |
'movie' 'video/x-sgi-movie' |
1820 | 581 |
('avi' 'wmv' 'asf') 'video/x-msvideo' |
1604 | 582 |
('mpv2' 'mp2v' 'mp2' 'mpeg2') 'video/x-mpeg2' |
1680 | 583 |
'rm' 'application/vnd.rn-realmedia' |
584 |
'rv' 'video/x-pn-realvideo' |
|
1778 | 585 |
) |
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
586 |
! |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
587 |
|
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
588 |
windowsSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
589 |
^ #( |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
590 |
"/ 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
|
591 |
"/ 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
|
592 |
'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
|
593 |
) |
643 | 594 |
! ! |
595 |
||
1729 | 596 |
!MIMETypes class methodsFor:'obsolete'! |
1489 | 597 |
|
1729 | 598 |
fontForCharset:aCharSetName |
599 |
"return the font-encoding for an iso-charset" |
|
1489 | 600 |
|
1981 | 601 |
<resource:#obsolete> |
1729 | 602 |
self obsoleteMethodWarning:'use FontDescription >> fontNamePatternForCharset:'. |
603 |
^ FontDescription fontNamePatternForCharset:aCharSetName. |
|
1489 | 604 |
|
605 |
" |
|
1729 | 606 |
MIMETypes fontForCharset:'iso2022-jp' |
607 |
MIMETypes fontForCharset:'euc-jp' |
|
1472 | 608 |
" |
609 |
||
1729 | 610 |
"Modified: / 1.8.1998 / 17:00:57 / cg" |
611 |
! ! |
|
1472 | 612 |
|
1729 | 613 |
!MIMETypes class methodsFor:'queries'! |
1472 | 614 |
|
647 | 615 |
defineImageType:mimeType suffix:aSuffix reader:aReaderClass |
616 |
"register an image reader." |
|
617 |
||
618 |
aSuffix notNil ifTrue:[ |
|
619 |
self imageReaderForSuffix:aSuffix put:aReaderClass. |
|
620 |
]. |
|
621 |
||
622 |
mimeType notNil ifTrue:[ |
|
623 |
self imageReaderForType:mimeType put:aReaderClass |
|
624 |
]. |
|
625 |
||
626 |
(aSuffix notNil and:[mimeType notNil]) ifTrue:[ |
|
627 |
self mimeTypeForSuffix:aSuffix put:mimeType |
|
628 |
]. |
|
629 |
! |
|
630 |
||
643 | 631 |
fileSuffixToImageReaderMapping |
1021 | 632 |
"return the suffix-to-imageReader mapping" |
633 |
||
643 | 634 |
^ FileSuffixToImageReaderClassMapping ? #() |
635 |
||
1021 | 636 |
"Modified: / 1.8.1998 / 17:00:11 / cg" |
643 | 637 |
! |
638 |
||
639 |
imageFileSuffixes |
|
1021 | 640 |
"return a collection with known file suffixes" |
641 |
||
643 | 642 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[^ #()]. |
643 |
^ FileSuffixToImageReaderClassMapping keys |
|
644 |
||
1021 | 645 |
"Created: / 30.6.1997 / 22:04:48 / cg" |
646 |
"Modified: / 1.8.1998 / 17:01:26 / cg" |
|
643 | 647 |
! |
648 |
||
1473 | 649 |
mimeTypeForFilename:filenameArg |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
650 |
"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
|
651 |
|
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
652 |
|type filename lcFilename suff suff2| |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
653 |
|
1473 | 654 |
filename := filenameArg asFilename. |
1474 | 655 |
|
656 |
lcFilename := filename baseName asLowercase. |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
657 |
type := FilenameToTypeMapping at:lcFilename ifAbsent:nil. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
658 |
type isNil ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
659 |
"/ allow for fallback ... |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
660 |
type := OperatingSystem mimeTypeForFilename:lcFilename. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
661 |
"/ 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
|
662 |
"/ 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
|
663 |
"/ the OS. |
1275 | 664 |
"/ type isNil ifTrue:[ |
665 |
"/ FilenameToTypeMapping at:lcFilename put:#unknown |
|
666 |
"/ ]. |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
667 |
]. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
668 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
669 |
type == #unknown ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
670 |
type := nil. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
671 |
]. |
1273
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
672 |
|
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
673 |
type isNil ifTrue:[ |
1473 | 674 |
suff := filename suffix. |
1273
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
675 |
suff size ~~ 0 ifTrue:[ |
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
676 |
"/ sigh - special code for multiple-suffices... |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
677 |
"/ .tar.gz -> tgz |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
678 |
suff2 := filename withoutSuffix suffix. |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
679 |
suff2 size > 0 ifTrue:[ |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
680 |
type := self mimeTypeForSuffix:(suff2 , '.' , suff). |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
681 |
]. |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
682 |
type isNil ifTrue:[ |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
683 |
type := self mimeTypeForSuffix:suff |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
684 |
]. |
1273
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
685 |
] |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
686 |
]. |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
687 |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
688 |
^ type |
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
689 |
|
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
690 |
" |
1841 | 691 |
self mimeTypeForFilename:'typeinst.dvi' |
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
692 |
self mimeTypeForFilename:'foo.tar' |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
693 |
self mimeTypeForFilename:'foo.tgz' |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
694 |
self mimeTypeForFilename:'foo.tar.gz' |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
695 |
" |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
696 |
! |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
697 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
698 |
mimeTypeForFilename:filename put:mimeType |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
699 |
"register a mime type for a filename" |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
700 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
701 |
FilenameToTypeMapping isNil ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
702 |
FilenameToTypeMapping := Dictionary new |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
703 |
]. |
1612 | 704 |
FilenameToTypeMapping at:filename put:(MIMEType fromString:mimeType asLowercase) |
1611 | 705 |
! |
706 |
||
643 | 707 |
mimeTypeForSuffix:suffix |
1021 | 708 |
"given a file suffix, return the mime-type" |
709 |
||
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
710 |
|type lcSuffix| |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
711 |
|
1837 | 712 |
suffix = LastSuffix ifTrue:[ |
713 |
^ LastType |
|
714 |
]. |
|
715 |
||
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
716 |
lcSuffix := suffix asLowercase. |
1837 | 717 |
type := FileSuffixToTypeMapping at:lcSuffix ifAbsent:nil. |
718 |
type isNil ifTrue:[ |
|
719 |
"/ allow for fallback ... |
|
720 |
type := OperatingSystem mimeTypeForSuffix:lcSuffix. |
|
721 |
"/ the special value #unknown is returned as nil; |
|
722 |
"/ this avoids constant retry if a mimeType is not known in the OS. |
|
723 |
||
724 |
type := type ? #unknown. |
|
725 |
FileSuffixToTypeMapping at:lcSuffix put:type. |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
726 |
]. |
1837 | 727 |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
728 |
type == #unknown ifTrue:[ |
1837 | 729 |
type := nil. |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
730 |
]. |
1840 | 731 |
type notNil ifTrue:[ |
732 |
LastSuffix := suffix. |
|
733 |
LastType := MIMEType fromString:type. |
|
734 |
^ LastType |
|
735 |
]. |
|
1841 | 736 |
^ type |
643 | 737 |
|
1666 | 738 |
" |
1840 | 739 |
self mimeTypeForSuffix:'gif' |
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
740 |
self mimeTypeForSuffix:'rpm' |
1666 | 741 |
" |
742 |
||
1021 | 743 |
"Created: / 30.6.1997 / 21:55:51 / cg" |
1300 | 744 |
"Modified: / 23.12.1999 / 22:30:55 / cg" |
643 | 745 |
! |
746 |
||
747 |
mimeTypeForSuffix:suffix put:mimeType |
|
1021 | 748 |
"register a mime type for a file suffix" |
749 |
||
643 | 750 |
FileSuffixToTypeMapping isNil ifTrue:[ |
751 |
FileSuffixToTypeMapping := Dictionary new |
|
752 |
]. |
|
753 |
FileSuffixToTypeMapping at:suffix put:mimeType asLowercase |
|
754 |
||
1021 | 755 |
"Created: / 30.6.1997 / 21:56:20 / cg" |
756 |
"Modified: / 1.8.1998 / 17:03:18 / cg" |
|
1593 | 757 |
! |
758 |
||
759 |
mimeTypeForSuffixMapping |
|
760 |
||
761 |
^ FileSuffixToTypeMapping |
|
1611 | 762 |
! |
763 |
||
2023 | 764 |
mimeTypeFromString:mimeTypeString |
765 |
"given a mime-type for a string" |
|
766 |
||
767 |
^ MIMEType fromString:mimeTypeString |
|
768 |
||
769 |
" |
|
770 |
self mimeTypeFromString:'image/gif' |
|
771 |
" |
|
772 |
! |
|
773 |
||
1611 | 774 |
mimeTypeOfContents:filename |
775 |
"given a filename, scan the contents, return the mime-type or nil, if unknown" |
|
776 |
||
1612 | 777 |
|typeString| |
778 |
||
779 |
typeString := filename mimeTypeOfContents. |
|
780 |
typeString isNil ifTrue:[^ nil]. |
|
781 |
^ MIMEType fromString:typeString. |
|
1887 | 782 |
! |
783 |
||
784 |
suffixForMimeType:mimeType |
|
785 |
"given a file suffix, return the mime-type" |
|
786 |
||
787 |
^ TypeToFileSuffixMapping at:mimeType ifAbsent:nil |
|
788 |
||
789 |
" |
|
790 |
self suffixForMimeType:(MIMEType fromString:'image/gif') |
|
791 |
" |
|
792 |
||
793 |
"Created: / 30.6.1997 / 21:55:51 / cg" |
|
794 |
"Modified: / 23.12.1999 / 22:30:55 / cg" |
|
795 |
! |
|
796 |
||
797 |
suffixForMimeTypeString:mimeTypeString |
|
798 |
"given a file suffix, return the mime-type" |
|
799 |
||
800 |
^ self suffixForMimeType:(MIMEType fromString:mimeTypeString) |
|
801 |
||
802 |
" |
|
803 |
self suffixForMimeTypeString:'image/gif' |
|
804 |
" |
|
805 |
||
806 |
"Created: / 30.6.1997 / 21:55:51 / cg" |
|
807 |
"Modified: / 23.12.1999 / 22:30:55 / cg" |
|
1612 | 808 |
! ! |
809 |
||
2116 | 810 |
!MIMETypes class methodsFor:'queries-applications'! |
811 |
||
2117 | 812 |
defaultCommandForMimeType:mimeType |
813 |
self obsoleteMethodWarning:'use #defaultCommandTemplateToOpenMimeType:'. |
|
814 |
||
815 |
^ self defaultCommandTemplateToOpenMimeType:mimeType |
|
816 |
||
817 |
" |
|
818 |
MIMETypes defaultCommandForMimeType:'application/pdf' |
|
819 |
" |
|
820 |
||
821 |
"Created: / 12-05-2004 / 11:09:22 / cg" |
|
822 |
"Modified: / 12-05-2004 / 11:16:53 / cg" |
|
823 |
! |
|
824 |
||
825 |
defaultCommandPerMIME |
|
826 |
"returns the collection which is used to map MIME-type to command-templates." |
|
827 |
||
828 |
"TODO: move this to OS/UserPreferences" |
|
829 |
||
830 |
DefaultCommandPerMIMEPerOS isNil ifTrue:[ |
|
831 |
self initializeDefaultCommands |
|
832 |
]. |
|
833 |
OperatingSystem isUNIXlike ifTrue:[ |
|
834 |
^ DefaultCommandPerMIMEPerOS at:#unix |
|
835 |
]. |
|
836 |
^ DefaultCommandPerMIMEPerOS at:#win32 |
|
837 |
! |
|
838 |
||
2116 | 839 |
defaultCommandTemplateToOpenMimeType:mimeType |
840 |
|cmd| |
|
841 |
||
842 |
cmd := self defaultCommandPerMIME at:mimeType ifAbsent:nil. |
|
843 |
cmd isNil ifTrue:[ |
|
844 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
|
845 |
cmd := Win32OperatingSystem::RegistryEntry commandTemplateToOpenMimeType:mimeType |
|
846 |
]. |
|
847 |
]. |
|
848 |
^ cmd |
|
849 |
||
850 |
" |
|
851 |
MIMETypes defaultCommandTemplateToOpenMimeType:'application/pdf' |
|
2118 | 852 |
MIMETypes defaultCommandTemplateToOpenMimeType:'text/html' |
2116 | 853 |
" |
854 |
||
855 |
"Created: / 12-05-2004 / 11:09:22 / cg" |
|
856 |
"Modified: / 12-05-2004 / 11:16:53 / cg" |
|
857 |
! |
|
858 |
||
859 |
defaultCommandTemplateToPrintMimeType:mimeType |
|
860 |
|cmd| |
|
861 |
||
862 |
cmd := self defaultPrintCommandPerMIME at:mimeType ifAbsent:nil. |
|
863 |
cmd isNil ifTrue:[ |
|
864 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
|
865 |
cmd := Win32OperatingSystem::RegistryEntry commandTemplateToPrintMimeType:mimeType |
|
866 |
]. |
|
867 |
]. |
|
868 |
^ cmd |
|
869 |
||
870 |
" |
|
871 |
MIMETypes defaultCommandTemplateToPrintMimeType:'application/pdf' |
|
872 |
" |
|
2117 | 873 |
! |
874 |
||
875 |
defaultPrintCommandPerMIME |
|
876 |
"returns the collection which is used to map MIME-type to printing command-templates." |
|
877 |
||
878 |
"TODO: move this to OS/UserPreferences" |
|
879 |
||
880 |
DefaultPrintCommandPerMIMEPerOS isNil ifTrue:[ |
|
881 |
self initializeDefaultCommands |
|
882 |
]. |
|
883 |
OperatingSystem isUNIXlike ifTrue:[ |
|
884 |
^ DefaultPrintCommandPerMIMEPerOS at:#unix |
|
885 |
]. |
|
886 |
^ DefaultPrintCommandPerMIMEPerOS at:#win32 |
|
2116 | 887 |
! ! |
888 |
||
1729 | 889 |
!MIMETypes class methodsFor:'queries-image formats'! |
890 |
||
891 |
imageReaderClasses |
|
892 |
"return a collection of registered image reader classes" |
|
893 |
||
894 |
|setOfClasses| |
|
895 |
||
896 |
setOfClasses := IdentitySet new. |
|
897 |
FileSuffixToImageReaderClassMapping notNil ifTrue:[ |
|
898 |
FileSuffixToImageReaderClassMapping keysAndValuesDo:[:suff :cls | |
|
899 |
setOfClasses add:cls |
|
900 |
]. |
|
901 |
]. |
|
902 |
TypeToImageReaderClassMapping notNil ifTrue:[ |
|
903 |
TypeToImageReaderClassMapping keysAndValuesDo:[:suff :cls | |
|
904 |
setOfClasses add:cls |
|
905 |
]. |
|
906 |
]. |
|
907 |
^ setOfClasses |
|
908 |
||
909 |
"Created: / 30.6.1997 / 22:03:42 / cg" |
|
910 |
"Modified: / 1.8.1998 / 16:59:52 / cg" |
|
911 |
! |
|
912 |
||
913 |
imageReaderForSuffix:aSuffix |
|
914 |
"given a file suffix, return an approriate image reader class" |
|
915 |
||
916 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[^ nil]. |
|
917 |
^ FileSuffixToImageReaderClassMapping at:aSuffix asLowercase ifAbsent:nil |
|
918 |
||
919 |
"Created: / 30.6.1997 / 21:59:11 / cg" |
|
920 |
"Modified: / 1.8.1998 / 17:01:58 / cg" |
|
921 |
! |
|
922 |
||
923 |
imageReaderForSuffix:aSuffix put:aReaderClass |
|
924 |
"register an image reader for a file suffix" |
|
925 |
||
926 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[ |
|
927 |
FileSuffixToImageReaderClassMapping := Dictionary new. |
|
928 |
]. |
|
929 |
FileSuffixToImageReaderClassMapping at:aSuffix asLowercase put:aReaderClass |
|
930 |
||
931 |
"Created: / 30.6.1997 / 21:59:43 / cg" |
|
932 |
"Modified: / 1.8.1998 / 17:02:14 / cg" |
|
933 |
! |
|
934 |
||
935 |
imageReaderForType:mimeTypeString |
|
936 |
"given a mime-type, return an approriate image reader class" |
|
937 |
||
938 |
TypeToImageReaderClassMapping isNil ifTrue:[^ nil]. |
|
939 |
^ TypeToImageReaderClassMapping at:mimeTypeString asLowercase ifAbsent:nil |
|
940 |
||
941 |
"Created: / 30.6.1997 / 21:56:01 / cg" |
|
942 |
"Modified: / 1.8.1998 / 17:02:28 / cg" |
|
943 |
! |
|
944 |
||
945 |
imageReaderForType:mimeTypeString put:aReaderClass |
|
946 |
"register an image reader for a mime-type" |
|
947 |
||
948 |
TypeToImageReaderClassMapping isNil ifTrue:[ |
|
949 |
TypeToImageReaderClassMapping := Dictionary new. |
|
950 |
]. |
|
951 |
TypeToImageReaderClassMapping at:mimeTypeString asLowercase put:aReaderClass |
|
952 |
||
953 |
"Created: / 30.6.1997 / 21:56:11 / cg" |
|
954 |
"Modified: / 1.8.1998 / 17:02:40 / cg" |
|
955 |
! ! |
|
956 |
||
957 |
!MIMETypes class methodsFor:'queries-language syntax'! |
|
958 |
||
959 |
commentStringsForFilename:aFilename |
|
960 |
"return a useful comment definition; heuristics for now. |
|
961 |
The returned value is an array of 2 elements; |
|
962 |
the first is the end-of-line comment string (or nil); |
|
963 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
964 |
||
965 |
|mime| |
|
966 |
||
967 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
968 |
^ self commentStringsForMimeType:mime suffix:(aFilename asFilename suffix) |
|
969 |
||
970 |
" |
|
971 |
MIMETypes commentStringsForFilename:'Makefile'. |
|
972 |
MIMETypes commentStringsForFilename:'Object.st'. |
|
973 |
MIMETypes commentStringsForFilename:'Foo.java'. |
|
1925 | 974 |
MIMETypes commentStringsForFilename:'Foo.html'. |
1729 | 975 |
" |
976 |
! |
|
977 |
||
978 |
commentStringsForFilename:aFilename ifUnknown:alternativeBlockReturningCommentString |
|
979 |
"return a useful comment definition; heuristics for now. |
|
980 |
The returned value is an array of 2 elements; |
|
981 |
the first is the end-of-line comment string (or nil); |
|
982 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
983 |
||
984 |
|mime| |
|
985 |
||
986 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
987 |
^ self commentStringsForMimeType:mime suffix:(aFilename asFilename suffix) ifUnknown:alternativeBlockReturningCommentString |
|
988 |
||
989 |
" |
|
990 |
MIMETypes commentStringsForFilename:'Makefile'. |
|
991 |
MIMETypes commentStringsForFilename:'Object.st'. |
|
992 |
MIMETypes commentStringsForFilename:'Foo.java'. |
|
993 |
" |
|
994 |
! |
|
995 |
||
996 |
commentStringsForMimeType:mime suffix:suff |
|
997 |
"return a useful comment definition; heuristics for now. |
|
998 |
The returned value is an array of 2 elements; |
|
999 |
the first is the end-of-line comment string (or nil); |
|
1000 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
1001 |
||
1002 |
^ self |
|
1003 |
commentStringsForMimeType:mime suffix:suff |
|
1004 |
ifUnknown: #(';' (nil nil)) |
|
1005 |
||
1006 |
" |
|
1007 |
|mime| |
|
1008 |
||
1009 |
mime := MIMETypes mimeTypeForFilename:'Makefile'. |
|
1010 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
1011 |
" |
|
1012 |
||
1013 |
" |
|
1014 |
|mime| |
|
1015 |
||
1016 |
mime := MIMETypes mimeTypeForFilename:'Object.st'. |
|
1017 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
1018 |
" |
|
1019 |
! |
|
1020 |
||
1021 |
commentStringsForMimeType:mime suffix:suff ifUnknown:alternativeBlockReturningCommentString |
|
1022 |
"return a useful comment definition; heuristics for now. |
|
1023 |
The returned value is an array of 2 elements; |
|
1024 |
the first is the end-of-line comment string (or nil); |
|
1025 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
1026 |
||
1027 |
|commentSpec| |
|
1028 |
||
1029 |
commentSpec := TypeToCommentStringMapping at:mime ifAbsent:nil. |
|
1030 |
commentSpec notNil ifTrue:[ |
|
1031 |
^ commentSpec |
|
1032 |
]. |
|
1033 |
||
1034 |
commentSpec := SuffixToCommentStringMapping at:suff ifAbsent:nil. |
|
1035 |
commentSpec notNil ifTrue:[ |
|
1036 |
^ commentSpec |
|
1037 |
]. |
|
1038 |
||
1039 |
^ alternativeBlockReturningCommentString value |
|
1040 |
||
1041 |
" |
|
1042 |
|mime| |
|
1043 |
||
1044 |
mime := MIMETypes mimeTypeForFilename:'Makefile'. |
|
1045 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
1046 |
" |
|
1047 |
||
1048 |
" |
|
1049 |
|mime| |
|
1050 |
||
1051 |
mime := MIMETypes mimeTypeForFilename:'Object.st'. |
|
1052 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
1053 |
" |
|
2298 | 1054 |
! |
1055 |
||
1056 |
parentesisSpecForFilename:aFilename |
|
1057 |
"return a useful parentesis spec; heuristics for now. |
|
1058 |
The returned value is a dictionary to be used as parentesis spec in an editor" |
|
1059 |
||
1060 |
|mime| |
|
1061 |
||
1062 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
1063 |
^ self parentesisSpecForMimeType:mime suffix:(aFilename asFilename suffix) |
|
1064 |
||
1065 |
" |
|
1066 |
MIMETypes parentesisSpecForFilename:'Object.st'. |
|
1067 |
MIMETypes parentesisSpecForFilename:'Foo.java'. |
|
1068 |
MIMETypes parentesisSpecForFilename:'Foo.html'. |
|
1069 |
MIMETypes parentesisSpecForFilename:'Foo.lsp'. |
|
1070 |
" |
|
1071 |
||
1072 |
"Created: / 10-04-2007 / 15:18:41 / cg" |
|
1073 |
! |
|
1074 |
||
1075 |
parentesisSpecForFilename:aFilename ifUnknown:alternative |
|
1076 |
|mime| |
|
1077 |
||
1078 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
1079 |
^ self parentesisSpecForMimeType:mime suffix:(aFilename asFilename suffix) ifUnknown:alternative |
|
1080 |
||
1081 |
"Created: / 10-04-2007 / 15:26:20 / cg" |
|
1082 |
! |
|
1083 |
||
1084 |
parentesisSpecForMimeType:mime suffix:suff |
|
1085 |
^ self |
|
1086 |
parentesisSpecForMimeType:mime suffix:suff |
|
1087 |
ifUnknown: nil |
|
1088 |
||
1089 |
"Created: / 10-04-2007 / 15:19:39 / cg" |
|
1090 |
! |
|
1091 |
||
1092 |
parentesisSpecForMimeType:mime suffix:suff ifUnknown:alternativeValue |
|
1093 |
|spec| |
|
1094 |
||
1095 |
spec := TypeToParentesisSpecMapping at:mime ifAbsent:nil. |
|
1096 |
spec notNil ifTrue:[ |
|
1097 |
^ spec |
|
1098 |
]. |
|
1099 |
||
1100 |
spec := SuffixToParentesisSpecMapping at:suff ifAbsent:nil. |
|
1101 |
spec notNil ifTrue:[ |
|
1102 |
^ spec |
|
1103 |
]. |
|
1104 |
||
1105 |
^ alternativeValue value |
|
1106 |
||
1107 |
"Created: / 10-04-2007 / 15:20:38 / cg" |
|
1729 | 1108 |
! ! |
1109 |
||
1612 | 1110 |
!MIMETypes::MIMEType class methodsFor:'documentation'! |
1111 |
||
1112 |
documentation |
|
1113 |
" |
|
1864 | 1114 |
like a string, but knows that it represents a mimeType. |
1612 | 1115 |
" |
1116 |
! ! |
|
1117 |
||
1118 |
!MIMETypes::MIMEType class methodsFor:'initialization'! |
|
1119 |
||
1120 |
initialize |
|
1121 |
CachedTypes := CacheDictionary new:30. |
|
1122 |
||
1123 |
" |
|
1124 |
self initialize |
|
1125 |
" |
|
1126 |
! ! |
|
1127 |
||
1128 |
!MIMETypes::MIMEType class methodsFor:'instance creation'! |
|
1129 |
||
1130 |
fromString:aString |
|
1131 |
|cachedType newType| |
|
1132 |
||
1133 |
aString class == self ifTrue:[^ aString]. |
|
1134 |
||
1135 |
cachedType := CachedTypes at:aString ifAbsent:nil. |
|
1136 |
cachedType notNil ifTrue:[^ cachedType]. |
|
1137 |
newType := aString copy changeClassTo:self. |
|
1138 |
CachedTypes at:aString put:newType. |
|
1139 |
^ newType |
|
1140 |
||
1141 |
" |
|
1142 |
self fromString:'text/html' |
|
1143 |
" |
|
1144 |
! ! |
|
1145 |
||
1146 |
!MIMETypes::MIMEType methodsFor:'queries'! |
|
1147 |
||
1693 | 1148 |
isArchive |
1864 | 1149 |
"return true, if I represent an archive type (such as zip or tar)" |
1150 |
||
1612 | 1151 |
|archivTypes| |
1152 |
||
1729 | 1153 |
archivTypes := MIMETypes applicationCompressorsAndArchiveTypeList. |
1612 | 1154 |
archivTypes pairWiseDo:[: ext : type | |
1155 |
self = type ifTrue:[ ^ true]. |
|
1156 |
]. |
|
1157 |
^ false |
|
1158 |
! |
|
1159 |
||
2024 | 1160 |
isBinary |
1161 |
"return true, if I represent a binary (non-text) type" |
|
1162 |
||
1163 |
^ self isTextType not |
|
1164 |
! |
|
1165 |
||
1612 | 1166 |
isHtml |
1864 | 1167 |
"return true, if I represent the html text type" |
1612 | 1168 |
|
1169 |
^ (self = 'text/html') |
|
1170 |
! |
|
1171 |
||
1172 |
isImage |
|
1864 | 1173 |
"return true, if I represent an image type (such as gif or jpg)" |
1612 | 1174 |
|
1693 | 1175 |
^ (self startsWith:'image/') |
1612 | 1176 |
! |
1177 |
||
1178 |
isPdf |
|
1864 | 1179 |
"return true, if I represent the pdf type" |
1180 |
||
1612 | 1181 |
^ (self = 'application/pdf') |
1182 |
! |
|
1183 |
||
1184 |
isSmalltalkSource |
|
1864 | 1185 |
"return true, if I represent the smalltalk sourcecode type" |
1186 |
||
1612 | 1187 |
^ (self = 'application/x-smalltalk-source') |
1783 | 1188 |
! |
1189 |
||
2024 | 1190 |
isTextType |
1191 |
"return true, if I represent some text type" |
|
1192 |
||
1193 |
^ self startsWith:'text/' |
|
1194 |
! |
|
1195 |
||
1783 | 1196 |
isXml |
1864 | 1197 |
"return true, if I represent the xml text type" |
1198 |
||
1783 | 1199 |
^ (self = 'text/xml') |
643 | 1200 |
! ! |
1201 |
||
1202 |
!MIMETypes class methodsFor:'documentation'! |
|
1203 |
||
1204 |
version |
|
2479 | 1205 |
^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.91 2008-05-26 08:36:40 cg Exp $' |
643 | 1206 |
! ! |
1666 | 1207 |
|
643 | 1208 |
MIMETypes initialize! |
1666 | 1209 |
MIMETypes::MIMEType initialize! |