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