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