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