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