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