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