author | penk |
Mon, 18 Oct 2004 15:48:30 +0200 | |
changeset 2020 | d5c5d7928433 |
parent 1981 | 52b15b1e90b6 |
child 2023 | 70c535a959be |
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' |
2020 | 420 |
'ico' 'image/x-ico' |
1604 | 421 |
) |
422 |
! |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
423 |
|
1609 | 424 |
miscFilenameList |
425 |
"other formats (not by suffix, but by fileName isnstead) ..." |
|
426 |
||
427 |
^ #( |
|
428 |
('makefile' 'make.proto') 'application/x-make' |
|
1778 | 429 |
('exe' 'bin') 'application/octet-stream' |
430 |
('class') 'application/octet-stream' |
|
1609 | 431 |
) |
432 |
! |
|
433 |
||
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
434 |
osSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
435 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
436 |
^ self windowsSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
437 |
]. |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
438 |
^ self unixSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
439 |
! |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
440 |
|
1604 | 441 |
textTypeList |
442 |
"/ misc text ... |
|
443 |
||
444 |
^ #( |
|
1887 | 445 |
('html' 'htm' 'shtml') 'text/html' |
1604 | 446 |
('txt' 'text') 'text/plain' |
1680 | 447 |
'xml' 'text/xml' |
1777 | 448 |
'css' 'text/css' |
1604 | 449 |
) |
450 |
! |
|
451 |
||
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
452 |
unixSpecificTypeList |
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 |
^ #( |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
455 |
"/ 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
|
456 |
"/ 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
|
457 |
'rpm' 'application/x-rpm' |
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 |
! |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
460 |
|
1604 | 461 |
videoTypeList |
462 |
"/ video formats ... |
|
463 |
||
464 |
^ #( |
|
1720 | 465 |
('qt' 'mov' 'moov') 'video/quicktime' |
466 |
('mpv' 'mpegv' 'mpg' 'mpeg' 'mpe') 'video/mpeg' |
|
1604 | 467 |
'movie' 'video/x-sgi-movie' |
1820 | 468 |
('avi' 'wmv' 'asf') 'video/x-msvideo' |
1604 | 469 |
('mpv2' 'mp2v' 'mp2' 'mpeg2') 'video/x-mpeg2' |
1680 | 470 |
'rm' 'application/vnd.rn-realmedia' |
471 |
'rv' 'video/x-pn-realvideo' |
|
1778 | 472 |
) |
1888
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 |
|
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
475 |
windowsSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
476 |
^ #( |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
477 |
"/ 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
|
478 |
"/ 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
|
479 |
'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
|
480 |
) |
643 | 481 |
! ! |
482 |
||
1729 | 483 |
!MIMETypes class methodsFor:'obsolete'! |
1489 | 484 |
|
1729 | 485 |
fontForCharset:aCharSetName |
486 |
"return the font-encoding for an iso-charset" |
|
1489 | 487 |
|
1981 | 488 |
<resource:#obsolete> |
1729 | 489 |
self obsoleteMethodWarning:'use FontDescription >> fontNamePatternForCharset:'. |
490 |
^ FontDescription fontNamePatternForCharset:aCharSetName. |
|
1489 | 491 |
|
492 |
" |
|
1729 | 493 |
MIMETypes fontForCharset:'iso2022-jp' |
494 |
MIMETypes fontForCharset:'euc-jp' |
|
1472 | 495 |
" |
496 |
||
1729 | 497 |
"Modified: / 1.8.1998 / 17:00:57 / cg" |
498 |
! ! |
|
1472 | 499 |
|
1729 | 500 |
!MIMETypes class methodsFor:'queries'! |
1472 | 501 |
|
1979
0612875a95c1
acroread command from registry (win32)
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
502 |
defaultCommandForMimeType:mimeType |
0612875a95c1
acroread command from registry (win32)
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
503 |
^ self defaultCommandPerMIME at:mimeType ifAbsent:nil. |
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 |
" |
0612875a95c1
acroread command from registry (win32)
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
506 |
MIMETypes defaultCommandForMimeType:'application/pdf' |
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 |
|
0612875a95c1
acroread command from registry (win32)
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
509 |
"Created: / 12-05-2004 / 11:09:22 / cg" |
0612875a95c1
acroread command from registry (win32)
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
510 |
"Modified: / 12-05-2004 / 11:16:53 / cg" |
0612875a95c1
acroread command from registry (win32)
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
511 |
! |
0612875a95c1
acroread command from registry (win32)
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
512 |
|
1691
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
513 |
defaultCommandPerMIME |
1729 | 514 |
"TODO: move this to OS/UserPreferences" |
1691
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
515 |
|
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
516 |
DefaultCommandPerMIMEPerOS isNil ifTrue:[ |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
517 |
self initializeDefaultCommands |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
518 |
]. |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
519 |
OperatingSystem isUNIXlike ifTrue:[ |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
520 |
^ DefaultCommandPerMIMEPerOS at:#unix |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
521 |
]. |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
522 |
^ DefaultCommandPerMIMEPerOS at:#win32 |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
523 |
! |
6ee1100ba672
defaultCommandPerMIME moved from FileBrowser
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
524 |
|
647 | 525 |
defineImageType:mimeType suffix:aSuffix reader:aReaderClass |
526 |
"register an image reader." |
|
527 |
||
528 |
aSuffix notNil ifTrue:[ |
|
529 |
self imageReaderForSuffix:aSuffix put:aReaderClass. |
|
530 |
]. |
|
531 |
||
532 |
mimeType notNil ifTrue:[ |
|
533 |
self imageReaderForType:mimeType put:aReaderClass |
|
534 |
]. |
|
535 |
||
536 |
(aSuffix notNil and:[mimeType notNil]) ifTrue:[ |
|
537 |
self mimeTypeForSuffix:aSuffix put:mimeType |
|
538 |
]. |
|
539 |
! |
|
540 |
||
643 | 541 |
fileSuffixToImageReaderMapping |
1021 | 542 |
"return the suffix-to-imageReader mapping" |
543 |
||
643 | 544 |
^ FileSuffixToImageReaderClassMapping ? #() |
545 |
||
1021 | 546 |
"Modified: / 1.8.1998 / 17:00:11 / cg" |
643 | 547 |
! |
548 |
||
549 |
imageFileSuffixes |
|
1021 | 550 |
"return a collection with known file suffixes" |
551 |
||
643 | 552 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[^ #()]. |
553 |
^ FileSuffixToImageReaderClassMapping keys |
|
554 |
||
1021 | 555 |
"Created: / 30.6.1997 / 22:04:48 / cg" |
556 |
"Modified: / 1.8.1998 / 17:01:26 / cg" |
|
643 | 557 |
! |
558 |
||
1473 | 559 |
mimeTypeForFilename:filenameArg |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
560 |
"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
|
561 |
|
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
562 |
|type filename lcFilename suff suff2| |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
563 |
|
1473 | 564 |
filename := filenameArg asFilename. |
1474 | 565 |
|
566 |
lcFilename := filename baseName asLowercase. |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
567 |
type := FilenameToTypeMapping at:lcFilename ifAbsent:nil. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
568 |
type isNil ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
569 |
"/ allow for fallback ... |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
570 |
type := OperatingSystem mimeTypeForFilename:lcFilename. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
571 |
"/ 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
|
572 |
"/ 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
|
573 |
"/ the OS. |
1275 | 574 |
"/ type isNil ifTrue:[ |
575 |
"/ FilenameToTypeMapping at:lcFilename put:#unknown |
|
576 |
"/ ]. |
|
1272
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 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
579 |
type == #unknown ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
580 |
type := nil. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
581 |
]. |
1273
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
582 |
|
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
583 |
type isNil ifTrue:[ |
1473 | 584 |
suff := filename suffix. |
1273
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
585 |
suff size ~~ 0 ifTrue:[ |
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
586 |
"/ sigh - special code for multiple-suffices... |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
587 |
"/ .tar.gz -> tgz |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
588 |
suff2 := filename withoutSuffix suffix. |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
589 |
suff2 size > 0 ifTrue:[ |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
590 |
type := self mimeTypeForSuffix:(suff2 , '.' , suff). |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
591 |
]. |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
592 |
type isNil ifTrue:[ |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
593 |
type := self mimeTypeForSuffix:suff |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
594 |
]. |
1273
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 |
]. |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
597 |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
598 |
^ type |
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
599 |
|
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
600 |
" |
1841 | 601 |
self mimeTypeForFilename:'typeinst.dvi' |
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
602 |
self mimeTypeForFilename:'foo.tar' |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
603 |
self mimeTypeForFilename:'foo.tgz' |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
604 |
self mimeTypeForFilename:'foo.tar.gz' |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
605 |
" |
1272
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 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
608 |
mimeTypeForFilename:filename put:mimeType |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
609 |
"register a mime type for a filename" |
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 |
FilenameToTypeMapping isNil ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
612 |
FilenameToTypeMapping := Dictionary new |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
613 |
]. |
1612 | 614 |
FilenameToTypeMapping at:filename put:(MIMEType fromString:mimeType asLowercase) |
1611 | 615 |
! |
616 |
||
643 | 617 |
mimeTypeForSuffix:suffix |
1021 | 618 |
"given a file suffix, return the mime-type" |
619 |
||
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
620 |
|type lcSuffix| |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
621 |
|
1837 | 622 |
suffix = LastSuffix ifTrue:[ |
623 |
^ LastType |
|
624 |
]. |
|
625 |
||
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
626 |
lcSuffix := suffix asLowercase. |
1837 | 627 |
type := FileSuffixToTypeMapping at:lcSuffix ifAbsent:nil. |
628 |
type isNil ifTrue:[ |
|
629 |
"/ allow for fallback ... |
|
630 |
type := OperatingSystem mimeTypeForSuffix:lcSuffix. |
|
631 |
"/ the special value #unknown is returned as nil; |
|
632 |
"/ this avoids constant retry if a mimeType is not known in the OS. |
|
633 |
||
634 |
type := type ? #unknown. |
|
635 |
FileSuffixToTypeMapping at:lcSuffix put:type. |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
636 |
]. |
1837 | 637 |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
638 |
type == #unknown ifTrue:[ |
1837 | 639 |
type := nil. |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
640 |
]. |
1840 | 641 |
type notNil ifTrue:[ |
642 |
LastSuffix := suffix. |
|
643 |
LastType := MIMEType fromString:type. |
|
644 |
^ LastType |
|
645 |
]. |
|
1841 | 646 |
^ type |
643 | 647 |
|
1666 | 648 |
" |
1840 | 649 |
self mimeTypeForSuffix:'gif' |
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
650 |
self mimeTypeForSuffix:'rpm' |
1666 | 651 |
" |
652 |
||
1021 | 653 |
"Created: / 30.6.1997 / 21:55:51 / cg" |
1300 | 654 |
"Modified: / 23.12.1999 / 22:30:55 / cg" |
643 | 655 |
! |
656 |
||
657 |
mimeTypeForSuffix:suffix put:mimeType |
|
1021 | 658 |
"register a mime type for a file suffix" |
659 |
||
643 | 660 |
FileSuffixToTypeMapping isNil ifTrue:[ |
661 |
FileSuffixToTypeMapping := Dictionary new |
|
662 |
]. |
|
663 |
FileSuffixToTypeMapping at:suffix put:mimeType asLowercase |
|
664 |
||
1021 | 665 |
"Created: / 30.6.1997 / 21:56:20 / cg" |
666 |
"Modified: / 1.8.1998 / 17:03:18 / cg" |
|
1593 | 667 |
! |
668 |
||
669 |
mimeTypeForSuffixMapping |
|
670 |
||
671 |
^ FileSuffixToTypeMapping |
|
1611 | 672 |
! |
673 |
||
674 |
mimeTypeOfContents:filename |
|
675 |
"given a filename, scan the contents, return the mime-type or nil, if unknown" |
|
676 |
||
1612 | 677 |
|typeString| |
678 |
||
679 |
typeString := filename mimeTypeOfContents. |
|
680 |
typeString isNil ifTrue:[^ nil]. |
|
681 |
^ MIMEType fromString:typeString. |
|
1887 | 682 |
! |
683 |
||
684 |
suffixForMimeType:mimeType |
|
685 |
"given a file suffix, return the mime-type" |
|
686 |
||
687 |
^ TypeToFileSuffixMapping at:mimeType ifAbsent:nil |
|
688 |
||
689 |
" |
|
690 |
self suffixForMimeType:(MIMEType fromString:'image/gif') |
|
691 |
" |
|
692 |
||
693 |
"Created: / 30.6.1997 / 21:55:51 / cg" |
|
694 |
"Modified: / 23.12.1999 / 22:30:55 / cg" |
|
695 |
! |
|
696 |
||
697 |
suffixForMimeTypeString:mimeTypeString |
|
698 |
"given a file suffix, return the mime-type" |
|
699 |
||
700 |
^ self suffixForMimeType:(MIMEType fromString:mimeTypeString) |
|
701 |
||
702 |
" |
|
703 |
self suffixForMimeTypeString:'image/gif' |
|
704 |
" |
|
705 |
||
706 |
"Created: / 30.6.1997 / 21:55:51 / cg" |
|
707 |
"Modified: / 23.12.1999 / 22:30:55 / cg" |
|
1612 | 708 |
! ! |
709 |
||
1729 | 710 |
!MIMETypes class methodsFor:'queries-image formats'! |
711 |
||
712 |
imageReaderClasses |
|
713 |
"return a collection of registered image reader classes" |
|
714 |
||
715 |
|setOfClasses| |
|
716 |
||
717 |
setOfClasses := IdentitySet new. |
|
718 |
FileSuffixToImageReaderClassMapping notNil ifTrue:[ |
|
719 |
FileSuffixToImageReaderClassMapping keysAndValuesDo:[:suff :cls | |
|
720 |
setOfClasses add:cls |
|
721 |
]. |
|
722 |
]. |
|
723 |
TypeToImageReaderClassMapping notNil ifTrue:[ |
|
724 |
TypeToImageReaderClassMapping keysAndValuesDo:[:suff :cls | |
|
725 |
setOfClasses add:cls |
|
726 |
]. |
|
727 |
]. |
|
728 |
^ setOfClasses |
|
729 |
||
730 |
"Created: / 30.6.1997 / 22:03:42 / cg" |
|
731 |
"Modified: / 1.8.1998 / 16:59:52 / cg" |
|
732 |
! |
|
733 |
||
734 |
imageReaderForSuffix:aSuffix |
|
735 |
"given a file suffix, return an approriate image reader class" |
|
736 |
||
737 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[^ nil]. |
|
738 |
^ FileSuffixToImageReaderClassMapping at:aSuffix asLowercase ifAbsent:nil |
|
739 |
||
740 |
"Created: / 30.6.1997 / 21:59:11 / cg" |
|
741 |
"Modified: / 1.8.1998 / 17:01:58 / cg" |
|
742 |
! |
|
743 |
||
744 |
imageReaderForSuffix:aSuffix put:aReaderClass |
|
745 |
"register an image reader for a file suffix" |
|
746 |
||
747 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[ |
|
748 |
FileSuffixToImageReaderClassMapping := Dictionary new. |
|
749 |
]. |
|
750 |
FileSuffixToImageReaderClassMapping at:aSuffix asLowercase put:aReaderClass |
|
751 |
||
752 |
"Created: / 30.6.1997 / 21:59:43 / cg" |
|
753 |
"Modified: / 1.8.1998 / 17:02:14 / cg" |
|
754 |
! |
|
755 |
||
756 |
imageReaderForType:mimeTypeString |
|
757 |
"given a mime-type, return an approriate image reader class" |
|
758 |
||
759 |
TypeToImageReaderClassMapping isNil ifTrue:[^ nil]. |
|
760 |
^ TypeToImageReaderClassMapping at:mimeTypeString asLowercase ifAbsent:nil |
|
761 |
||
762 |
"Created: / 30.6.1997 / 21:56:01 / cg" |
|
763 |
"Modified: / 1.8.1998 / 17:02:28 / cg" |
|
764 |
! |
|
765 |
||
766 |
imageReaderForType:mimeTypeString put:aReaderClass |
|
767 |
"register an image reader for a mime-type" |
|
768 |
||
769 |
TypeToImageReaderClassMapping isNil ifTrue:[ |
|
770 |
TypeToImageReaderClassMapping := Dictionary new. |
|
771 |
]. |
|
772 |
TypeToImageReaderClassMapping at:mimeTypeString asLowercase put:aReaderClass |
|
773 |
||
774 |
"Created: / 30.6.1997 / 21:56:11 / cg" |
|
775 |
"Modified: / 1.8.1998 / 17:02:40 / cg" |
|
776 |
! ! |
|
777 |
||
778 |
!MIMETypes class methodsFor:'queries-language syntax'! |
|
779 |
||
780 |
commentStringsForFilename:aFilename |
|
781 |
"return a useful comment definition; heuristics for now. |
|
782 |
The returned value is an array of 2 elements; |
|
783 |
the first is the end-of-line comment string (or nil); |
|
784 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
785 |
||
786 |
|mime| |
|
787 |
||
788 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
789 |
^ self commentStringsForMimeType:mime suffix:(aFilename asFilename suffix) |
|
790 |
||
791 |
" |
|
792 |
MIMETypes commentStringsForFilename:'Makefile'. |
|
793 |
MIMETypes commentStringsForFilename:'Object.st'. |
|
794 |
MIMETypes commentStringsForFilename:'Foo.java'. |
|
1925 | 795 |
MIMETypes commentStringsForFilename:'Foo.html'. |
1729 | 796 |
" |
797 |
! |
|
798 |
||
799 |
commentStringsForFilename:aFilename ifUnknown:alternativeBlockReturningCommentString |
|
800 |
"return a useful comment definition; heuristics for now. |
|
801 |
The returned value is an array of 2 elements; |
|
802 |
the first is the end-of-line comment string (or nil); |
|
803 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
804 |
||
805 |
|mime| |
|
806 |
||
807 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
808 |
^ self commentStringsForMimeType:mime suffix:(aFilename asFilename suffix) ifUnknown:alternativeBlockReturningCommentString |
|
809 |
||
810 |
" |
|
811 |
MIMETypes commentStringsForFilename:'Makefile'. |
|
812 |
MIMETypes commentStringsForFilename:'Object.st'. |
|
813 |
MIMETypes commentStringsForFilename:'Foo.java'. |
|
814 |
" |
|
815 |
! |
|
816 |
||
817 |
commentStringsForMimeType:mime suffix:suff |
|
818 |
"return a useful comment definition; heuristics for now. |
|
819 |
The returned value is an array of 2 elements; |
|
820 |
the first is the end-of-line comment string (or nil); |
|
821 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
822 |
||
823 |
^ self |
|
824 |
commentStringsForMimeType:mime suffix:suff |
|
825 |
ifUnknown: #(';' (nil nil)) |
|
826 |
||
827 |
" |
|
828 |
|mime| |
|
829 |
||
830 |
mime := MIMETypes mimeTypeForFilename:'Makefile'. |
|
831 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
832 |
" |
|
833 |
||
834 |
" |
|
835 |
|mime| |
|
836 |
||
837 |
mime := MIMETypes mimeTypeForFilename:'Object.st'. |
|
838 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
839 |
" |
|
840 |
! |
|
841 |
||
842 |
commentStringsForMimeType:mime suffix:suff ifUnknown:alternativeBlockReturningCommentString |
|
843 |
"return a useful comment definition; heuristics for now. |
|
844 |
The returned value is an array of 2 elements; |
|
845 |
the first is the end-of-line comment string (or nil); |
|
846 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
847 |
||
848 |
|commentSpec| |
|
849 |
||
850 |
commentSpec := TypeToCommentStringMapping at:mime ifAbsent:nil. |
|
851 |
commentSpec notNil ifTrue:[ |
|
852 |
^ commentSpec |
|
853 |
]. |
|
854 |
||
855 |
commentSpec := SuffixToCommentStringMapping at:suff ifAbsent:nil. |
|
856 |
commentSpec notNil ifTrue:[ |
|
857 |
^ commentSpec |
|
858 |
]. |
|
859 |
||
860 |
^ alternativeBlockReturningCommentString value |
|
861 |
||
862 |
" |
|
863 |
|mime| |
|
864 |
||
865 |
mime := MIMETypes mimeTypeForFilename:'Makefile'. |
|
866 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
867 |
" |
|
868 |
||
869 |
" |
|
870 |
|mime| |
|
871 |
||
872 |
mime := MIMETypes mimeTypeForFilename:'Object.st'. |
|
873 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
874 |
" |
|
875 |
! ! |
|
876 |
||
1612 | 877 |
!MIMETypes::MIMEType class methodsFor:'documentation'! |
878 |
||
879 |
documentation |
|
880 |
" |
|
1864 | 881 |
like a string, but knows that it represents a mimeType. |
1612 | 882 |
" |
883 |
! ! |
|
884 |
||
885 |
!MIMETypes::MIMEType class methodsFor:'initialization'! |
|
886 |
||
887 |
initialize |
|
888 |
CachedTypes := CacheDictionary new:30. |
|
889 |
||
890 |
" |
|
891 |
self initialize |
|
892 |
" |
|
893 |
! ! |
|
894 |
||
895 |
!MIMETypes::MIMEType class methodsFor:'instance creation'! |
|
896 |
||
897 |
fromString:aString |
|
898 |
|cachedType newType| |
|
899 |
||
900 |
aString class == self ifTrue:[^ aString]. |
|
901 |
||
902 |
cachedType := CachedTypes at:aString ifAbsent:nil. |
|
903 |
cachedType notNil ifTrue:[^ cachedType]. |
|
904 |
newType := aString copy changeClassTo:self. |
|
905 |
CachedTypes at:aString put:newType. |
|
906 |
^ newType |
|
907 |
||
908 |
" |
|
909 |
self fromString:'text/html' |
|
910 |
" |
|
911 |
! ! |
|
912 |
||
913 |
!MIMETypes::MIMEType methodsFor:'queries'! |
|
914 |
||
1693 | 915 |
isArchive |
1864 | 916 |
"return true, if I represent an archive type (such as zip or tar)" |
917 |
||
1612 | 918 |
|archivTypes| |
919 |
||
1729 | 920 |
archivTypes := MIMETypes applicationCompressorsAndArchiveTypeList. |
1612 | 921 |
archivTypes pairWiseDo:[: ext : type | |
922 |
self = type ifTrue:[ ^ true]. |
|
923 |
]. |
|
924 |
^ false |
|
925 |
! |
|
926 |
||
927 |
isHtml |
|
1864 | 928 |
"return true, if I represent the html text type" |
1612 | 929 |
|
930 |
^ (self = 'text/html') |
|
931 |
! |
|
932 |
||
933 |
isImage |
|
1864 | 934 |
"return true, if I represent an image type (such as gif or jpg)" |
1612 | 935 |
|
1693 | 936 |
^ (self startsWith:'image/') |
1612 | 937 |
! |
938 |
||
939 |
isPdf |
|
1864 | 940 |
"return true, if I represent the pdf type" |
941 |
||
1612 | 942 |
^ (self = 'application/pdf') |
943 |
! |
|
944 |
||
945 |
isSmalltalkSource |
|
1864 | 946 |
"return true, if I represent the smalltalk sourcecode type" |
947 |
||
1612 | 948 |
^ (self = 'application/x-smalltalk-source') |
1783 | 949 |
! |
950 |
||
951 |
isXml |
|
1864 | 952 |
"return true, if I represent the xml text type" |
953 |
||
1783 | 954 |
^ (self = 'text/xml') |
643 | 955 |
! ! |
956 |
||
957 |
!MIMETypes class methodsFor:'documentation'! |
|
958 |
||
959 |
version |
|
2020 | 960 |
^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.75 2004-10-18 13:48:30 penk Exp $' |
643 | 961 |
! ! |
1666 | 962 |
|
643 | 963 |
MIMETypes initialize! |
1666 | 964 |
MIMETypes::MIMEType initialize! |