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