643
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1997 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
|
|
12 |
|
|
13 |
"
|
|
14 |
|
|
15 |
Object subclass:#MIMETypes
|
|
16 |
instanceVariableNames:''
|
|
17 |
classVariableNames:'TypeToImageReaderClassMapping FileSuffixToTypeMapping
|
648
|
18 |
FileSuffixToImageReaderClassMapping CharSetToFontMapping'
|
643
|
19 |
poolDictionaries:''
|
|
20 |
category:'System-Documentation'
|
|
21 |
!
|
|
22 |
|
|
23 |
!MIMETypes class methodsFor:'documentation'!
|
|
24 |
|
|
25 |
copyright
|
|
26 |
"
|
|
27 |
COPYRIGHT (c) 1997 by eXept Software AG
|
|
28 |
All Rights Reserved
|
|
29 |
|
|
30 |
This software is furnished under a license and may be used
|
|
31 |
only in accordance with the terms of that license and with the
|
|
32 |
inclusion of the above copyright notice. This software may not
|
|
33 |
be provided or otherwise made available to, or used by, any
|
|
34 |
other person. No title to or ownership of the software is
|
|
35 |
hereby transferred.
|
|
36 |
|
|
37 |
|
|
38 |
"
|
|
39 |
!
|
|
40 |
|
|
41 |
documentation
|
|
42 |
"
|
|
43 |
just a place to keep MIME information
|
|
44 |
(avoid spreading things at many places)
|
|
45 |
|
1021
|
46 |
MIMETypes is abstract and functional.
|
|
47 |
Actually, in some OperatingSystems, this information may
|
|
48 |
be found in some config files (or registries).
|
|
49 |
Therefore, this class may have to be extended to support this
|
|
50 |
and fetch the information from there eventually.
|
|
51 |
|
643
|
52 |
[author:]
|
|
53 |
Claus Gittinger
|
|
54 |
"
|
|
55 |
! !
|
|
56 |
|
|
57 |
!MIMETypes class methodsFor:'initialization'!
|
|
58 |
|
|
59 |
initialize
|
645
|
60 |
"initialize wellKnown facts"
|
|
61 |
|
1022
|
62 |
|typeToImageReaderClassMapping fileSuffixToTypeMapping
|
|
63 |
fileSuffixToImageReaderClassMapping charSetToFontMapping|
|
713
|
64 |
|
1022
|
65 |
"/ image formats.
|
645
|
66 |
|
1022
|
67 |
(typeToImageReaderClassMapping := TypeToImageReaderClassMapping) isNil ifTrue:[
|
|
68 |
TypeToImageReaderClassMapping := typeToImageReaderClassMapping := Dictionary new
|
713
|
69 |
].
|
1022
|
70 |
typeToImageReaderClassMapping at:'image/jpeg' put:JPEGReader.
|
|
71 |
typeToImageReaderClassMapping at:'image/gif' put:GIFReader.
|
|
72 |
typeToImageReaderClassMapping at:'image/tiff' put:TIFFReader.
|
645
|
73 |
|
1022
|
74 |
(fileSuffixToTypeMapping := FileSuffixToTypeMapping) isNil ifTrue:[
|
|
75 |
FileSuffixToTypeMapping := fileSuffixToTypeMapping := Dictionary new
|
713
|
76 |
].
|
1022
|
77 |
fileSuffixToTypeMapping at:'jpg' put:'image/jpeg'.
|
|
78 |
fileSuffixToTypeMapping at:'gif' put:'image/gif'.
|
|
79 |
fileSuffixToTypeMapping at:'tif' put:'image/tiff'.
|
|
80 |
fileSuffixToTypeMapping at:'xbm' put:'image/x-xbitmap'.
|
|
81 |
fileSuffixToTypeMapping at:'xpm' put:'image/x-xpixmap'.
|
|
82 |
fileSuffixToTypeMapping at:'png' put:'image/x-png'.
|
|
83 |
fileSuffixToTypeMapping at:'pcd' put:'image/x-photo-cd'.
|
|
84 |
fileSuffixToTypeMapping at:'bmp' put:'image/x-MS-bmp'.
|
|
85 |
fileSuffixToTypeMapping at:'rgb' put:'image/x-rgb'.
|
|
86 |
fileSuffixToTypeMapping at:'ppm' put:'image/x-portable-pixmap'.
|
|
87 |
fileSuffixToTypeMapping at:'pgm' put:'image/x-portable-graymap'.
|
|
88 |
fileSuffixToTypeMapping at:'pbm' put:'image/x-portable-bitmap'.
|
|
89 |
fileSuffixToTypeMapping at:'pnm' put:'image/x-portable-anymap'.
|
|
90 |
fileSuffixToTypeMapping at:'xwd' put:'image/x-xwindowdump'.
|
|
91 |
fileSuffixToTypeMapping at:'ras' put:'image/x-cmu-raster'.
|
|
92 |
|
|
93 |
fileSuffixToTypeMapping at:'htm' put:'text/html'.
|
|
94 |
fileSuffixToTypeMapping at:'html' put:'text/html'.
|
|
95 |
fileSuffixToTypeMapping at:'ps' put:'application/postscript'.
|
|
96 |
fileSuffixToTypeMapping at:'pdf' put:'application/pdf'.
|
|
97 |
fileSuffixToTypeMapping at:'rtf' put:'application/rtf'.
|
645
|
98 |
|
1022
|
99 |
fileSuffixToTypeMapping at:'htm' put:'text/html'.
|
|
100 |
fileSuffixToTypeMapping at:'html' put:'text/html'.
|
|
101 |
fileSuffixToTypeMapping at:'txt' put:'text/plain'.
|
|
102 |
fileSuffixToTypeMapping at:'text' put:'text/plain'.
|
|
103 |
|
|
104 |
fileSuffixToTypeMapping at:'movie' put:'video/x-sgi-movie'.
|
|
105 |
fileSuffixToTypeMapping at:'avi' put:'video/x-msvideo'.
|
|
106 |
fileSuffixToTypeMapping at:'qt' put:'video/quicktime'.
|
|
107 |
fileSuffixToTypeMapping at:'mov' put:'video/quicktime'.
|
|
108 |
fileSuffixToTypeMapping at:'moov' put:'video/quicktime'.
|
|
109 |
fileSuffixToTypeMapping at:'mpv2' put:'video/x-mpeg2'.
|
|
110 |
fileSuffixToTypeMapping at:'mpv' put:'video/mpeg'.
|
|
111 |
fileSuffixToTypeMapping at:'mpegv' put:'video/mpeg'.
|
|
112 |
fileSuffixToTypeMapping at:'mpg' put:'video/mpeg'.
|
|
113 |
fileSuffixToTypeMapping at:'mpeg' put:'video/mpeg'.
|
|
114 |
|
|
115 |
fileSuffixToTypeMapping at:'ra' put:'audio/x-pn-realaudio'.
|
|
116 |
fileSuffixToTypeMapping at:'mpa' put:'audio/x-mpeg'.
|
|
117 |
fileSuffixToTypeMapping at:'mpega' put:'audio/x-mpeg'.
|
|
118 |
fileSuffixToTypeMapping at:'wav' put:'audio/x-wav'.
|
|
119 |
fileSuffixToTypeMapping at:'aif' put:'audio/x-aiff'.
|
|
120 |
fileSuffixToTypeMapping at:'aiff' put:'audio/x-aiff'.
|
|
121 |
fileSuffixToTypeMapping at:'aifc' put:'audio/x-aiff'.
|
|
122 |
fileSuffixToTypeMapping at:'au' put:'audio/basic'.
|
|
123 |
fileSuffixToTypeMapping at:'snd' put:'audio/basic'.
|
|
124 |
|
|
125 |
(fileSuffixToImageReaderClassMapping := FileSuffixToImageReaderClassMapping) isNil ifTrue:[
|
|
126 |
FileSuffixToImageReaderClassMapping := fileSuffixToImageReaderClassMapping := Dictionary new
|
713
|
127 |
].
|
1022
|
128 |
fileSuffixToImageReaderClassMapping at:'jpg' put:JPEGReader.
|
|
129 |
fileSuffixToImageReaderClassMapping at:'gif' put:GIFReader.
|
|
130 |
fileSuffixToImageReaderClassMapping at:'tif' put:TIFFReader.
|
|
131 |
|
|
132 |
"/ misc stuff
|
|
133 |
|
|
134 |
fileSuffixToTypeMapping at:'st' put:'application/x-smalltalk-source'.
|
|
135 |
fileSuffixToTypeMapping at:'tar' put:'application/x-tar'.
|
|
136 |
fileSuffixToTypeMapping at:'zip' put:'application/x-zip-compressed'.
|
|
137 |
|
|
138 |
"/ character sets (not really mime stuff, but also placed here)
|
645
|
139 |
|
1022
|
140 |
(charSetToFontMapping := CharSetToFontMapping) isNil ifTrue:[
|
|
141 |
CharSetToFontMapping := charSetToFontMapping := Dictionary new
|
|
142 |
].
|
|
143 |
charSetToFontMapping at:'iso2022-jp' put:'jis*0208*'.
|
|
144 |
charSetToFontMapping at:'x-iso2022-jp' put:'jis*0208*'.
|
|
145 |
charSetToFontMapping at:'x-euc-jp' put:'jis*0208*'.
|
|
146 |
charSetToFontMapping at:'x-shift-jis' put:'jis*0208*'.
|
|
147 |
charSetToFontMapping at:'x-sjis' put:'jis*0208*'.
|
|
148 |
charSetToFontMapping at:'x-jis7' put:'jis*0208*'.
|
|
149 |
charSetToFontMapping at:'jis7' put:'jis*0208*'.
|
|
150 |
charSetToFontMapping at:'euc' put:'jis*0208*'.
|
|
151 |
charSetToFontMapping at:'euc-jp' put:'jis*0208*'.
|
|
152 |
charSetToFontMapping at:'sjis' put:'jis*0208*'.
|
645
|
153 |
|
1022
|
154 |
charSetToFontMapping at:'big5' put:'big5*'.
|
713
|
155 |
|
1022
|
156 |
charSetToFontMapping at:'gb2312' put:'gb*'.
|
|
157 |
charSetToFontMapping at:'hz-gb-2312' put:'gb*'.
|
|
158 |
charSetToFontMapping at:'x-gbk' put:'gb*'.
|
|
159 |
|
|
160 |
charSetToFontMapping at:'iso2022-kr' put:'ksc*'.
|
|
161 |
charSetToFontMapping at:'x-euc-kr' put:'ksc*'.
|
643
|
162 |
|
|
163 |
"
|
|
164 |
self initialize
|
|
165 |
"
|
|
166 |
|
1022
|
167 |
"Modified: / 1.8.1998 / 17:28:38 / cg"
|
643
|
168 |
! !
|
|
169 |
|
|
170 |
!MIMETypes class methodsFor:'accessing'!
|
|
171 |
|
647
|
172 |
defineImageType:mimeType suffix:aSuffix reader:aReaderClass
|
|
173 |
"register an image reader."
|
|
174 |
|
|
175 |
aSuffix notNil ifTrue:[
|
|
176 |
self imageReaderForSuffix:aSuffix put:aReaderClass.
|
|
177 |
].
|
|
178 |
|
|
179 |
mimeType notNil ifTrue:[
|
|
180 |
self imageReaderForType:mimeType put:aReaderClass
|
|
181 |
].
|
|
182 |
|
|
183 |
(aSuffix notNil and:[mimeType notNil]) ifTrue:[
|
|
184 |
self mimeTypeForSuffix:aSuffix put:mimeType
|
|
185 |
].
|
|
186 |
!
|
|
187 |
|
643
|
188 |
fileSuffixToImageReaderMapping
|
1021
|
189 |
"return the suffix-to-imageReader mapping"
|
|
190 |
|
643
|
191 |
^ FileSuffixToImageReaderClassMapping ? #()
|
|
192 |
|
1021
|
193 |
"Modified: / 1.8.1998 / 17:00:11 / cg"
|
643
|
194 |
!
|
|
195 |
|
648
|
196 |
fontForCharset:aCharSet
|
1021
|
197 |
"return the font-encoding for an iso-charset"
|
|
198 |
|
648
|
199 |
^ CharSetToFontMapping at:aCharSet ifAbsent:nil
|
|
200 |
|
|
201 |
"
|
1021
|
202 |
MIMETypes fontForCharset:'iso2022-jp'
|
648
|
203 |
MIMETypes fontForCharset:'euc-jp'
|
|
204 |
"
|
|
205 |
|
1021
|
206 |
"Modified: / 1.8.1998 / 17:00:57 / cg"
|
648
|
207 |
!
|
|
208 |
|
643
|
209 |
imageFileSuffixes
|
1021
|
210 |
"return a collection with known file suffixes"
|
|
211 |
|
643
|
212 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[^ #()].
|
|
213 |
^ FileSuffixToImageReaderClassMapping keys
|
|
214 |
|
1021
|
215 |
"Created: / 30.6.1997 / 22:04:48 / cg"
|
|
216 |
"Modified: / 1.8.1998 / 17:01:26 / cg"
|
643
|
217 |
!
|
|
218 |
|
|
219 |
imageReaderClasses
|
1021
|
220 |
"return a collection of registered image reader classes"
|
|
221 |
|
645
|
222 |
|setOfClasses|
|
|
223 |
|
|
224 |
setOfClasses := IdentitySet new.
|
|
225 |
FileSuffixToImageReaderClassMapping notNil ifTrue:[
|
|
226 |
FileSuffixToImageReaderClassMapping keysAndValuesDo:[:suff :cls |
|
1021
|
227 |
setOfClasses add:cls
|
|
228 |
].
|
645
|
229 |
].
|
|
230 |
TypeToImageReaderClassMapping notNil ifTrue:[
|
|
231 |
TypeToImageReaderClassMapping keysAndValuesDo:[:suff :cls |
|
1021
|
232 |
setOfClasses add:cls
|
|
233 |
].
|
645
|
234 |
].
|
|
235 |
^ setOfClasses
|
643
|
236 |
|
1021
|
237 |
"Created: / 30.6.1997 / 22:03:42 / cg"
|
|
238 |
"Modified: / 1.8.1998 / 16:59:52 / cg"
|
643
|
239 |
!
|
|
240 |
|
|
241 |
imageReaderForSuffix:aSuffix
|
1021
|
242 |
"given a file suffix, return an approriate image reader class"
|
|
243 |
|
643
|
244 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[^ nil].
|
|
245 |
^ FileSuffixToImageReaderClassMapping at:aSuffix asLowercase ifAbsent:nil
|
|
246 |
|
1021
|
247 |
"Created: / 30.6.1997 / 21:59:11 / cg"
|
|
248 |
"Modified: / 1.8.1998 / 17:01:58 / cg"
|
643
|
249 |
!
|
|
250 |
|
|
251 |
imageReaderForSuffix:aSuffix put:aReaderClass
|
1021
|
252 |
"register an image reader for a file suffix"
|
|
253 |
|
643
|
254 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[
|
|
255 |
FileSuffixToImageReaderClassMapping := Dictionary new.
|
|
256 |
].
|
|
257 |
FileSuffixToImageReaderClassMapping at:aSuffix asLowercase put:aReaderClass
|
|
258 |
|
1021
|
259 |
"Created: / 30.6.1997 / 21:59:43 / cg"
|
|
260 |
"Modified: / 1.8.1998 / 17:02:14 / cg"
|
643
|
261 |
!
|
|
262 |
|
|
263 |
imageReaderForType:mimeTypeString
|
1021
|
264 |
"given a mime-type, return an approriate image reader class"
|
|
265 |
|
643
|
266 |
TypeToImageReaderClassMapping isNil ifTrue:[^ nil].
|
|
267 |
^ TypeToImageReaderClassMapping at:mimeTypeString asLowercase ifAbsent:nil
|
|
268 |
|
1021
|
269 |
"Created: / 30.6.1997 / 21:56:01 / cg"
|
|
270 |
"Modified: / 1.8.1998 / 17:02:28 / cg"
|
643
|
271 |
!
|
|
272 |
|
|
273 |
imageReaderForType:mimeTypeString put:aReaderClass
|
1021
|
274 |
"register an image reader for a mime-type"
|
|
275 |
|
643
|
276 |
TypeToImageReaderClassMapping isNil ifTrue:[
|
|
277 |
TypeToImageReaderClassMapping := Dictionary new.
|
|
278 |
].
|
|
279 |
TypeToImageReaderClassMapping at:mimeTypeString asLowercase put:aReaderClass
|
|
280 |
|
1021
|
281 |
"Created: / 30.6.1997 / 21:56:11 / cg"
|
|
282 |
"Modified: / 1.8.1998 / 17:02:40 / cg"
|
643
|
283 |
!
|
|
284 |
|
|
285 |
mimeTypeForSuffix:suffix
|
1021
|
286 |
"given a file suffix, return the mime-type"
|
|
287 |
|
643
|
288 |
^ FileSuffixToTypeMapping at:suffix asLowercase ifAbsent:nil
|
|
289 |
|
1021
|
290 |
"Created: / 30.6.1997 / 21:55:51 / cg"
|
|
291 |
"Modified: / 1.8.1998 / 17:02:59 / cg"
|
643
|
292 |
!
|
|
293 |
|
|
294 |
mimeTypeForSuffix:suffix put:mimeType
|
1021
|
295 |
"register a mime type for a file suffix"
|
|
296 |
|
643
|
297 |
FileSuffixToTypeMapping isNil ifTrue:[
|
|
298 |
FileSuffixToTypeMapping := Dictionary new
|
|
299 |
].
|
|
300 |
FileSuffixToTypeMapping at:suffix put:mimeType asLowercase
|
|
301 |
|
1021
|
302 |
"Created: / 30.6.1997 / 21:56:20 / cg"
|
|
303 |
"Modified: / 1.8.1998 / 17:03:18 / cg"
|
643
|
304 |
! !
|
|
305 |
|
|
306 |
!MIMETypes class methodsFor:'documentation'!
|
|
307 |
|
|
308 |
version
|
1022
|
309 |
^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.12 1998-08-01 15:28:54 cg Exp $'
|
643
|
310 |
! !
|
|
311 |
MIMETypes initialize!
|