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