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