author | penk |
Tue, 10 Sep 2002 15:50:49 +0200 | |
changeset 1604 | 0c678133dc4b |
parent 1593 | 4bf2544435a9 |
child 1606 | 158c10a36736 |
permissions | -rw-r--r-- |
643 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
3 |
All Rights Reserved |
|
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 |
18 |
instanceVariableNames:'' |
|
19 |
classVariableNames:'TypeToImageReaderClassMapping FileSuffixToTypeMapping |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
20 |
FilenameToTypeMapping FileSuffixToImageReaderClassMapping |
1300 | 21 |
CharSetToFontMapping LastSuffix LastType' |
643 | 22 |
poolDictionaries:'' |
23 |
category:'System-Documentation' |
|
24 |
! |
|
25 |
||
26 |
!MIMETypes class methodsFor:'documentation'! |
|
27 |
||
28 |
copyright |
|
29 |
" |
|
30 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
31 |
All Rights Reserved |
|
32 |
||
33 |
This software is furnished under a license and may be used |
|
34 |
only in accordance with the terms of that license and with the |
|
35 |
inclusion of the above copyright notice. This software may not |
|
36 |
be provided or otherwise made available to, or used by, any |
|
37 |
other person. No title to or ownership of the software is |
|
38 |
hereby transferred. |
|
39 |
||
40 |
||
41 |
" |
|
42 |
! |
|
43 |
||
44 |
documentation |
|
45 |
" |
|
46 |
just a place to keep MIME information |
|
47 |
(avoid spreading things at many places) |
|
48 |
||
1021 | 49 |
MIMETypes is abstract and functional. |
50 |
Actually, in some OperatingSystems, this information may |
|
51 |
be found in some config files (or registries). |
|
52 |
Therefore, this class may have to be extended to support this |
|
53 |
and fetch the information from there eventually. |
|
54 |
||
643 | 55 |
[author:] |
56 |
Claus Gittinger |
|
57 |
" |
|
1311 | 58 |
! |
59 |
||
60 |
knownTypes |
|
61 |
" |
|
62 |
simply a reminder for me ... |
|
63 |
||
64 |
application mime file extentsions |
|
65 |
||
66 |
powerpoint application/ms-powerpoint .pot, .ppz, .ppt, .pps, |
|
67 |
application/mspowerpoint |
|
68 |
application/vnd.ms-powerpoint |
|
69 |
application/x-mspowerpoint |
|
70 |
||
1312 | 71 |
shockwave application/x-shockwave-flash .swf |
1311 | 72 |
|
1312 | 73 |
futuresplash application/futuresplash .spl |
1311 | 74 |
" |
643 | 75 |
! ! |
76 |
||
77 |
!MIMETypes class methodsFor:'initialization'! |
|
78 |
||
1604 | 79 |
applicationComprAndArchiveTypeList |
80 |
"/ compressors and archivers |
|
81 |
||
82 |
^ #( |
|
83 |
||
84 |
'tar' 'application/x-tar' |
|
85 |
'gtar' 'application/x-gtar' |
|
86 |
'tgz' 'application/x-tar-compressed' |
|
87 |
'zip' 'application/x-zip-compressed' |
|
88 |
('gz' 'z') 'application/x-gzip-compressed' |
|
89 |
'cpio' 'application/x-cpio' |
|
90 |
'shar' 'application/x-shar' |
|
91 |
'jar' 'application/java-archive' |
|
92 |
) |
|
93 |
! |
|
645 | 94 |
|
1604 | 95 |
applicationProgLangTypeList |
96 |
"/ applications for programm languages |
|
713 | 97 |
|
1604 | 98 |
^ #( |
99 |
('st' 'cls') 'application/x-smalltalk-source' |
|
100 |
'sif' 'application/x-smalltalk-source-sif' |
|
101 |
'c' 'application/x-c-source' |
|
102 |
('cc' 'cpp') 'application/x-cpp-source' |
|
103 |
('js' 'mocha') 'application/x-javascript' |
|
104 |
('java' 'jav') 'application/x-java-source' |
|
105 |
'sh' 'application/x-sh' |
|
106 |
'csh' 'application/x-csh' |
|
107 |
'tcl' 'application/x-tcl' |
|
108 |
'pl' 'application/x-perl' |
|
109 |
'mak' 'application/x-make' |
|
110 |
'bat' 'application/x-batch-script' |
|
111 |
('asn1' 'x409' 'gdmo' 'gdm') 'application/x-asn1-source' |
|
112 |
) |
|
113 |
! |
|
1561 | 114 |
|
1604 | 115 |
applicationTextTypeList |
116 |
"/ text applications |
|
117 |
||
118 |
^ #( |
|
119 |
('ps' 'eps') 'application/postscript' |
|
120 |
'pdf' 'application/pdf' |
|
121 |
'rtf' 'application/rtf' |
|
122 |
'doc' 'application/winword' |
|
123 |
) |
|
124 |
! |
|
125 |
||
126 |
applicationTypeList |
|
127 |
"/ applications |
|
128 |
||
129 |
|types| |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
130 |
|
1604 | 131 |
types := Array new. |
132 |
types addAll:self applicationProgLangTypeList. |
|
133 |
types addAll:self applicationTextTypeList. |
|
134 |
types addAll:self applicationComprAndArchiveTypeList. |
|
135 |
^ types |
|
136 |
! |
|
137 |
||
138 |
audioTypeList |
|
139 |
"/ audio formats ... |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
140 |
|
1604 | 141 |
^ #( |
142 |
('ra' 'ram') 'audio/x-pn-realaudio' |
|
143 |
('mpa' 'mpega') 'audio/x-mpeg' |
|
144 |
('mp3' ) 'audio/x-mp3' |
|
145 |
'wav' 'audio/x-wav' |
|
146 |
('aif' 'aiff' 'aifc') 'audio/x-aiff' |
|
147 |
('au' 'snd') 'audio/basic' |
|
148 |
('swf') 'audio/x-shockwave-flash' |
|
149 |
) |
|
150 |
! |
|
151 |
||
152 |
imageTypeList |
|
153 |
||
154 |
^ #( |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
155 |
"/ image formats ... |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
156 |
|
1216 | 157 |
('jpg' 'jpeg') 'image/jpeg' |
1188 | 158 |
'gif' 'image/gif' |
159 |
('tif' 'tiff') 'image/tiff' |
|
160 |
'xbm' 'image/x-xbitmap' |
|
161 |
'xpm' 'image/x-xpixmap' |
|
162 |
'png' 'image/x-png' |
|
163 |
'pcd' 'image/x-photo-cd' |
|
164 |
'bmp' 'image/x-MS-bmp' |
|
165 |
'rgb' 'image/x-rgb' |
|
166 |
'ppm' 'image/x-portable-pixmap' |
|
167 |
'pgm' 'image/x-portable-graymap' |
|
168 |
'pbm' 'image/x-portable-bitmap' |
|
169 |
'pnm' 'image/x-portable-anymap' |
|
170 |
'xwd' 'image/x-xwindowdump' |
|
171 |
'ras' 'image/x-cmu-raster' |
|
1216 | 172 |
'tga' 'image/x-targa' |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
173 |
|
1604 | 174 |
) |
175 |
! |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
176 |
|
1604 | 177 |
initialize |
178 |
"initialize wellKnown facts" |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
179 |
|
1604 | 180 |
|typeToImageReaderClassMapping fileSuffixToTypeMapping |
181 |
fileSuffixToImageReaderClassMapping charSetToFontMapping types| |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
182 |
|
1604 | 183 |
LastSuffix := LastType := nil. |
1411 | 184 |
|
1604 | 185 |
(fileSuffixToImageReaderClassMapping := FileSuffixToImageReaderClassMapping) isNil ifTrue:[ |
186 |
FileSuffixToImageReaderClassMapping := fileSuffixToImageReaderClassMapping := Dictionary new |
|
187 |
]. |
|
188 |
(typeToImageReaderClassMapping := TypeToImageReaderClassMapping) isNil ifTrue:[ |
|
189 |
TypeToImageReaderClassMapping := typeToImageReaderClassMapping := Dictionary new |
|
190 |
]. |
|
191 |
(fileSuffixToTypeMapping := FileSuffixToTypeMapping) isNil ifTrue:[ |
|
192 |
FileSuffixToTypeMapping := fileSuffixToTypeMapping := Dictionary new |
|
193 |
]. |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
194 |
|
1604 | 195 |
"/ setup file-suffix to mimeType mapping ... |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
196 |
|
1604 | 197 |
types := Array new. |
198 |
types addAll:self textTypeList. |
|
199 |
types addAll:self imageTypeList. |
|
200 |
types addAll:self videoTypeList. |
|
201 |
types addAll:self audioTypeList. |
|
202 |
types addAll:self applicationTypeList. |
|
203 |
types pairWiseDo:[:suff :type| |
|
1188 | 204 |
suff isArray ifTrue:[ |
205 |
suff do:[:s | fileSuffixToTypeMapping at:s put:type] |
|
206 |
] ifFalse:[ |
|
207 |
fileSuffixToTypeMapping at:suff put:type |
|
208 |
] |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
209 |
]. |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
210 |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
211 |
FilenameToTypeMapping := Dictionary new. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
212 |
#( |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
213 |
('makefile' 'make.proto') 'application/x-make' |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
214 |
) pairWiseDo:[:nm :type| |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
215 |
nm isArray ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
216 |
nm do:[:s | FilenameToTypeMapping at:s put:type] |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
217 |
] ifFalse:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
218 |
FilenameToTypeMapping at:nm put:type |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
219 |
] |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
220 |
]. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
221 |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
222 |
"/ setup mimeType to image reader class mapping ... |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
223 |
|
1022 | 224 |
typeToImageReaderClassMapping at:'image/jpeg' put:JPEGReader. |
225 |
typeToImageReaderClassMapping at:'image/gif' put:GIFReader. |
|
226 |
typeToImageReaderClassMapping at:'image/tiff' put:TIFFReader. |
|
645 | 227 |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
228 |
"/ setup suffix to image reader class mapping ... |
645 | 229 |
|
1022 | 230 |
fileSuffixToImageReaderClassMapping at:'jpg' put:JPEGReader. |
231 |
fileSuffixToImageReaderClassMapping at:'gif' put:GIFReader. |
|
232 |
fileSuffixToImageReaderClassMapping at:'tif' put:TIFFReader. |
|
233 |
||
234 |
||
235 |
"/ character sets (not really mime stuff, but also placed here) |
|
645 | 236 |
|
1022 | 237 |
(charSetToFontMapping := CharSetToFontMapping) isNil ifTrue:[ |
238 |
CharSetToFontMapping := charSetToFontMapping := Dictionary new |
|
239 |
]. |
|
645 | 240 |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
241 |
#( |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
242 |
'iso2022-jp' 'jis*0208*' |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
243 |
'x-iso2022-jp' 'jis*0208*' |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
244 |
'x-euc-jp' 'jis*0208*' |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
245 |
'x-shift-jis' 'jis*0208*' |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
246 |
'x-sjis' 'jis*0208*' |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
247 |
'x-jis7' 'jis*0208*' |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
248 |
'jis7' 'jis*0208*' |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
249 |
'euc' 'jis*0208*' |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
250 |
'euc-jp' 'jis*0208*' |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
251 |
'sjis' 'jis*0208*' |
713 | 252 |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
253 |
'big5' 'big5*' |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
254 |
|
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
255 |
'gb2312' 'gb*' |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
256 |
'hz-gb-2312' 'gb*' |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
257 |
'x-gbk' 'gb*' |
1022 | 258 |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
259 |
'iso2022-kr' 'ksc*' |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
260 |
'x-euc-kr' 'ksc*' |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
261 |
) pairWiseDo:[:charSet :fontEncoding| |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
262 |
charSetToFontMapping at:charSet put:fontEncoding |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
263 |
]. |
643 | 264 |
|
265 |
" |
|
266 |
self initialize |
|
267 |
" |
|
268 |
||
1269 | 269 |
"Modified: / 19.11.1999 / 15:01:53 / cg" |
1604 | 270 |
! |
271 |
||
272 |
textTypeList |
|
273 |
"/ misc text ... |
|
274 |
||
275 |
^ #( |
|
276 |
('htm' 'html') 'text/html' |
|
277 |
('shtml') 'text/html' |
|
278 |
('txt' 'text') 'text/plain' |
|
279 |
) |
|
280 |
! |
|
281 |
||
282 |
videoTypeList |
|
283 |
"/ video formats ... |
|
284 |
||
285 |
^ #( |
|
286 |
'movie' 'video/x-sgi-movie' |
|
287 |
'avi' 'video/x-msvideo' |
|
288 |
('qt' 'mov' 'moov') 'video/quicktime' |
|
289 |
('mpv2' 'mp2v' 'mp2' 'mpeg2') 'video/x-mpeg2' |
|
290 |
('mpv' 'mpegv' 'mpg' 'mpeg' 'mpe') 'video/mpeg' |
|
291 |
) |
|
643 | 292 |
! ! |
293 |
||
294 |
!MIMETypes class methodsFor:'accessing'! |
|
295 |
||
1472 | 296 |
commentStringsForFilename:aFilename |
297 |
"return a useful comment definition; heuristics for now. |
|
298 |
The returned value is an array of 2 elements; |
|
299 |
the first is the end-of-line comment string (or nil); |
|
300 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
301 |
||
302 |
|mime| |
|
303 |
||
304 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
305 |
^ self commentStringsForMimeType:mime suffix:(aFilename asFilename suffix) |
|
306 |
||
307 |
" |
|
308 |
MIMETypes commentStringsForFilename:'Makefile'. |
|
309 |
MIMETypes commentStringsForFilename:'Object.st'. |
|
310 |
MIMETypes commentStringsForFilename:'Foo.java'. |
|
311 |
" |
|
312 |
! |
|
313 |
||
1489 | 314 |
commentStringsForFilename:aFilename ifUnknown:alternativeBlockReturningCommentString |
315 |
"return a useful comment definition; heuristics for now. |
|
316 |
The returned value is an array of 2 elements; |
|
317 |
the first is the end-of-line comment string (or nil); |
|
318 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
319 |
||
320 |
|mime| |
|
321 |
||
322 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
323 |
^ self commentStringsForMimeType:mime suffix:(aFilename asFilename suffix) ifUnknown:alternativeBlockReturningCommentString |
|
324 |
||
325 |
" |
|
326 |
MIMETypes commentStringsForFilename:'Makefile'. |
|
327 |
MIMETypes commentStringsForFilename:'Object.st'. |
|
328 |
MIMETypes commentStringsForFilename:'Foo.java'. |
|
329 |
" |
|
330 |
! |
|
331 |
||
1472 | 332 |
commentStringsForMimeType:mime suffix:suff |
333 |
"return a useful comment definition; heuristics for now. |
|
334 |
The returned value is an array of 2 elements; |
|
335 |
the first is the end-of-line comment string (or nil); |
|
336 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
337 |
||
1489 | 338 |
^ self |
339 |
commentStringsForMimeType:mime suffix:suff |
|
340 |
ifUnknown: #(';' (nil nil)) |
|
341 |
||
342 |
" |
|
343 |
|mime| |
|
344 |
||
345 |
mime := MIMETypes mimeTypeForFilename:'Makefile'. |
|
346 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
347 |
" |
|
348 |
||
349 |
" |
|
350 |
|mime| |
|
351 |
||
352 |
mime := MIMETypes mimeTypeForFilename:'Object.st'. |
|
353 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
354 |
" |
|
355 |
! |
|
356 |
||
357 |
commentStringsForMimeType:mime suffix:suff ifUnknown:alternativeBlockReturningCommentString |
|
358 |
"return a useful comment definition; heuristics for now. |
|
359 |
The returned value is an array of 2 elements; |
|
360 |
the first is the end-of-line comment string (or nil); |
|
361 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
362 |
||
1472 | 363 |
(mime = 'application/x-make') ifTrue:[ |
364 |
"/ makefile |
|
365 |
^ #('#' (nil nil)). |
|
366 |
]. |
|
367 |
(mime = 'application/x-sh') ifTrue:[ |
|
368 |
"/ shell script |
|
369 |
^ #('#' (nil nil)). |
|
370 |
]. |
|
371 |
((mime = 'text/html') |
|
372 |
or:[(mime = 'text/xml') |
|
373 |
or:[(mime = 'application/xml')]]) ifTrue:[ |
|
374 |
^ #(nil ('<!!-- ' ' -->')). |
|
375 |
]. |
|
376 |
(mime = 'application/x-batch-script') ifTrue:[ |
|
377 |
^ #('rem ' (nil nil)). |
|
378 |
]. |
|
379 |
(mime = 'application/x-smalltalk-source') ifTrue:[ |
|
380 |
^ #('"/' ('"' '"')). |
|
381 |
]. |
|
382 |
(mime = 'application/x-pascal-source') ifTrue:[ |
|
383 |
^ #(nil ('{' '}')). |
|
384 |
]. |
|
385 |
(mime = 'application/x-c-source') ifTrue:[ |
|
386 |
^ #(nil ('/*' '*/')). |
|
387 |
]. |
|
388 |
(mime = 'application/x-cpp-source') ifTrue:[ |
|
389 |
^ #('//' ('/*' '*/')). |
|
390 |
]. |
|
391 |
(mime = 'application/x-java-source') ifTrue:[ |
|
392 |
^ #('//' ('/*' '*/')). |
|
393 |
]. |
|
394 |
(mime = 'application/x-asn1-source') ifTrue:[ |
|
395 |
^ #('--' ('--' '--')). |
|
396 |
]. |
|
397 |
||
398 |
"/ st/x support files |
|
399 |
(suff = 'style') ifTrue:[ |
|
400 |
^ #(';' (nil nil)). |
|
401 |
]. |
|
402 |
(suff = 'rs') ifTrue:[ |
|
403 |
^ #(';' (nil nil)). |
|
404 |
]. |
|
405 |
||
1489 | 406 |
^ alternativeBlockReturningCommentString value |
1472 | 407 |
|
408 |
" |
|
409 |
|mime| |
|
410 |
||
411 |
mime := MIMETypes mimeTypeForFilename:'Makefile'. |
|
412 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
413 |
" |
|
414 |
||
415 |
" |
|
416 |
|mime| |
|
417 |
||
418 |
mime := MIMETypes mimeTypeForFilename:'Object.st'. |
|
419 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
|
420 |
" |
|
421 |
! |
|
422 |
||
647 | 423 |
defineImageType:mimeType suffix:aSuffix reader:aReaderClass |
424 |
"register an image reader." |
|
425 |
||
426 |
aSuffix notNil ifTrue:[ |
|
427 |
self imageReaderForSuffix:aSuffix put:aReaderClass. |
|
428 |
]. |
|
429 |
||
430 |
mimeType notNil ifTrue:[ |
|
431 |
self imageReaderForType:mimeType put:aReaderClass |
|
432 |
]. |
|
433 |
||
434 |
(aSuffix notNil and:[mimeType notNil]) ifTrue:[ |
|
435 |
self mimeTypeForSuffix:aSuffix put:mimeType |
|
436 |
]. |
|
437 |
! |
|
438 |
||
643 | 439 |
fileSuffixToImageReaderMapping |
1021 | 440 |
"return the suffix-to-imageReader mapping" |
441 |
||
643 | 442 |
^ FileSuffixToImageReaderClassMapping ? #() |
443 |
||
1021 | 444 |
"Modified: / 1.8.1998 / 17:00:11 / cg" |
643 | 445 |
! |
446 |
||
648 | 447 |
fontForCharset:aCharSet |
1021 | 448 |
"return the font-encoding for an iso-charset" |
449 |
||
648 | 450 |
^ CharSetToFontMapping at:aCharSet ifAbsent:nil |
451 |
||
452 |
" |
|
1021 | 453 |
MIMETypes fontForCharset:'iso2022-jp' |
648 | 454 |
MIMETypes fontForCharset:'euc-jp' |
455 |
" |
|
456 |
||
1021 | 457 |
"Modified: / 1.8.1998 / 17:00:57 / cg" |
648 | 458 |
! |
459 |
||
643 | 460 |
imageFileSuffixes |
1021 | 461 |
"return a collection with known file suffixes" |
462 |
||
643 | 463 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[^ #()]. |
464 |
^ FileSuffixToImageReaderClassMapping keys |
|
465 |
||
1021 | 466 |
"Created: / 30.6.1997 / 22:04:48 / cg" |
467 |
"Modified: / 1.8.1998 / 17:01:26 / cg" |
|
643 | 468 |
! |
469 |
||
470 |
imageReaderClasses |
|
1021 | 471 |
"return a collection of registered image reader classes" |
472 |
||
645 | 473 |
|setOfClasses| |
474 |
||
475 |
setOfClasses := IdentitySet new. |
|
476 |
FileSuffixToImageReaderClassMapping notNil ifTrue:[ |
|
477 |
FileSuffixToImageReaderClassMapping keysAndValuesDo:[:suff :cls | |
|
1021 | 478 |
setOfClasses add:cls |
479 |
]. |
|
645 | 480 |
]. |
481 |
TypeToImageReaderClassMapping notNil ifTrue:[ |
|
482 |
TypeToImageReaderClassMapping keysAndValuesDo:[:suff :cls | |
|
1021 | 483 |
setOfClasses add:cls |
484 |
]. |
|
645 | 485 |
]. |
486 |
^ setOfClasses |
|
643 | 487 |
|
1021 | 488 |
"Created: / 30.6.1997 / 22:03:42 / cg" |
489 |
"Modified: / 1.8.1998 / 16:59:52 / cg" |
|
643 | 490 |
! |
491 |
||
492 |
imageReaderForSuffix:aSuffix |
|
1021 | 493 |
"given a file suffix, return an approriate image reader class" |
494 |
||
643 | 495 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[^ nil]. |
496 |
^ FileSuffixToImageReaderClassMapping at:aSuffix asLowercase ifAbsent:nil |
|
497 |
||
1021 | 498 |
"Created: / 30.6.1997 / 21:59:11 / cg" |
499 |
"Modified: / 1.8.1998 / 17:01:58 / cg" |
|
643 | 500 |
! |
501 |
||
502 |
imageReaderForSuffix:aSuffix put:aReaderClass |
|
1021 | 503 |
"register an image reader for a file suffix" |
504 |
||
643 | 505 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[ |
506 |
FileSuffixToImageReaderClassMapping := Dictionary new. |
|
507 |
]. |
|
508 |
FileSuffixToImageReaderClassMapping at:aSuffix asLowercase put:aReaderClass |
|
509 |
||
1021 | 510 |
"Created: / 30.6.1997 / 21:59:43 / cg" |
511 |
"Modified: / 1.8.1998 / 17:02:14 / cg" |
|
643 | 512 |
! |
513 |
||
514 |
imageReaderForType:mimeTypeString |
|
1021 | 515 |
"given a mime-type, return an approriate image reader class" |
516 |
||
643 | 517 |
TypeToImageReaderClassMapping isNil ifTrue:[^ nil]. |
518 |
^ TypeToImageReaderClassMapping at:mimeTypeString asLowercase ifAbsent:nil |
|
519 |
||
1021 | 520 |
"Created: / 30.6.1997 / 21:56:01 / cg" |
521 |
"Modified: / 1.8.1998 / 17:02:28 / cg" |
|
643 | 522 |
! |
523 |
||
524 |
imageReaderForType:mimeTypeString put:aReaderClass |
|
1021 | 525 |
"register an image reader for a mime-type" |
526 |
||
643 | 527 |
TypeToImageReaderClassMapping isNil ifTrue:[ |
528 |
TypeToImageReaderClassMapping := Dictionary new. |
|
529 |
]. |
|
530 |
TypeToImageReaderClassMapping at:mimeTypeString asLowercase put:aReaderClass |
|
531 |
||
1021 | 532 |
"Created: / 30.6.1997 / 21:56:11 / cg" |
533 |
"Modified: / 1.8.1998 / 17:02:40 / cg" |
|
643 | 534 |
! |
535 |
||
1473 | 536 |
mimeTypeForFilename:filenameArg |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
537 |
"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
|
538 |
|
1473 | 539 |
|type filename lcFilename suff| |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
540 |
|
1473 | 541 |
filename := filenameArg asFilename. |
1474 | 542 |
|
543 |
lcFilename := filename baseName asLowercase. |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
544 |
type := FilenameToTypeMapping at:lcFilename ifAbsent:nil. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
545 |
type isNil ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
546 |
"/ allow for fallback ... |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
547 |
type := OperatingSystem mimeTypeForFilename:lcFilename. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
548 |
"/ 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
|
549 |
"/ 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
|
550 |
"/ the OS. |
1275 | 551 |
"/ type isNil ifTrue:[ |
552 |
"/ FilenameToTypeMapping at:lcFilename put:#unknown |
|
553 |
"/ ]. |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
554 |
]. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
555 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
556 |
type == #unknown ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
557 |
type := nil. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
558 |
]. |
1273
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
559 |
|
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
560 |
type isNil ifTrue:[ |
1473 | 561 |
suff := filename suffix. |
1273
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
562 |
suff size ~~ 0 ifTrue:[ |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
563 |
^ self mimeTypeForSuffix:suff |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
564 |
] |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
565 |
]. |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
566 |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
567 |
^ type |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
568 |
! |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
569 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
570 |
mimeTypeForFilename:filename put:mimeType |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
571 |
"register a mime type for a filename" |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
572 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
573 |
FilenameToTypeMapping isNil ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
574 |
FilenameToTypeMapping := Dictionary new |
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 |
FilenameToTypeMapping at:filename put:mimeType asLowercase |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
577 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
578 |
! |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
579 |
|
643 | 580 |
mimeTypeForSuffix:suffix |
1021 | 581 |
"given a file suffix, return the mime-type" |
582 |
||
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
583 |
|type lcSuffix| |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
584 |
|
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
585 |
lcSuffix := suffix asLowercase. |
1300 | 586 |
lcSuffix = LastSuffix ifTrue:[ |
587 |
type := LastType |
|
588 |
] ifFalse:[ |
|
589 |
type := FileSuffixToTypeMapping at:lcSuffix ifAbsent:nil. |
|
590 |
type isNil ifTrue:[ |
|
591 |
"/ allow for fallback ... |
|
592 |
type := OperatingSystem mimeTypeForSuffix:lcSuffix. |
|
593 |
"/ the special value #unknown is returned as nil; |
|
594 |
"/ this avoids constant retry if a mimeType is not known in |
|
595 |
"/ the OS. |
|
596 |
"/ type isNil ifTrue:[ |
|
597 |
"/ FileSuffixToTypeMapping at:lcSuffix put:#unknown |
|
598 |
"/ ]. |
|
599 |
]. |
|
600 |
LastSuffix := lcSuffix. |
|
601 |
LastType := type. |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
602 |
]. |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
603 |
type == #unknown ifTrue:[ |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
604 |
type := nil |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
605 |
]. |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
606 |
^ type |
643 | 607 |
|
1021 | 608 |
"Created: / 30.6.1997 / 21:55:51 / cg" |
1300 | 609 |
"Modified: / 23.12.1999 / 22:30:55 / cg" |
643 | 610 |
! |
611 |
||
612 |
mimeTypeForSuffix:suffix put:mimeType |
|
1021 | 613 |
"register a mime type for a file suffix" |
614 |
||
643 | 615 |
FileSuffixToTypeMapping isNil ifTrue:[ |
616 |
FileSuffixToTypeMapping := Dictionary new |
|
617 |
]. |
|
618 |
FileSuffixToTypeMapping at:suffix put:mimeType asLowercase |
|
619 |
||
1021 | 620 |
"Created: / 30.6.1997 / 21:56:20 / cg" |
621 |
"Modified: / 1.8.1998 / 17:03:18 / cg" |
|
1593 | 622 |
! |
623 |
||
624 |
mimeTypeForSuffixMapping |
|
625 |
||
626 |
^ FileSuffixToTypeMapping |
|
643 | 627 |
! ! |
628 |
||
629 |
!MIMETypes class methodsFor:'documentation'! |
|
630 |
||
631 |
version |
|
1604 | 632 |
^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.37 2002-09-10 13:50:49 penk Exp $' |
643 | 633 |
! ! |
634 |
MIMETypes initialize! |