author | Claus Gittinger <cg@exept.de> |
Fri, 11 May 2018 13:09:47 +0200 | |
changeset 4087 | d9336080778d |
parent 4080 | 90b625be9e29 |
child 4088 | bbf9b58f99c8 |
permissions | -rw-r--r-- |
4087 | 1 |
"{ Encoding: utf8 }" |
2 |
||
643 | 3 |
" |
4 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
1612 | 5 |
All Rights Reserved |
643 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
1410 | 14 |
"{ Package: 'stx:libview2' }" |
15 |
||
3451 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
643 | 18 |
Object subclass:#MIMETypes |
1612 | 19 |
instanceVariableNames:'' |
3691 | 20 |
classVariableNames:'CharSetToFontMapping DefaultCommandPerMIMEPerOS |
21 |
DefaultPrintCommandPerMIMEPerOS |
|
22 |
FileSuffixToImageReaderClassMapping FileSuffixToTypeMapping |
|
23 |
FilenameToTypeMapping LastSuffix LastType |
|
24 |
SuffixToCommentStringMapping SuffixToParenthesisSpecMapping |
|
25 |
TypeFromContentsDetectors TypeToCommentStringMapping |
|
26 |
TypeToFileSuffixMapping TypeToImageReaderClassMapping |
|
27 |
TypeToInfoMapping TypeToParenthesisSpecMapping |
|
28 |
TypeToViewerApplicationMapping' |
|
1612 | 29 |
poolDictionaries:'' |
1800 | 30 |
category:'Net-Communication-Support' |
1612 | 31 |
! |
32 |
||
3359 | 33 |
ImmutableString variableByteSubclass:#MIMEType |
1612 | 34 |
instanceVariableNames:'' |
35 |
classVariableNames:'CachedTypes' |
|
36 |
poolDictionaries:'' |
|
37 |
privateIn:MIMETypes |
|
643 | 38 |
! |
39 |
||
40 |
!MIMETypes class methodsFor:'documentation'! |
|
41 |
||
42 |
copyright |
|
43 |
" |
|
44 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
1612 | 45 |
All Rights Reserved |
643 | 46 |
|
47 |
This software is furnished under a license and may be used |
|
48 |
only in accordance with the terms of that license and with the |
|
49 |
inclusion of the above copyright notice. This software may not |
|
50 |
be provided or otherwise made available to, or used by, any |
|
51 |
other person. No title to or ownership of the software is |
|
52 |
hereby transferred. |
|
53 |
||
54 |
||
55 |
" |
|
56 |
! |
|
57 |
||
58 |
documentation |
|
59 |
" |
|
60 |
just a place to keep MIME information |
|
61 |
(avoid spreading things at many places) |
|
62 |
||
1021 | 63 |
MIMETypes is abstract and functional. |
64 |
Actually, in some OperatingSystems, this information may |
|
65 |
be found in some config files (or registries). |
|
66 |
Therefore, this class may have to be extended to support this |
|
67 |
and fetch the information from there eventually. |
|
68 |
||
643 | 69 |
[author:] |
70 |
Claus Gittinger |
|
71 |
" |
|
1311 | 72 |
! |
73 |
||
2486
42063a7fc3db
mimeType: x-expecco-testSuite (extension: ets)
Claus Gittinger <cg@exept.de>
parents:
2479
diff
changeset
|
74 |
examples |
42063a7fc3db
mimeType: x-expecco-testSuite (extension: ets)
Claus Gittinger <cg@exept.de>
parents:
2479
diff
changeset
|
75 |
" |
2970
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
76 |
[exBegin] |
4074 | 77 |
MIMETypes mimeTypeFromString:'text/plain' |
3210 | 78 |
[exEnd] |
79 |
[exBegin] |
|
4074 | 80 |
MIMETypes mimeTypeFromString:'application/x-expecco-testsuite' |
2970
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
81 |
[exEnd] |
2486
42063a7fc3db
mimeType: x-expecco-testSuite (extension: ets)
Claus Gittinger <cg@exept.de>
parents:
2479
diff
changeset
|
82 |
|
2970
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
83 |
[exBegin] |
4074 | 84 |
MIMETypes mimeTypeForSuffix:'gif' |
2970
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
85 |
MIMETypes mimeTypeForSuffix:'ets' |
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
86 |
MIMETypes mimeTypeForSuffix:'xlsx' |
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
87 |
[exEnd] |
2486
42063a7fc3db
mimeType: x-expecco-testSuite (extension: ets)
Claus Gittinger <cg@exept.de>
parents:
2479
diff
changeset
|
88 |
" |
42063a7fc3db
mimeType: x-expecco-testSuite (extension: ets)
Claus Gittinger <cg@exept.de>
parents:
2479
diff
changeset
|
89 |
! |
42063a7fc3db
mimeType: x-expecco-testSuite (extension: ets)
Claus Gittinger <cg@exept.de>
parents:
2479
diff
changeset
|
90 |
|
1311 | 91 |
knownTypes |
92 |
" |
|
93 |
simply a reminder for me ... |
|
94 |
||
95 |
application mime file extentsions |
|
96 |
||
4074 | 97 |
powerpoint application/ms-powerpoint .pot, .ppz, .ppt, .pps, |
98 |
application/mspowerpoint |
|
99 |
application/vnd.ms-powerpoint |
|
1311 | 100 |
application/x-mspowerpoint |
101 |
||
4074 | 102 |
shockwave application/x-shockwave-flash .swf |
1311 | 103 |
|
1312 | 104 |
futuresplash application/futuresplash .spl |
1311 | 105 |
" |
643 | 106 |
! ! |
107 |
||
108 |
!MIMETypes class methodsFor:'initialization'! |
|
109 |
||
3691 | 110 |
addMimeTypeDetector:aMimeTypeFromContentsDetectorBlock |
111 |
"any class (especially: image readers) may add a block |
|
4074 | 112 |
that detects the MIME type from a given content. |
3691 | 113 |
The block is called with two arguments, some data (usually the first few kilobytes |
114 |
of a file) and the suffix of the file, or nil if unknown. |
|
4074 | 115 |
The block should return the MIME type or nil." |
116 |
||
117 |
TypeFromContentsDetectors isNil ifTrue:[ TypeFromContentsDetectors := OrderedCollection new ]. |
|
3691 | 118 |
TypeFromContentsDetectors add:aMimeTypeFromContentsDetectorBlock. |
4074 | 119 |
|
120 |
"Modified (comment): / 01-03-2018 / 19:06:46 / mawalch" |
|
3691 | 121 |
! |
122 |
||
1729 | 123 |
initialize |
124 |
"initialize wellKnown facts" |
|
4074 | 125 |
|
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
126 |
MIMEType initialize. "must be initialized first" |
1729 | 127 |
LastSuffix := LastType := nil. |
128 |
self initializeFileNameToMimeTypeMapping. |
|
129 |
self initializeImageReaderMappings. |
|
130 |
self initializeCommentStringMappings. |
|
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
131 |
self initializeParenthesisSpecMappings. |
4074 | 132 |
|
1729 | 133 |
" |
2970
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
134 |
self initialize |
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
135 |
" |
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
136 |
|
2298 | 137 |
"Modified: / 10-04-2007 / 15:16:44 / cg" |
2970
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
138 |
"Modified (comment): / 29-11-2011 / 19:11:51 / cg" |
1729 | 139 |
! |
140 |
||
141 |
initializeCommentStringMappings |
|
3359 | 142 |
"these are used by the editor's comment/uncomment functions" |
143 |
||
1729 | 144 |
TypeToCommentStringMapping := Dictionary new. |
145 |
SuffixToCommentStringMapping := Dictionary new. |
|
146 |
||
4074 | 147 |
TypeToCommentStringMapping |
1729 | 148 |
at:'application/x-make' |
3359 | 149 |
put:#('#' (nil nil)). "/ '#' EOL comments only |
1729 | 150 |
|
4074 | 151 |
TypeToCommentStringMapping |
1729 | 152 |
at:'application/x-sh' |
3359 | 153 |
put:#('#' (nil nil)). "/ '#' EOL comments only |
1729 | 154 |
|
4074 | 155 |
#('text/html' 'text/xml' |
156 |
'application/xml' |
|
2489
b891d96fd496
elf extension: x-expecco-logfile
Claus Gittinger <cg@exept.de>
parents:
2487
diff
changeset
|
157 |
'application/x-expecco-testsuite' |
b891d96fd496
elf extension: x-expecco-logfile
Claus Gittinger <cg@exept.de>
parents:
2487
diff
changeset
|
158 |
'application/x-expecco-logfile' |
b891d96fd496
elf extension: x-expecco-logfile
Claus Gittinger <cg@exept.de>
parents:
2487
diff
changeset
|
159 |
) |
1729 | 160 |
do:[:eachXMLType | |
4074 | 161 |
TypeToCommentStringMapping |
1729 | 162 |
at:eachXMLType |
163 |
put:#(nil ('<!!-- ' ' -->')). "/ '<!!-- ... -->' delimited comments only |
|
164 |
]. |
|
165 |
||
4074 | 166 |
TypeToCommentStringMapping |
2055 | 167 |
at:'text/css' |
4074 | 168 |
put:#('//' ('/*' '*/')). |
2055 | 169 |
|
4074 | 170 |
TypeToCommentStringMapping |
1729 | 171 |
at:'application/x-batch-script' |
2937
67ef44218dc0
changed: #initializeCommentStringMappings
Claus Gittinger <cg@exept.de>
parents:
2924
diff
changeset
|
172 |
put:#('@REM ' '@rem ' 'REM ' 'rem ' (nil nil)). "/ 'rem ' for EOL comments only |
1729 | 173 |
|
174 |
"/ the following is ST/X specific |
|
4074 | 175 |
TypeToCommentStringMapping |
1729 | 176 |
at:'application/x-smalltalk-source' |
177 |
put:#('"/' ('"' '"')). "/ '"/ ' for EOL; ".." for delimited comments |
|
178 |
||
179 |
"/ this is for standard smalltalk |
|
4074 | 180 |
"/ TypeToCommentStringMapping |
1729 | 181 |
"/ at:'application/x-smalltalk-source' |
182 |
"/ put:#(nil ('"' '"')). "/ ".." for delimited comments only |
|
183 |
||
184 |
||
4074 | 185 |
TypeToCommentStringMapping |
1729 | 186 |
at:'application/x-pascal-source' |
187 |
put:#(nil ('{' '}')). "/ '{'..'}' for delimited comments |
|
188 |
||
189 |
"/ this is ANSI-c |
|
4074 | 190 |
TypeToCommentStringMapping |
1729 | 191 |
at:'application/x-c-source' |
4074 | 192 |
put:#('//' ('/*' '*/')). |
1729 | 193 |
|
4074 | 194 |
TypeToCommentStringMapping |
1729 | 195 |
at:'application/x-cpp-source' |
4074 | 196 |
put:#('//' ('/*' '*/')). |
1729 | 197 |
|
4074 | 198 |
TypeToCommentStringMapping |
2479 | 199 |
at:'application/x-csharp-source' |
4074 | 200 |
put:#('//' ('/*' '*/')). |
2479 | 201 |
|
4074 | 202 |
TypeToCommentStringMapping |
1729 | 203 |
at:'application/x-java-source' |
4074 | 204 |
put:#('//' ('/*' '*/')). |
1729 | 205 |
|
4074 | 206 |
TypeToCommentStringMapping |
2048
dbb361dd9c5f
comment strings for javascript files
Claus Gittinger <cg@exept.de>
parents:
2028
diff
changeset
|
207 |
at:'application/x-javascript' |
4074 | 208 |
put:#('//' ('/*' '*/')). |
2048
dbb361dd9c5f
comment strings for javascript files
Claus Gittinger <cg@exept.de>
parents:
2028
diff
changeset
|
209 |
|
4074 | 210 |
TypeToCommentStringMapping |
4043 | 211 |
at:'application/x-scheme-source' |
212 |
put:#(';' ('#| ' ' |#')). "/ ';' for EOL comments only |
|
213 |
||
4074 | 214 |
TypeToCommentStringMapping |
2298 | 215 |
at:'application/x-lisp-source' |
3482 | 216 |
put:#(';' (nil nil)). "/ ';' for EOL comments only |
217 |
||
4074 | 218 |
TypeToCommentStringMapping |
3482 | 219 |
at:'application/x-python-source' |
220 |
put:#('#' (nil nil)). "/ '#' for EOL comments only |
|
2298 | 221 |
|
4074 | 222 |
TypeToCommentStringMapping |
1729 | 223 |
at:'application/x-asn1-source' |
4074 | 224 |
put:#('--' ('--' '--')). |
1729 | 225 |
|
226 |
||
227 |
"/ st/x support files |
|
4074 | 228 |
SuffixToCommentStringMapping |
1729 | 229 |
at:'style' |
4074 | 230 |
put:#(';' (nil nil)). |
1604 | 231 |
|
4074 | 232 |
SuffixToCommentStringMapping |
1729 | 233 |
at:'rs' |
2298 | 234 |
put:#(';' (nil nil)). |
235 |
||
2937
67ef44218dc0
changed: #initializeCommentStringMappings
Claus Gittinger <cg@exept.de>
parents:
2924
diff
changeset
|
236 |
"Modified: / 06-09-2011 / 10:46:27 / cg" |
1729 | 237 |
! |
238 |
||
239 |
initializeDefaultCommands |
|
3359 | 240 |
"these are used to select an application to be opened when a file of a particular |
241 |
type is double clicked in the browser. |
|
242 |
TODO: move this to OS" |
|
1729 | 243 |
|
3253 | 244 |
|unixCommands win32Commands unixPrintCommands win32PrintCommands listToTry| |
1729 | 245 |
|
246 |
DefaultCommandPerMIMEPerOS := Dictionary new. |
|
247 |
DefaultCommandPerMIMEPerOS at:#unix put:(unixCommands := Dictionary new). |
|
248 |
DefaultCommandPerMIMEPerOS at:#win32 put:(win32Commands := Dictionary new). |
|
249 |
||
3187 | 250 |
unixCommands at:'application/x-tar-compressed' put:'tar tvf -'. |
1729 | 251 |
|
2141 | 252 |
OperatingSystem isMSWINDOWSlike ifFalse:[ |cmd| |
3253 | 253 |
OperatingSystem isOSXlike ifTrue:[ |
4074 | 254 |
unixCommands at:'text/html' put:('open -a Safari "%1"'). |
255 |
unixCommands at:'application/pdf' put:('open -a Preview "%1"'). |
|
3253 | 256 |
] ifFalse:[ |
3322 | 257 |
listToTry := #('firefox' 'chrome' 'chromium' 'konqueror' 'opera'). |
258 |
cmd := listToTry |
|
259 |
detect:[:aCmd| (OperatingSystem pathOfCommand:aCmd) notEmptyOrNil ] |
|
260 |
ifNone:nil. |
|
261 |
cmd notNil ifTrue:[ |
|
4074 | 262 |
unixCommands at:'text/html' put:(cmd, ' "%1"') |
3322 | 263 |
]. |
3187 | 264 |
|
3322 | 265 |
listToTry := #('acroread' 'okular' 'evince' 'kpdf' 'xpdf'). |
266 |
cmd := listToTry |
|
267 |
detect:[:aCmd| (OperatingSystem pathOfCommand:aCmd) notEmptyOrNil ] |
|
268 |
ifNone:nil. |
|
269 |
cmd notNil ifTrue:[ |
|
4074 | 270 |
unixCommands at:'application/pdf' put:(cmd, ' "%1"') |
3322 | 271 |
]. |
4073 | 272 |
|
273 |
listToTry := #('xdg-open'). |
|
274 |
cmd := listToTry |
|
275 |
detect:[:aCmd| (OperatingSystem pathOfCommand:aCmd) notEmptyOrNil ] |
|
276 |
ifNone:nil. |
|
277 |
cmd notNil ifTrue:[ |
|
4074 | 278 |
unixCommands at:'text/plain' put:(cmd , ' "%1"') |
4073 | 279 |
]. |
280 |
||
3187 | 281 |
]. |
2141 | 282 |
]. |
283 |
||
284 |
||
2116 | 285 |
DefaultPrintCommandPerMIMEPerOS := Dictionary new. |
286 |
DefaultPrintCommandPerMIMEPerOS at:#unix put:(unixPrintCommands := Dictionary new). |
|
287 |
DefaultPrintCommandPerMIMEPerOS at:#win32 put:(win32PrintCommands := Dictionary new). |
|
288 |
||
289 |
"/ if you have a good (intelligent) spooler ;-) |
|
2904
bb555534881e
changed: #initializeDefaultCommands
Stefan Vogel <sv@exept.de>
parents:
2892
diff
changeset
|
290 |
unixPrintCommands at:'application/pdf' put:'lpr "%1"'. |
2116 | 291 |
"/ if not, you may need more... |
292 |
"/ unixPrintCommands at:'application/pdf' put:'pdfToPS %1 | lpr'. |
|
293 |
||
1729 | 294 |
" |
295 |
self initializeDefaultCommands |
|
296 |
" |
|
1979
0612875a95c1
acroread command from registry (win32)
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
297 |
|
0612875a95c1
acroread command from registry (win32)
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
298 |
"Modified: / 12-05-2004 / 11:43:23 / cg" |
4073 | 299 |
"Modified: / 01-03-2018 / 18:42:42 / mawalch" |
1729 | 300 |
! |
301 |
||
3359 | 302 |
initializeFileInfoMappings |
303 |
"these are used by the file browser if a 'file' command is not present in the OS" |
|
304 |
||
305 |
TypeToInfoMapping := Dictionary new. |
|
306 |
||
307 |
TypeToInfoMapping at:'application/x-smalltalk-source' put:'Smalltalk source'. |
|
308 |
TypeToInfoMapping at:'text/html' put:'HTML document'. |
|
309 |
TypeToInfoMapping at:'text/xml' put:'XML document'. |
|
310 |
TypeToInfoMapping at:'application/xml' put:'XML document'. |
|
311 |
TypeToInfoMapping at:'application/x-c-source' put:'C source'. |
|
312 |
TypeToInfoMapping at:'application/x-c-header' put:'C header file'. |
|
313 |
TypeToInfoMapping at:'application/x-cpp-source' put:'C++ source'. |
|
314 |
TypeToInfoMapping at:'application/x-csharp-source' put:'C# source'. |
|
315 |
TypeToInfoMapping at:'application/x-java-source' put:'Java source'. |
|
4030 | 316 |
TypeToInfoMapping at:'application/x-javascript' put:'JavaScript source'. |
3359 | 317 |
TypeToInfoMapping at:'application/x-lisp-source' put:'Lisp source'. |
4043 | 318 |
TypeToInfoMapping at:'application/x-scheme-source' put:'Scheme source'. |
3482 | 319 |
TypeToInfoMapping at:'application/x-python-source' put:'Python source'. |
3359 | 320 |
|
321 |
TypeToInfoMapping at:'application/x-make' put:'make rules'. |
|
322 |
TypeToInfoMapping at:'application/binary' put:'binary object file'. |
|
323 |
||
324 |
" |
|
325 |
self initializeFileInfoMappings |
|
326 |
'foo.H' asFilename mimeTypeFromName |
|
327 |
'foo.o' asFilename mimeTypeFromName |
|
328 |
" |
|
4030 | 329 |
|
330 |
"Modified: / 30-11-2017 / 07:54:23 / mawalch" |
|
3359 | 331 |
! |
332 |
||
1729 | 333 |
initializeFileNameToMimeTypeMapping |
334 |
"initialize wellKnown facts" |
|
335 |
||
336 |
|types| |
|
337 |
||
338 |
FileSuffixToTypeMapping isNil ifTrue:[ |
|
3870 | 339 |
FileSuffixToTypeMapping := Dictionary new:270. |
1729 | 340 |
]. |
1887 | 341 |
TypeToFileSuffixMapping isNil ifTrue:[ |
3870 | 342 |
TypeToFileSuffixMapping := Dictionary new:105. |
1887 | 343 |
]. |
1729 | 344 |
FilenameToTypeMapping isNil ifTrue:[ |
3870 | 345 |
FilenameToTypeMapping := Dictionary new:16. |
1729 | 346 |
]. |
347 |
||
348 |
types := OrderedCollection new. |
|
349 |
types addAll:self textTypeList. |
|
350 |
types addAll:self imageTypeList. |
|
351 |
types addAll:self videoTypeList. |
|
352 |
types addAll:self audioTypeList. |
|
353 |
types addAll:self applicationTypeList. |
|
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
354 |
types addAll:self osSpecificTypeList. |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
355 |
|
1729 | 356 |
types pairWiseDo:[:suff :typeString| |
3870 | 357 |
|mimeType| |
1729 | 358 |
|
3870 | 359 |
mimeType := MIMEType fromString:typeString. |
1729 | 360 |
suff isArray ifTrue:[ |
3870 | 361 |
suff do:[:s |FileSuffixToTypeMapping at:s put:mimeType]. |
362 |
TypeToFileSuffixMapping at:mimeType put:suff first. |
|
1729 | 363 |
] ifFalse:[ |
3870 | 364 |
FileSuffixToTypeMapping at:suff put:mimeType. |
365 |
TypeToFileSuffixMapping at:mimeType put:suff. |
|
1887 | 366 |
]. |
1729 | 367 |
]. |
368 |
||
3870 | 369 |
self miscFilenameList pairWiseDo:[:suffixes :typeString| |
370 |
|mimeType| |
|
1729 | 371 |
|
3870 | 372 |
mimeType := MIMEType fromString:typeString. |
373 |
suffixes isArray ifTrue:[ |
|
374 |
suffixes do:[:eachSuffix | FilenameToTypeMapping at:eachSuffix put:mimeType] |
|
1729 | 375 |
] ifFalse:[ |
3870 | 376 |
FilenameToTypeMapping at:suffixes put:mimeType |
1729 | 377 |
] |
378 |
]. |
|
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
379 |
|
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
380 |
" |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
381 |
self initializeFileNameToMimeTypeMapping |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
382 |
" |
3870 | 383 |
|
384 |
"Modified (format): / 09-02-2017 / 14:59:33 / stefan" |
|
1729 | 385 |
! |
386 |
||
387 |
initializeImageReaderMappings |
|
4074 | 388 |
"these are used so select an image reader, based on a bitmap image's MIME type" |
3359 | 389 |
|
3295 | 390 |
|rdr| |
391 |
||
1729 | 392 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[ |
393 |
FileSuffixToImageReaderClassMapping := Dictionary new |
|
394 |
]. |
|
395 |
"MIME" TypeToImageReaderClassMapping isNil ifTrue:[ |
|
396 |
TypeToImageReaderClassMapping := Dictionary new |
|
397 |
]. |
|
398 |
||
399 |
"/ setup mimeType to image reader class mapping ... |
|
3870 | 400 |
self imageReaderForType:'image/jpeg' put:JPEGReader. |
401 |
self imageReaderForType:'image/gif' put:GIFReader. |
|
402 |
self imageReaderForType:'image/tiff' put:TIFFReader. |
|
3978 | 403 |
self imageReaderForType:'image/x-adobe-dng' put:TIFFReader. |
3870 | 404 |
self imageReaderForType:'image/png' put:PNGReader. |
405 |
self imageReaderForType:'image/icns' put:MacOSXIconReader. |
|
1729 | 406 |
|
407 |
"/ setup suffix to image reader class mapping ... |
|
3870 | 408 |
self imageReaderForSuffix:'jpg' put:JPEGReader. |
409 |
self imageReaderForSuffix:'jpeg' put:JPEGReader. |
|
410 |
self imageReaderForSuffix:'gif' put:GIFReader. |
|
411 |
self imageReaderForSuffix:'tif' put:TIFFReader. |
|
412 |
self imageReaderForSuffix:'tiff' put:TIFFReader. |
|
413 |
self imageReaderForSuffix:'png' put:PNGReader. |
|
414 |
self imageReaderForSuffix:'icns' put:MacOSXIconReader. |
|
2570 | 415 |
|
3295 | 416 |
"/ some 'used-to-be-optional' readers |
417 |
(rdr := Smalltalk at:#WindowsIconReader) notNil ifTrue:[ |
|
3870 | 418 |
self imageReaderForType:'image/bmp' put:rdr. |
419 |
self imageReaderForType:'image/x-MS-bmp' put:rdr. |
|
420 |
self imageReaderForType:'image/x-ms-bmp' put:rdr. |
|
421 |
self imageReaderForType:'image/x-MS-ico' put:rdr. |
|
422 |
self imageReaderForType:'image/x-ms-ico' put:rdr. |
|
423 |
self imageReaderForSuffix:'bmp' put:rdr. |
|
424 |
self imageReaderForSuffix:'ico' put:rdr. |
|
3295 | 425 |
]. |
426 |
(rdr := Smalltalk at:#XBMReader) notNil ifTrue:[ |
|
3870 | 427 |
self imageReaderForType:'image/x-xbitmap' put:rdr. |
428 |
self imageReaderForSuffix:'xbm' put:rdr. |
|
3295 | 429 |
]. |
430 |
(rdr := Smalltalk at:#XPMReader) notNil ifTrue:[ |
|
3870 | 431 |
self imageReaderForType:'image/x-xpixmap' put:rdr. |
432 |
self imageReaderForSuffix:'pm' put:rdr. |
|
3295 | 433 |
]. |
434 |
(rdr := Smalltalk at:#PBMReader) notNil ifTrue:[ |
|
3870 | 435 |
self imageReaderForType:'image/x-portable-pixmap' put:rdr. |
436 |
self imageReaderForType:'image/x-portable-bitmap' put:rdr. |
|
437 |
self imageReaderForType:'image/x-portable-graymap' put:rdr. |
|
438 |
self imageReaderForType:'image/x-portable-anymap' put:rdr. |
|
439 |
self imageReaderForSuffix:'ppm' put:rdr. |
|
440 |
self imageReaderForSuffix:'pbm' put:rdr. |
|
441 |
self imageReaderForSuffix:'pgm' put:rdr. |
|
442 |
self imageReaderForSuffix:'pnm' put:rdr. |
|
3295 | 443 |
]. |
444 |
(rdr := Smalltalk at:#PCXReader) notNil ifTrue:[ |
|
3870 | 445 |
self imageReaderForType:'image/x-pcx' put:rdr. |
446 |
self imageReaderForSuffix:'pcx' put:rdr. |
|
3295 | 447 |
]. |
448 |
(rdr := Smalltalk at:#TargaReader) notNil ifTrue:[ |
|
3870 | 449 |
self imageReaderForType:'image/x-targa' put:rdr. |
450 |
self imageReaderForSuffix:'tga' put:rdr. |
|
3295 | 451 |
]. |
452 |
(rdr := Smalltalk at:#XWDReader) notNil ifTrue:[ |
|
3870 | 453 |
self imageReaderForType:'image/x-xwindowdump' put:rdr. |
454 |
self imageReaderForType:'image/x-windowdump' put:rdr. |
|
455 |
self imageReaderForSuffix:'xwd' put:rdr. |
|
3295 | 456 |
]. |
457 |
(rdr := Smalltalk at:#BlitImageReader) notNil ifTrue:[ |
|
3870 | 458 |
self imageReaderForType:'image/x-blitimage' put:rdr. |
459 |
self imageReaderForSuffix:'48x48x1' put:rdr. |
|
3295 | 460 |
]. |
461 |
(rdr := Smalltalk at:#IrisRGBReader) notNil ifTrue:[ |
|
3870 | 462 |
self imageReaderForType:'image/x-rgb' put:rdr. |
463 |
self imageReaderForSuffix:'rgb' put:rdr. |
|
3295 | 464 |
]. |
465 |
(rdr := Smalltalk at:#SunRasterReader) notNil ifTrue:[ |
|
3870 | 466 |
self imageReaderForType:'image/x-sunraster' put:rdr. |
467 |
self imageReaderForSuffix:'im8' put:rdr. |
|
468 |
self imageReaderForSuffix:'icon' put:rdr. |
|
2570 | 469 |
]. |
3295 | 470 |
(rdr := Smalltalk at:#ST80FormReader) notNil ifTrue:[ |
3870 | 471 |
self imageReaderForType:'image/x-st80-form' put:rdr. |
472 |
self imageReaderForSuffix:'form' put:rdr. |
|
3295 | 473 |
]. |
474 |
(rdr := Smalltalk at:#FaceReader) notNil ifTrue:[ |
|
3870 | 475 |
self imageReaderForType:'image/x-face' put:rdr. |
476 |
self imageReaderForSuffix:'face' put:rdr. |
|
3295 | 477 |
]. |
478 |
(rdr := Smalltalk at:#PCDReader) notNil ifTrue:[ |
|
3870 | 479 |
self imageReaderForType:'image/x-photo-cd' put:rdr. |
480 |
self imageReaderForSuffix:'pcd' put:rdr. |
|
3295 | 481 |
]. |
482 |
(rdr := Smalltalk at:#CMURasterReader) notNil ifTrue:[ |
|
3870 | 483 |
self imageReaderForType:'image/x-cmu-raster' put:rdr. |
484 |
self imageReaderForSuffix:'ras' put:rdr. |
|
3295 | 485 |
]. |
486 |
||
3359 | 487 |
"/ movie formats - experimental and not yet complete / finished / delivered / published |
3295 | 488 |
"/ (rdr := Smalltalk at:#FLIReader) notNil ifTrue:[ |
3870 | 489 |
"/ self imageReaderForType:'video/x-fli' put:rdr. |
490 |
"/ self imageReaderForSuffix:'fli' put:rdr. |
|
3295 | 491 |
"/ ]. |
492 |
"/ (rdr := Smalltalk at:#AVIReader) notNil ifTrue:[ |
|
3870 | 493 |
"/ self imageReaderForType:'video/x-msvideo' put:rdr. |
494 |
"/ self imageReaderForSuffix:'avi' put:rdr. |
|
3295 | 495 |
"/ ]. |
496 |
"/ (rdr := Smalltalk at:#AVIReader) notNil ifTrue:[ |
|
3870 | 497 |
"/ self imageReaderForType:'video/x-msvideo' put:rdr. |
498 |
"/ self imageReaderForSuffix:'avi' put:rdr. |
|
3295 | 499 |
"/ ]. |
500 |
"/ (rdr := Smalltalk at:#QuickTimeReader) notNil ifTrue:[ |
|
3870 | 501 |
"/ self imageReaderForType:'video/quicktime' put:rdr. |
502 |
"/ self imageReaderForSuffix:'qt' put:rdr. |
|
503 |
"/ self imageReaderForSuffix:'mov' put:rdr. |
|
504 |
"/ self imageReaderForSuffix:'moov' put:rdr. |
|
3295 | 505 |
"/ ]. |
506 |
"/ (rdr := Smalltalk at:#MPEG2Reader) notNil ifTrue:[ |
|
3870 | 507 |
"/ self imageReaderForType:'video/x-mpeg2' put:rdr. |
508 |
"/ self imageReaderForSuffix:'mpg2' put:rdr. |
|
509 |
"/ self imageReaderForSuffix:'mpv2' put:rdr. |
|
510 |
"/ self imageReaderForSuffix:'mp2v' put:rdr. |
|
511 |
"/ self imageReaderForSuffix:'mp2' put:rdr. |
|
3295 | 512 |
"/ ]. |
513 |
"/ (rdr := Smalltalk at:#MPEGReader) notNil ifTrue:[ |
|
3870 | 514 |
"/ self imageReaderForType:'video/mpeg' put:rdr. |
515 |
"/ self imageReaderForSuffix:'mpg' put:rdr. |
|
516 |
"/ self imageReaderForSuffix:'mpeg' put:rdr. |
|
517 |
"/ self imageReaderForSuffix:'mpe' put:rdr. |
|
518 |
"/ self imageReaderForSuffix:'mpv' put:rdr. |
|
519 |
"/ self imageReaderForSuffix:'vps' put:rdr. |
|
520 |
"/ self imageReaderForSuffix:'mpegv' put:rdr. |
|
3295 | 521 |
"/ ]. |
522 |
"/ (rdr := Smalltalk at:#SGIMovieReader) notNil ifTrue:[ |
|
3870 | 523 |
"/ self imageReaderForType:'video/x-sgi-movie' put:rdr. |
524 |
"/ self imageReaderForSuffix:'movie' put:rdr. |
|
3295 | 525 |
"/ ]. |
3870 | 526 |
|
527 |
"Modified (format): / 09-02-2017 / 15:46:48 / stefan" |
|
3978 | 528 |
"Modified: / 25-08-2017 / 15:24:51 / cg" |
2298 | 529 |
! |
530 |
||
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
531 |
initializeParenthesisSpecMappings |
4074 | 532 |
"these are used by the editors to mark matching parentheses" |
3359 | 533 |
|
2298 | 534 |
|spec| |
535 |
||
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
536 |
TypeToParenthesisSpecMapping := Dictionary new. |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
537 |
SuffixToParenthesisSpecMapping := Dictionary new. |
4074 | 538 |
|
2298 | 539 |
"/ ST/X spec |
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
540 |
spec := IdentityDictionary new. |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
541 |
spec at:#open put:#( $( $[ ${ ). |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
542 |
spec at:#close put:#( $) $] $} ). |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
543 |
spec at:#ignore put:#( $' $" '$[' '$]' '${' '$)' ). |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
544 |
spec at:#eolComment put:'"/'. |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
545 |
TypeToParenthesisSpecMapping at:'application/x-smalltalk-source' put:spec. |
4074 | 546 |
|
2479 | 547 |
"/ XML & HTML |
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
548 |
spec := IdentityDictionary new. |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
549 |
spec at:#open put:#( $< ). |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
550 |
spec at:#close put:#( $> ). |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
551 |
spec at:#ignore put:#( $' $" '$[' '$]' '${' '$)' ). |
4074 | 552 |
#( 'text/html' 'text/xml' 'application/xml' ) do:[:eachXMLType | |
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
553 |
TypeToParenthesisSpecMapping at:eachXMLType put:spec |
2298 | 554 |
]. |
4074 | 555 |
|
556 |
"/ ANSI-c, Java, C# |
|
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
557 |
spec := IdentityDictionary new. |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
558 |
spec at:#open put:#( $( $[ ${ ). |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
559 |
spec at:#close put:#( $) $] $} ). |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
560 |
spec at:#ignore put:#( $' $" ). |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
561 |
spec at:#eolComment put:'//'. |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
562 |
TypeToParenthesisSpecMapping at:'application/x-c-source' put:spec. |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
563 |
TypeToParenthesisSpecMapping at:'application/x-cpp-source' put:spec. |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
564 |
TypeToParenthesisSpecMapping at:'application/x-csharp-source' put:spec. |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
565 |
TypeToParenthesisSpecMapping at:'application/x-java-source' put:spec. |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
566 |
TypeToParenthesisSpecMapping at:'application/x-javascript' put:spec. |
3482 | 567 |
TypeToParenthesisSpecMapping at:'application/x-python-source' put:spec. |
4074 | 568 |
|
569 |
"/ Lisp / Scheme |
|
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
570 |
spec := IdentityDictionary new. |
3039 | 571 |
spec at:#open put:#( $( $[ ). |
572 |
spec at:#close put:#( $) $] ). |
|
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
573 |
spec at:#ignore put:#( $" ). |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
574 |
spec at:#eolComment put:';'. |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
575 |
TypeToParenthesisSpecMapping at:'application/x-lisp-source' put:spec. |
4043 | 576 |
TypeToParenthesisSpecMapping at:'application/x-scheme-source' put:spec. |
2298 | 577 |
|
578 |
"Created: / 10-04-2007 / 15:16:37 / cg" |
|
4074 | 579 |
"Modified (format): / 01-03-2018 / 19:02:39 / mawalch" |
1729 | 580 |
! ! |
581 |
||
582 |
!MIMETypes class methodsFor:'initialization-lists'! |
|
583 |
||
584 |
applicationCompressorsAndArchiveTypeList |
|
3862 | 585 |
"compressor applications" |
586 |
||
1604 | 587 |
^ #( |
4074 | 588 |
"/ the first column is a list of extensions, the second the more-or-less official MIME type |
589 |
||
1890 | 590 |
'tar' 'application/x-tar' |
591 |
'gtar' 'application/x-gtar' |
|
4065 | 592 |
('tgz' 'tar.gz') 'application/x-tar-gzip-compressed' "/ 'application/x-tar-compressed' |
1891 | 593 |
('tar.bz2') 'application/x-tar-bzip2-compressed' |
4065 | 594 |
'zip' 'application/x-zip-compressed' "/ will be changed to application/zip soon |
1890 | 595 |
'bz2' 'application/x-bzip2-compressed' |
4065 | 596 |
('gz' 'z') 'application/x-gzip-compressed' "/ will be changed to application/gzip soon |
597 |
'lz' 'application/lzip' |
|
1890 | 598 |
'cpio' 'application/x-cpio' |
599 |
'shar' 'application/x-shar' |
|
600 |
'jar' 'application/java-archive' |
|
601 |
'sar' 'application/x-squeak-archive' |
|
602 |
'sit' 'application/x-stuffit' |
|
603 |
'hqx' 'application/mac-binhex40' |
|
604 |
'cpt' 'application/mac-compactpro' |
|
4065 | 605 |
'pkg' 'application/x-xar' "/ a mac archiver for packages |
1604 | 606 |
) |
3862 | 607 |
|
608 |
"Modified (format): / 05-02-2017 / 19:37:10 / cg" |
|
4074 | 609 |
"Modified (comment): / 01-03-2018 / 19:07:27 / mawalch" |
1604 | 610 |
! |
645 | 611 |
|
1609 | 612 |
applicationMiscTypeList |
613 |
"misc applications" |
|
614 |
||
615 |
^ #( |
|
4074 | 616 |
"/ the first column is a list of extensions, the second the more-or-less official MIME type |
3862 | 617 |
|
3870 | 618 |
('a' 'o' 'obj' ) 'application/binary' |
619 |
'lic' 'application/license' |
|
620 |
('dll' 'so') 'application/shared-library' |
|
2486
42063a7fc3db
mimeType: x-expecco-testSuite (extension: ets)
Claus Gittinger <cg@exept.de>
parents:
2479
diff
changeset
|
621 |
|
3870 | 622 |
'ets' 'application/x-expecco-testsuite' |
623 |
'etr' 'application/x-expecco-testrepository' |
|
624 |
'elf' 'application/x-expecco-logfile' |
|
625 |
'expeccolicense' 'application/x-expecco-license' |
|
626 |
'expeccopatch' 'application/x-expecco-patch' |
|
1609 | 627 |
) |
2886
22b48a4da285
comment/format in: #initializeFileNameToMimeTypeMapping
sr
parents:
2830
diff
changeset
|
628 |
|
2968 | 629 |
"Modified: / 03-11-2011 / 10:42:28 / sr" |
3862 | 630 |
"Modified (format): / 05-02-2017 / 19:37:05 / cg" |
3870 | 631 |
"Modified: / 09-02-2017 / 14:31:45 / stefan" |
4074 | 632 |
"Modified (comment): / 01-03-2018 / 19:07:37 / mawalch" |
1609 | 633 |
! |
634 |
||
1604 | 635 |
applicationProgLangTypeList |
3020
3f9c74ff0975
changed: #applicationProgLangTypeList
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
636 |
"applications for programming languages" |
713 | 637 |
|
1604 | 638 |
^ #( |
4074 | 639 |
"/ the first column is a list of extensions, the second the more-or-less official MIME type |
3862 | 640 |
|
1609 | 641 |
('st' 'cls' 'rc') 'application/x-smalltalk-source' |
1604 | 642 |
'sif' 'application/x-smalltalk-source-sif' |
1668 | 643 |
'pac' 'application/x-smalltalk-dolphin-package' |
1778 | 644 |
|
645 |
'sts' 'application/x-squeak-source' |
|
646 |
'pr' 'application/x-squeak-project' |
|
647 |
||
1604 | 648 |
'c' 'application/x-c-source' |
649 |
('cc' 'cpp') 'application/x-cpp-source' |
|
2479 | 650 |
'cs' 'application/x-csharp-source' |
1609 | 651 |
('h' 'hi') 'application/x-c-header' |
1604 | 652 |
('js' 'mocha') 'application/x-javascript' |
653 |
('java' 'jav') 'application/x-java-source' |
|
654 |
'sh' 'application/x-sh' |
|
655 |
'csh' 'application/x-csh' |
|
656 |
'tcl' 'application/x-tcl' |
|
657 |
'pl' 'application/x-perl' |
|
3020
3f9c74ff0975
changed: #applicationProgLangTypeList
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
658 |
'dart' 'application/x-dart' |
1604 | 659 |
'mak' 'application/x-make' |
660 |
'bat' 'application/x-batch-script' |
|
3008 | 661 |
('asn1' 'x409' 'gdmo' 'gdm') 'application/x-asn1-source' |
662 |
||
4068 | 663 |
('scm' 'ss' 'sch' |
4043 | 664 |
'arc' 'brg' 'rkt') 'application/x-scheme-source' |
665 |
||
666 |
('lisp' 'lsp' 'cl' ) 'application/x-lisp-source' |
|
4074 | 667 |
|
3482 | 668 |
'py' 'application/x-python-source' |
3961 | 669 |
('pyc' 'pyo' ) 'application/x-python-compiled-bytecode' |
670 |
'pyd' 'application/x-python-compiled-code' |
|
671 |
'whl' 'application/x-python-wheel-package' |
|
1604 | 672 |
) |
2298 | 673 |
|
3961 | 674 |
"Modified: / 23-06-2017 / 13:34:37 / cg" |
4074 | 675 |
"Modified (comment): / 01-03-2018 / 19:07:43 / mawalch" |
1604 | 676 |
! |
1561 | 677 |
|
1604 | 678 |
applicationTextTypeList |
1606 | 679 |
"text applications" |
1604 | 680 |
|
681 |
^ #( |
|
4074 | 682 |
"/ the first column is a list of extensions, the second the more-or-less official MIME type |
3862 | 683 |
|
1604 | 684 |
('ps' 'eps') 'application/postscript' |
1778 | 685 |
"/ 'ai' 'application/postscript' |
1604 | 686 |
'pdf' 'application/pdf' |
687 |
'rtf' 'application/rtf' |
|
1778 | 688 |
"/ 'rtf' 'text/rtf' ???? |
3008 | 689 |
'ics' 'text/calendar' |
690 |
'doc' 'application/ms-word-document' |
|
1778 | 691 |
"/ 'doc' 'application/winword' |
692 |
'swf' 'application/x-shockwave-flash' |
|
693 |
('ppt' 'ppz' 'pot' 'pps') 'application/mspowerpoint' |
|
4074 | 694 |
'xls' 'application/x-excel' |
2028 | 695 |
'slk' 'application/vnd.ms-excel' |
2911
7afaf1fdae8b
comment/format in: #mimeTypeForFilename:
Claus Gittinger <cg@exept.de>
parents:
2904
diff
changeset
|
696 |
'txt' 'text/plain' |
2970
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
697 |
'xlsx' 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' |
3476 | 698 |
'xltx' 'application/vnd.openxmlformats-officedocument.spreadsheetml.template' |
699 |
'potx' 'application/vnd.openxmlformats-officedocument.presentationml.template' |
|
700 |
'ppsx' 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' |
|
701 |
'pptx' 'application/vnd.openxmlformats-officedocument.presentationml.presentation' |
|
702 |
'sldx' 'application/vnd.openxmlformats-officedocument.presentationml.slide' |
|
703 |
'docx' 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' |
|
704 |
'dotx' 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' |
|
705 |
'xlam' 'application/vnd.ms-excel.addin.macroEnabled.12' |
|
706 |
'xlsb' 'application/vnd.ms-excel.sheet.binary.macroEnabled.12' |
|
3952 | 707 |
'xhtml' 'application/xhtml+xml' |
3482 | 708 |
|
709 |
'edi' 'application/EDIFACT' |
|
1604 | 710 |
) |
2911
7afaf1fdae8b
comment/format in: #mimeTypeForFilename:
Claus Gittinger <cg@exept.de>
parents:
2904
diff
changeset
|
711 |
|
3008 | 712 |
"Modified: / 26-05-2012 / 15:27:30 / cg" |
3476 | 713 |
"Modified: / 18-05-2015 / 09:46:47 / sr" |
3862 | 714 |
"Modified (format): / 05-02-2017 / 19:37:20 / cg" |
4074 | 715 |
"Modified (comment): / 01-03-2018 / 19:07:51 / mawalch" |
1604 | 716 |
! |
717 |
||
718 |
applicationTypeList |
|
1606 | 719 |
"applications" |
1604 | 720 |
|
4074 | 721 |
|typeList| |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
722 |
|
1729 | 723 |
typeList := OrderedCollection new. |
724 |
typeList addAll:self applicationProgLangTypeList. |
|
725 |
typeList addAll:self applicationTextTypeList. |
|
726 |
typeList addAll:self applicationCompressorsAndArchiveTypeList. |
|
727 |
typeList addAll:self applicationMiscTypeList. |
|
1616 | 728 |
|
1729 | 729 |
^ typeList |
1604 | 730 |
! |
731 |
||
732 |
audioTypeList |
|
1606 | 733 |
"audio formats ..." |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
734 |
|
1604 | 735 |
^ #( |
4074 | 736 |
"/ the first column is a list of extensions, the second the more-or-less official MIME type |
3862 | 737 |
|
1720 | 738 |
('au' 'snd') 'audio/basic' |
3870 | 739 |
'ra' 'audio/x-realaudio' |
1778 | 740 |
('ram' 'rm') 'audio/x-pn-realaudio' |
3862 | 741 |
"/ cg: see unixSpecific / windowsSpecific |
742 |
"/ 'rpm' 'audio/x-pn-realaudio-plugin' |
|
3008 | 743 |
('mpa' 'mpega' 'mpga') 'audio/mpeg' |
3862 | 744 |
"/ 'mp3' 'audio/x-mp3' |
1778 | 745 |
('mp3' 'mp2') 'audio/mpeg' |
1604 | 746 |
'wav' 'audio/x-wav' |
747 |
('aif' 'aiff' 'aifc') 'audio/x-aiff' |
|
1778 | 748 |
('midi' 'mid') 'audio/midi' |
1604 | 749 |
) |
3008 | 750 |
|
751 |
"Modified: / 26-05-2012 / 15:23:45 / cg" |
|
3862 | 752 |
"Modified (comment): / 05-02-2017 / 19:37:48 / cg" |
3870 | 753 |
"Modified: / 09-02-2017 / 14:29:59 / stefan" |
4074 | 754 |
"Modified (comment): / 01-03-2018 / 19:07:54 / mawalch" |
1604 | 755 |
! |
756 |
||
757 |
imageTypeList |
|
4013 | 758 |
"/ wellknown image formats ... |
1604 | 759 |
|
760 |
^ #( |
|
4074 | 761 |
"/ the first column is a list of extensions, the second the more-or-less official MIME type |
762 |
||
1216 | 763 |
('jpg' 'jpeg') 'image/jpeg' |
1188 | 764 |
'gif' 'image/gif' |
765 |
('tif' 'tiff') 'image/tiff' |
|
3295 | 766 |
('xbm' 'bm') 'image/x-xbitmap' |
1188 | 767 |
'xpm' 'image/x-xpixmap' |
1720 | 768 |
'png' 'image/png' |
1188 | 769 |
'pcd' 'image/x-photo-cd' |
770 |
'bmp' 'image/x-MS-bmp' |
|
771 |
'rgb' 'image/x-rgb' |
|
772 |
'ppm' 'image/x-portable-pixmap' |
|
773 |
'pgm' 'image/x-portable-graymap' |
|
774 |
'pbm' 'image/x-portable-bitmap' |
|
775 |
'pnm' 'image/x-portable-anymap' |
|
776 |
'xwd' 'image/x-xwindowdump' |
|
777 |
'ras' 'image/x-cmu-raster' |
|
1216 | 778 |
'tga' 'image/x-targa' |
4013 | 779 |
'ico' 'image/x-icon' |
4074 | 780 |
'icns' 'image/icns' |
3978 | 781 |
'dng' 'image/x-adobe-dng' |
3862 | 782 |
) |
783 |
||
4013 | 784 |
"Modified: / 13-09-2017 / 09:05:15 / cg" |
4074 | 785 |
"Modified (comment): / 01-03-2018 / 19:08:18 / mawalch" |
1604 | 786 |
! |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
787 |
|
1609 | 788 |
miscFilenameList |
3104 | 789 |
"other formats (not by suffix, but by fileName instead) ..." |
1609 | 790 |
|
791 |
^ #( |
|
4074 | 792 |
"/ the first column is a list of extensions, the second the more-or-less official MIME type |
3862 | 793 |
|
2113 | 794 |
('makefile' 'make.proto' 'make.spec' 'nt.mak') 'application/x-make' |
2830 | 795 |
('exe' 'bin' 'com') 'application/octet-stream' |
2113 | 796 |
('class') 'application/octet-stream' |
2375 | 797 |
('top') 'application/x-waltop-digital-notepad' |
1609 | 798 |
) |
3862 | 799 |
|
800 |
"Modified (comment): / 05-02-2017 / 19:38:00 / cg" |
|
4074 | 801 |
"Modified (comment): / 01-03-2018 / 19:09:17 / mawalch" |
1609 | 802 |
! |
803 |
||
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
804 |
osSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
805 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
806 |
^ self windowsSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
807 |
]. |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
808 |
^ self unixSpecificTypeList |
2023 | 809 |
|
810 |
" |
|
811 |
self osSpecificTypeList |
|
812 |
" |
|
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
813 |
! |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
814 |
|
1604 | 815 |
textTypeList |
816 |
"/ misc text ... |
|
817 |
||
818 |
^ #( |
|
4074 | 819 |
"/ the first column is a list of extensions, the second the more-or-less official MIME type |
3862 | 820 |
|
1887 | 821 |
('html' 'htm' 'shtml') 'text/html' |
1604 | 822 |
('txt' 'text') 'text/plain' |
1680 | 823 |
'xml' 'text/xml' |
3862 | 824 |
'fxml' 'text/xml' |
3517 | 825 |
'xsd' 'text/xml' |
1777 | 826 |
'css' 'text/css' |
2432 | 827 |
'csv' 'text/csv' |
1604 | 828 |
) |
3862 | 829 |
|
830 |
"Modified: / 05-02-2017 / 19:38:12 / cg" |
|
4074 | 831 |
"Modified (comment): / 01-03-2018 / 19:09:34 / mawalch" |
1604 | 832 |
! |
833 |
||
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
834 |
unixSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
835 |
|
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
836 |
^ #( |
4074 | 837 |
"/ the first column is a list of extensions, the second the more-or-less official MIME type |
3862 | 838 |
|
839 |
"/ cg: RPM is 'audio/x-pn-realaudio-plugin' for WIN32 |
|
840 |
"/ and 'application/x-rpm' for Unix |
|
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
841 |
'rpm' 'application/x-rpm' |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
842 |
) |
3862 | 843 |
|
844 |
"Modified (comment): / 05-02-2017 / 19:38:23 / cg" |
|
4074 | 845 |
"Modified (comment): / 01-03-2018 / 19:09:37 / mawalch" |
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
846 |
! |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
847 |
|
1604 | 848 |
videoTypeList |
849 |
"/ video formats ... |
|
850 |
||
851 |
^ #( |
|
3862 | 852 |
"/ the first column is a list of extensions, the second the more-or-less official mimetype |
853 |
||
1720 | 854 |
('qt' 'mov' 'moov') 'video/quicktime' |
855 |
('mpv' 'mpegv' 'mpg' 'mpeg' 'mpe') 'video/mpeg' |
|
1604 | 856 |
'movie' 'video/x-sgi-movie' |
1820 | 857 |
('avi' 'wmv' 'asf') 'video/x-msvideo' |
1604 | 858 |
('mpv2' 'mp2v' 'mp2' 'mpeg2') 'video/x-mpeg2' |
3367 | 859 |
('mp4') 'video/mp4' |
1680 | 860 |
'rm' 'application/vnd.rn-realmedia' |
861 |
'rv' 'video/x-pn-realvideo' |
|
3295 | 862 |
'fli' 'video/x-fli' |
3367 | 863 |
'flv' 'video/x-flv' "/ macromedia flash video |
1778 | 864 |
) |
3862 | 865 |
|
866 |
"Modified (comment): / 05-02-2017 / 19:38:33 / cg" |
|
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
867 |
! |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
868 |
|
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
869 |
windowsSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
870 |
^ #( |
4074 | 871 |
"/ the first column is a list of extensions, the second the more-or-less official MIME type |
3862 | 872 |
|
873 |
"/ cg: RPM is 'audio/x-pn-realaudio-plugin' for WIN32 |
|
874 |
"/ and 'application/x-rpm' for Unix |
|
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
875 |
'rpm' 'audio/x-pn-realaudio-plugin' |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
876 |
) |
3862 | 877 |
|
878 |
"Modified (comment): / 05-02-2017 / 19:38:42 / cg" |
|
4074 | 879 |
"Modified (comment): / 01-03-2018 / 19:09:41 / mawalch" |
643 | 880 |
! ! |
881 |
||
1729 | 882 |
!MIMETypes class methodsFor:'obsolete'! |
1489 | 883 |
|
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
884 |
defaultCommandForMimeType:mimeType |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
885 |
<resource: #obsolete> |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
886 |
self obsoleteMethodWarning:'use #defaultCommandTemplateToOpenMimeType:'. |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
887 |
|
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
888 |
^ self defaultCommandTemplateToOpenMimeType:mimeType |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
889 |
|
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
890 |
" |
4074 | 891 |
MIMETypes defaultCommandTemplateToOpenMimeType:'application/pdf' |
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
892 |
" |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
893 |
|
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
894 |
"Created: / 12-05-2004 / 11:09:22 / cg" |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
895 |
"Modified: / 12-05-2004 / 11:16:53 / cg" |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
896 |
! |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
897 |
|
1729 | 898 |
fontForCharset:aCharSetName |
899 |
"return the font-encoding for an iso-charset" |
|
1489 | 900 |
|
1981 | 901 |
<resource:#obsolete> |
1729 | 902 |
self obsoleteMethodWarning:'use FontDescription >> fontNamePatternForCharset:'. |
903 |
^ FontDescription fontNamePatternForCharset:aCharSetName. |
|
1489 | 904 |
|
905 |
" |
|
4074 | 906 |
MIMETypes fontForCharset:'iso2022-jp' |
907 |
MIMETypes fontForCharset:'euc-jp' |
|
1472 | 908 |
" |
909 |
||
1729 | 910 |
"Modified: / 1.8.1998 / 17:00:57 / cg" |
911 |
! ! |
|
1472 | 912 |
|
1729 | 913 |
!MIMETypes class methodsFor:'queries'! |
1472 | 914 |
|
647 | 915 |
defineImageType:mimeType suffix:aSuffix reader:aReaderClass |
916 |
"register an image reader." |
|
917 |
||
3981 | 918 |
self defineImageType:mimeType suffix:aSuffix reader:aReaderClass info:nil |
919 |
||
920 |
"Modified: / 26-08-2017 / 10:30:00 / cg" |
|
921 |
! |
|
922 |
||
923 |
defineImageType:mimeType suffix:aSuffix reader:aReaderClass info:info |
|
924 |
"register an image reader." |
|
925 |
||
4080 | 926 |
"/ flush caches |
927 |
LastSuffix := LastType := nil. |
|
928 |
||
647 | 929 |
aSuffix notNil ifTrue:[ |
930 |
self imageReaderForSuffix:aSuffix put:aReaderClass. |
|
931 |
]. |
|
932 |
||
933 |
mimeType notNil ifTrue:[ |
|
934 |
self imageReaderForType:mimeType put:aReaderClass |
|
935 |
]. |
|
936 |
||
937 |
(aSuffix notNil and:[mimeType notNil]) ifTrue:[ |
|
938 |
self mimeTypeForSuffix:aSuffix put:mimeType |
|
939 |
]. |
|
4074 | 940 |
|
3981 | 941 |
(info notNil and:[mimeType notNil]) ifTrue:[ |
3982 | 942 |
self typeToInfoMapping at:mimeType put:info. |
3981 | 943 |
]. |
944 |
||
945 |
"Created: / 26-08-2017 / 10:29:11 / cg" |
|
3982 | 946 |
"Modified: / 27-08-2017 / 14:30:53 / cg" |
647 | 947 |
! |
948 |
||
3359 | 949 |
fileInfoForMimeType:mimeType |
950 |
"given a mimeType, return an info string similar to what the unix 'file' command |
|
951 |
provides. This info here is returned by systems which have no file (i.e. MSDOS) and |
|
952 |
for types of which file does not know about (smalltalk files, for example)" |
|
953 |
||
3982 | 954 |
^ self typeToInfoMapping at:mimeType ifAbsent:nil |
3359 | 955 |
|
956 |
" |
|
4074 | 957 |
self fileInfoForMimeType:(MIMEType fromString:'text/html') |
958 |
self fileInfoForMimeType:(MIMEType fromString:'image/gif') |
|
3359 | 959 |
" |
3982 | 960 |
|
961 |
"Modified (comment): / 27-08-2017 / 14:31:33 / cg" |
|
3359 | 962 |
! |
963 |
||
643 | 964 |
fileSuffixToImageReaderMapping |
1021 | 965 |
"return the suffix-to-imageReader mapping" |
966 |
||
643 | 967 |
^ FileSuffixToImageReaderClassMapping ? #() |
968 |
||
1021 | 969 |
"Modified: / 1.8.1998 / 17:00:11 / cg" |
643 | 970 |
! |
971 |
||
972 |
imageFileSuffixes |
|
1021 | 973 |
"return a collection with known file suffixes" |
974 |
||
643 | 975 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[^ #()]. |
976 |
^ FileSuffixToImageReaderClassMapping keys |
|
977 |
||
1021 | 978 |
"Created: / 30.6.1997 / 22:04:48 / cg" |
979 |
"Modified: / 1.8.1998 / 17:01:26 / cg" |
|
643 | 980 |
! |
981 |
||
3014
e6d9a204da08
comment/format in: #mimeTypeForFilename:
Claus Gittinger <cg@exept.de>
parents:
3012
diff
changeset
|
982 |
mimeTypeForFilename:filenameOrString |
4074 | 983 |
"given a filename, return the MIME type or nil if unknown" |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
984 |
|
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
985 |
|type filename lcFilename suff suff2| |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
986 |
|
3014
e6d9a204da08
comment/format in: #mimeTypeForFilename:
Claus Gittinger <cg@exept.de>
parents:
3012
diff
changeset
|
987 |
filename := filenameOrString asFilename. |
1474 | 988 |
|
989 |
lcFilename := filename baseName asLowercase. |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
990 |
type := FilenameToTypeMapping at:lcFilename ifAbsent:nil. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
991 |
type isNil ifTrue:[ |
3962 | 992 |
"/ allow for fallback (maybe Windows registry knows something)... |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
993 |
type := OperatingSystem mimeTypeForFilename:lcFilename. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
994 |
"/ 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
|
995 |
"/ 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
|
996 |
"/ the OS. |
1275 | 997 |
"/ type isNil ifTrue:[ |
998 |
"/ FilenameToTypeMapping at:lcFilename put:#unknown |
|
999 |
"/ ]. |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1000 |
]. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1001 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1002 |
type == #unknown ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1003 |
type := nil. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1004 |
]. |
1273
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
1005 |
|
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
1006 |
type isNil ifTrue:[ |
1473 | 1007 |
suff := filename suffix. |
3962 | 1008 |
suff notEmpty ifTrue:[ |
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1009 |
"/ sigh - special code for multiple-suffices... |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1010 |
"/ .tar.gz -> tgz |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1011 |
suff2 := filename withoutSuffix suffix. |
3962 | 1012 |
suff2 notEmpty ifTrue:[ |
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1013 |
type := self mimeTypeForSuffix:(suff2 , '.' , suff). |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1014 |
]. |
3983 | 1015 |
(type isNil or:[type == #unknown]) ifTrue:[ |
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1016 |
type := self mimeTypeForSuffix:suff |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1017 |
]. |
1273
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
1018 |
] |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
1019 |
]. |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
1020 |
|
3871 | 1021 |
type == #unknown ifTrue:[ |
1022 |
type := nil. |
|
1023 |
]. |
|
1024 |
||
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1025 |
^ type |
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1026 |
|
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1027 |
" |
4074 | 1028 |
MIMETypes mimeTypeForFilename:'typeinst.dvi' |
2820 | 1029 |
MIMETypes mimeTypeForFilename:'foo.tar' |
1030 |
MIMETypes mimeTypeForFilename:'foo.tgz' |
|
1031 |
MIMETypes mimeTypeForFilename:'foo.tar.gz' |
|
4074 | 1032 |
MIMETypes mimeTypeForFilename:'foo.txt' |
1033 |
MIMETypes mimeTypeForFilename:'foo.pkg' |
|
1034 |
MIMETypes mimeTypeForFilename:'foo.sm' |
|
3983 | 1035 |
MIMETypes mimeTypeForFilename:'/Users/cg/work/stx/goodies/bitmaps/tiffimages/moreSamples/multi-channel.ome.tif' |
1036 |
MIMETypes mimeTypeForFilename:'multi-channel.ome.tif' |
|
1037 |
MIMETypes mimeTypeForFilename:'multi-channel.tif' |
|
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1038 |
" |
2911
7afaf1fdae8b
comment/format in: #mimeTypeForFilename:
Claus Gittinger <cg@exept.de>
parents:
2904
diff
changeset
|
1039 |
|
3962 | 1040 |
"Modified (format): / 27-06-2017 / 16:25:40 / stefan" |
3983 | 1041 |
"Modified: / 27-08-2017 / 16:35:37 / cg" |
4074 | 1042 |
"Modified (comment): / 01-03-2018 / 18:52:25 / mawalch" |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1043 |
! |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1044 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1045 |
mimeTypeForFilename:filename put:mimeType |
4074 | 1046 |
"register a MIME type for a filename" |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1047 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1048 |
FilenameToTypeMapping isNil ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1049 |
FilenameToTypeMapping := Dictionary new |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1050 |
]. |
1612 | 1051 |
FilenameToTypeMapping at:filename put:(MIMEType fromString:mimeType asLowercase) |
4074 | 1052 |
|
1053 |
"Modified (comment): / 01-03-2018 / 18:52:42 / mawalch" |
|
1611 | 1054 |
! |
1055 |
||
643 | 1056 |
mimeTypeForSuffix:suffix |
4074 | 1057 |
"given a file suffix, return the MIME type" |
1021 | 1058 |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
1059 |
|type lcSuffix| |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
1060 |
|
1837 | 1061 |
suffix = LastSuffix ifTrue:[ |
1062 |
^ LastType |
|
1063 |
]. |
|
1064 |
||
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
1065 |
lcSuffix := suffix asLowercase. |
1837 | 1066 |
type := FileSuffixToTypeMapping at:lcSuffix ifAbsent:nil. |
1067 |
type isNil ifTrue:[ |
|
1068 |
"/ allow for fallback ... |
|
1069 |
type := OperatingSystem mimeTypeForSuffix:lcSuffix. |
|
1070 |
"/ the special value #unknown is returned as nil; |
|
4074 | 1071 |
"/ this avoids constant retry if a suffix is not known in the OS. |
3870 | 1072 |
type := type isNil ifTrue:[#unknown] ifFalse:[MIMEType fromString:type]. |
1837 | 1073 |
FileSuffixToTypeMapping at:lcSuffix put:type. |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
1074 |
]. |
1837 | 1075 |
|
3870 | 1076 |
LastSuffix := suffix. |
1077 |
LastType := type. |
|
1841 | 1078 |
^ type |
643 | 1079 |
|
1666 | 1080 |
" |
4074 | 1081 |
self mimeTypeForSuffix:'gif' |
1082 |
self mimeTypeForSuffix:'rpm' |
|
1083 |
self mimeTypeForSuffix:'zip' |
|
1666 | 1084 |
" |
1085 |
||
2891 | 1086 |
"Created: / 30-06-1997 / 21:55:51 / cg" |
1087 |
"Modified: / 14-02-2011 / 17:14:34 / cg" |
|
3870 | 1088 |
"Modified: / 09-02-2017 / 14:57:52 / stefan" |
4074 | 1089 |
"Modified (comment): / 01-03-2018 / 18:51:35 / mawalch" |
643 | 1090 |
! |
1091 |
||
1092 |
mimeTypeForSuffix:suffix put:mimeType |
|
4074 | 1093 |
"register a MIME type for a file suffix" |
1021 | 1094 |
|
643 | 1095 |
FileSuffixToTypeMapping isNil ifTrue:[ |
1096 |
FileSuffixToTypeMapping := Dictionary new |
|
1097 |
]. |
|
3870 | 1098 |
FileSuffixToTypeMapping at:suffix ifAbsentPut:[MIMEType fromString:mimeType asLowercase]. |
643 | 1099 |
|
3870 | 1100 |
"Created: / 30-06-1997 / 21:56:20 / cg" |
1101 |
"Modified: / 01-08-1998 / 17:03:18 / cg" |
|
1102 |
"Modified: / 09-02-2017 / 15:09:17 / stefan" |
|
4074 | 1103 |
"Modified (comment): / 01-03-2018 / 18:51:17 / mawalch" |
1593 | 1104 |
! |
1105 |
||
1106 |
mimeTypeForSuffixMapping |
|
1107 |
||
1108 |
^ FileSuffixToTypeMapping |
|
1611 | 1109 |
! |
1110 |
||
2023 | 1111 |
mimeTypeFromString:mimeTypeString |
4074 | 1112 |
"given a MIME type for a string" |
2023 | 1113 |
|
1114 |
^ MIMEType fromString:mimeTypeString |
|
1115 |
||
1116 |
" |
|
4074 | 1117 |
MIMETypes mimeTypeFromString:'text/html' |
1118 |
MIMETypes mimeTypeFromString:'image/gif' |
|
1119 |
MIMETypes mimeTypeFromString:'application/x-expecco-testsuite' |
|
2023 | 1120 |
" |
4074 | 1121 |
|
1122 |
"Modified (comment): / 01-03-2018 / 18:49:50 / mawalch" |
|
2023 | 1123 |
! |
1124 |
||
1611 | 1125 |
mimeTypeOfContents:filename |
4074 | 1126 |
"given a filename, scan the contents, return the MIME type or nil, if unknown" |
1611 | 1127 |
|
1612 | 1128 |
|typeString| |
1129 |
||
1130 |
typeString := filename mimeTypeOfContents. |
|
1131 |
typeString isNil ifTrue:[^ nil]. |
|
1132 |
^ MIMEType fromString:typeString. |
|
4074 | 1133 |
|
1134 |
"Modified (comment): / 01-03-2018 / 18:50:06 / mawalch" |
|
1887 | 1135 |
! |
1136 |
||
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1137 |
mimeTypeOfData:someData |
4074 | 1138 |
"this tries to guess the MIME type of contents of someData. |
1139 |
Returns nil if unknown. |
|
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1140 |
This is done using some heuristics, and may need some improvement" |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1141 |
|
3400 | 1142 |
^ self mimeTypeOfData:someData suffix:nil |
4074 | 1143 |
|
1144 |
"Modified (comment): / 01-03-2018 / 18:50:22 / mawalch" |
|
3400 | 1145 |
! |
1146 |
||
1147 |
mimeTypeOfData:someData suffix:fileNameSuffixOrNilIfUnknown |
|
4074 | 1148 |
"this tries to guess the MIME type of someData. |
1149 |
Returns nil if unknown. |
|
3691 | 1150 |
In addition to registered detectors (see addMimeTypeDetector:), |
4072 | 1151 |
this is done using heuristics, and may need some improvement" |
3400 | 1152 |
|
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1153 |
|buffer lcBuffer size idx idx2| |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1154 |
|
2583 | 1155 |
someData isEmptyOrNil ifTrue:[^ nil]. |
1156 |
||
3691 | 1157 |
TypeFromContentsDetectors notNil ifTrue:[ |
1158 |
TypeFromContentsDetectors do:[:eachDetector | |
|
1159 |
|m| |
|
1160 |
||
1161 |
m := eachDetector value:someData value:fileNameSuffixOrNilIfUnknown. |
|
1162 |
m notNil ifTrue:[^ m] |
|
1163 |
] |
|
1164 |
]. |
|
1165 |
||
2583 | 1166 |
size := 2048 min:someData size. |
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1167 |
|
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1168 |
"/ read some data from the file ... |
2583 | 1169 |
buffer := (someData copyTo:size) asString. |
3691 | 1170 |
|
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1171 |
lcBuffer := buffer asLowercase. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1172 |
|
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1173 |
(idx := lcBuffer findString:'mimetype:') ~~ 0 ifTrue:[ |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1174 |
idx := idx + 'mimetype:' size. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1175 |
idx := lcBuffer indexOfNonSeparatorStartingAt:idx. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1176 |
idx2 := lcBuffer indexOfSeparatorStartingAt:idx. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1177 |
idx2 > idx ifTrue:[ |
2583 | 1178 |
^ MIMEType fromString:(lcBuffer copyFrom:idx to:idx2-1) |
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1179 |
]. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1180 |
]. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1181 |
|
2924 | 1182 |
"/ real starters |
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1183 |
#( |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1184 |
( #[16r4C 16r00 16r00 16r00 16r01 16r14 16r02 16r00 16r00 16r00 16r00 16r00 16rC0 16r00 16r00 16r00 16r00 16r00 16r00 16r46] |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1185 |
#'application/x-ms-shortcut' ) |
2924 | 1186 |
( 'ITOLITLS' |
1187 |
#'application/x-ms-reader' ) |
|
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1188 |
( 'WALTOP' |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1189 |
#'application/x-waltop-digital-notepad' ) |
2892 | 1190 |
('PK' |
1191 |
#'application/x-zip-compressed') |
|
4065 | 1192 |
('LZIP' |
1193 |
#'application/lzip') |
|
3113 | 1194 |
('<?xml' |
1195 |
#'text/xml') |
|
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1196 |
) pairsDo:[:pattern :what | |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1197 |
|patternString| |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1198 |
|
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1199 |
patternString := pattern asString. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1200 |
(buffer startsWith:patternString) ifTrue:[ |
3400 | 1201 |
what = #'application/x-zip-compressed' ifTrue:[ |
1202 |
fileNameSuffixOrNilIfUnknown = 'jar' ifTrue:[ |
|
1203 |
^ MIMEType fromString: #'application/java-archive' |
|
1204 |
]. |
|
1205 |
]. |
|
2583 | 1206 |
^ MIMEType fromString:what |
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1207 |
] |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1208 |
]. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1209 |
|
2924 | 1210 |
"/ somewhere near the beginning |
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1211 |
#( |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1212 |
('<body:' #'text/html') |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1213 |
('%!!ps-adobe' #'application/postscript') |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1214 |
('%PDF-' #'application/pdf') |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1215 |
('#!! /bin/sh' #'application/x-sh') |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1216 |
('#!!/bin/sh' #'application/x-sh') |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1217 |
"/ ('#!! /bin/bash' 'application/x-bash') |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1218 |
"/ ('#!!/bin/bash' 'application/x-bash') |
3482 | 1219 |
('UNB+UNO' #'application/EDIFACT') |
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1220 |
|
3113 | 1221 |
('---- encoding: ' #'application/x-smalltalk-source') |
1222 |
('---- timestamp ' #'application/x-smalltalk-source') |
|
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1223 |
('from dolphin' #'application/x-smalltalk-source') |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1224 |
('from visualworks' #'application/x-smalltalk-source') |
3359 | 1225 |
('from squeak' #'application/x-smalltalk-source') |
1226 |
('from smalltalk/x' #'application/x-smalltalk-source') |
|
1227 |
('"{ Package:' #'application(x-smalltalk-source') |
|
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1228 |
('categoriesforclass' #'application/x-smalltalk-source') |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1229 |
('methodsfor!!' #'application/x-smalltalk-source') |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1230 |
('subclass:' #'application/x-smalltalk-source') |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1231 |
('methodsfor:' #'application/x-smalltalk-source') |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1232 |
('interchangeversion:' #'application/x-smalltalk-source-sif') |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1233 |
('subclass:' #'application/x-smalltalk-source') |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1234 |
('methodsfor:' #'application/x-smalltalk-source') |
3332 | 1235 |
('Application create:' #'application/x-smalltalk-source') |
1236 |
('becomeDefault!!' #'application/x-smalltalk-source') |
|
3451 | 1237 |
('(reader defineClass:' #'application/x-smalltalk-source') "/ gravel smalltalk |
4072 | 1238 |
('(define ' #'application/x-scheme-source') |
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1239 |
|
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1240 |
) pairsDo:[:pattern :what | |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1241 |
(lcBuffer findString:pattern) ~~ 0 ifTrue:[ |
2583 | 1242 |
^ MIMEType fromString:what |
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1243 |
] |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1244 |
]. |
3691 | 1245 |
|
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1246 |
(idx := lcBuffer findString:'<h') ~~ 0 ifTrue:[ |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1247 |
((lcBuffer continuesWith:'<head' startingAt:idx) |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1248 |
or:[(lcBuffer continuesWith:'<html' startingAt:idx) |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1249 |
or:[(lcBuffer continuesWith:'<h1' startingAt:idx) |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1250 |
or:[(lcBuffer continuesWith:'<h2' startingAt:idx) |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1251 |
or:[(lcBuffer continuesWith:'<h3' startingAt:idx) |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1252 |
or:[(lcBuffer continuesWith:'<h4' startingAt:idx) |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1253 |
or:[(lcBuffer continuesWith:'<h5' startingAt:idx) |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1254 |
or:[(lcBuffer continuesWith:'<h6' startingAt:idx)]]]]]]]) |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1255 |
ifTrue:[ |
2583 | 1256 |
^ MIMEType fromString:'text/html' |
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1257 |
] |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1258 |
]. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1259 |
|
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1260 |
[size ~~ 0 and:[(buffer at:size) isPrintable]] whileTrue:[size := size - 1]. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1261 |
|
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1262 |
size == 0 ifTrue:[ |
2583 | 1263 |
^ MIMEType fromString:'text/plain' |
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1264 |
]. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1265 |
^ nil |
2891 | 1266 |
|
2924 | 1267 |
"Modified: / 12-07-2011 / 19:08:17 / cg" |
4074 | 1268 |
"Modified (comment): / 01-03-2018 / 18:50:36 / mawalch" |
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1269 |
! |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1270 |
|
1887 | 1271 |
suffixForMimeType:mimeType |
4074 | 1272 |
"given a file suffix, return the MIME type" |
1887 | 1273 |
|
1274 |
^ TypeToFileSuffixMapping at:mimeType ifAbsent:nil |
|
1275 |
||
1276 |
" |
|
4074 | 1277 |
self suffixForMimeType:(MIMEType fromString:'image/gif') |
1887 | 1278 |
" |
1279 |
||
4074 | 1280 |
"Created: / 30-06-1997 / 21:55:51 / cg" |
1281 |
"Modified: / 23-12-1999 / 22:30:55 / cg" |
|
1282 |
"Modified (comment): / 01-03-2018 / 18:50:50 / mawalch" |
|
1887 | 1283 |
! |
1284 |
||
1285 |
suffixForMimeTypeString:mimeTypeString |
|
4074 | 1286 |
"given a file suffix, return the MIME type" |
1887 | 1287 |
|
4074 | 1288 |
^ self suffixForMimeType:(MIMEType fromString:mimeTypeString) |
1887 | 1289 |
|
1290 |
" |
|
4074 | 1291 |
self suffixForMimeTypeString:'image/gif' |
1887 | 1292 |
" |
1293 |
||
4074 | 1294 |
"Created: / 30-06-1997 / 21:55:51 / cg" |
1295 |
"Modified: / 23-12-1999 / 22:30:55 / cg" |
|
1296 |
"Modified (comment): / 01-03-2018 / 18:51:06 / mawalch" |
|
3982 | 1297 |
! |
1298 |
||
1299 |
typeToInfoMapping |
|
1300 |
TypeToInfoMapping isNil ifTrue:[ |
|
1301 |
self initializeFileInfoMappings |
|
1302 |
]. |
|
1303 |
^ TypeToInfoMapping |
|
1304 |
||
1305 |
"Created: / 27-08-2017 / 14:30:44 / cg" |
|
1612 | 1306 |
! ! |
1307 |
||
2116 | 1308 |
!MIMETypes class methodsFor:'queries-applications'! |
1309 |
||
2117 | 1310 |
defaultCommandPerMIME |
4074 | 1311 |
"returns the collection which is used to map MIME type to command-templates." |
2117 | 1312 |
|
1313 |
"TODO: move this to OS/UserPreferences" |
|
1314 |
||
1315 |
DefaultCommandPerMIMEPerOS isNil ifTrue:[ |
|
1316 |
self initializeDefaultCommands |
|
1317 |
]. |
|
1318 |
OperatingSystem isUNIXlike ifTrue:[ |
|
1319 |
^ DefaultCommandPerMIMEPerOS at:#unix |
|
1320 |
]. |
|
1321 |
^ DefaultCommandPerMIMEPerOS at:#win32 |
|
2942
693d381bc775
comment/format in: #defaultCommandPerMIME
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1322 |
|
693d381bc775
comment/format in: #defaultCommandPerMIME
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1323 |
" |
693d381bc775
comment/format in: #defaultCommandPerMIME
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1324 |
MIMETypes defaultCommandPerMIME |
693d381bc775
comment/format in: #defaultCommandPerMIME
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1325 |
" |
693d381bc775
comment/format in: #defaultCommandPerMIME
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1326 |
|
693d381bc775
comment/format in: #defaultCommandPerMIME
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1327 |
"Modified (comment): / 16-09-2011 / 16:20:12 / cg" |
4074 | 1328 |
"Modified (comment): / 01-03-2018 / 19:06:54 / mawalch" |
2117 | 1329 |
! |
1330 |
||
2116 | 1331 |
defaultCommandTemplateToOpenMimeType:mimeType |
1332 |
|cmd| |
|
1333 |
||
1334 |
cmd := self defaultCommandPerMIME at:mimeType ifAbsent:nil. |
|
1335 |
cmd isNil ifTrue:[ |
|
1336 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
|
1337 |
cmd := Win32OperatingSystem::RegistryEntry commandTemplateToOpenMimeType:mimeType |
|
1338 |
]. |
|
1339 |
]. |
|
1340 |
^ cmd |
|
1341 |
||
1342 |
" |
|
1343 |
MIMETypes defaultCommandTemplateToOpenMimeType:'application/pdf' |
|
2118 | 1344 |
MIMETypes defaultCommandTemplateToOpenMimeType:'text/html' |
2116 | 1345 |
" |
1346 |
||
1347 |
"Created: / 12-05-2004 / 11:09:22 / cg" |
|
1348 |
"Modified: / 12-05-2004 / 11:16:53 / cg" |
|
1349 |
! |
|
1350 |
||
1351 |
defaultCommandTemplateToPrintMimeType:mimeType |
|
1352 |
|cmd| |
|
1353 |
||
1354 |
cmd := self defaultPrintCommandPerMIME at:mimeType ifAbsent:nil. |
|
1355 |
cmd isNil ifTrue:[ |
|
1356 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
|
1357 |
cmd := Win32OperatingSystem::RegistryEntry commandTemplateToPrintMimeType:mimeType |
|
1358 |
]. |
|
1359 |
]. |
|
1360 |
^ cmd |
|
1361 |
||
1362 |
" |
|
1363 |
MIMETypes defaultCommandTemplateToPrintMimeType:'application/pdf' |
|
1364 |
" |
|
2117 | 1365 |
! |
1366 |
||
1367 |
defaultPrintCommandPerMIME |
|
4074 | 1368 |
"returns the collection which is used to map MIME type to printing command-templates." |
2117 | 1369 |
|
1370 |
"TODO: move this to OS/UserPreferences" |
|
1371 |
||
1372 |
DefaultPrintCommandPerMIMEPerOS isNil ifTrue:[ |
|
1373 |
self initializeDefaultCommands |
|
1374 |
]. |
|
1375 |
OperatingSystem isUNIXlike ifTrue:[ |
|
1376 |
^ DefaultPrintCommandPerMIMEPerOS at:#unix |
|
1377 |
]. |
|
1378 |
^ DefaultPrintCommandPerMIMEPerOS at:#win32 |
|
2116 | 1379 |
! ! |
1380 |
||
1729 | 1381 |
!MIMETypes class methodsFor:'queries-image formats'! |
1382 |
||
1383 |
imageReaderClasses |
|
1384 |
"return a collection of registered image reader classes" |
|
1385 |
||
3870 | 1386 |
TypeToImageReaderClassMapping notNil ifTrue:[ |
1387 |
^ TypeToImageReaderClassMapping values asSet. |
|
1729 | 1388 |
]. |
3870 | 1389 |
^ #(). |
1729 | 1390 |
|
3870 | 1391 |
"Created: / 30-06-1997 / 22:03:42 / cg" |
1392 |
"Modified: / 01-08-1998 / 16:59:52 / cg" |
|
1393 |
"Modified: / 09-02-2017 / 15:23:52 / stefan" |
|
1729 | 1394 |
! |
1395 |
||
1396 |
imageReaderForSuffix:aSuffix |
|
4074 | 1397 |
"given a file suffix, return an appropriate image reader class" |
1729 | 1398 |
|
2724
8e834e62dbbc
Initialize when querying for image type and not yet initialized
Stefan Vogel <sv@exept.de>
parents:
2710
diff
changeset
|
1399 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[ |
8e834e62dbbc
Initialize when querying for image type and not yet initialized
Stefan Vogel <sv@exept.de>
parents:
2710
diff
changeset
|
1400 |
self initializeImageReaderMappings |
8e834e62dbbc
Initialize when querying for image type and not yet initialized
Stefan Vogel <sv@exept.de>
parents:
2710
diff
changeset
|
1401 |
]. |
1729 | 1402 |
^ FileSuffixToImageReaderClassMapping at:aSuffix asLowercase ifAbsent:nil |
1403 |
||
4080 | 1404 |
" |
1405 |
self imageReaderForSuffix:'wbmp' |
|
1406 |
" |
|
1407 |
||
4074 | 1408 |
"Created: / 30-06-1997 / 21:59:11 / cg" |
1409 |
"Modified: / 01-08-1998 / 17:01:58 / cg" |
|
1410 |
"Modified (comment): / 01-03-2018 / 18:57:59 / mawalch" |
|
1729 | 1411 |
! |
1412 |
||
1413 |
imageReaderForSuffix:aSuffix put:aReaderClass |
|
1414 |
"register an image reader for a file suffix" |
|
1415 |
||
1416 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[ |
|
2724
8e834e62dbbc
Initialize when querying for image type and not yet initialized
Stefan Vogel <sv@exept.de>
parents:
2710
diff
changeset
|
1417 |
self initializeImageReaderMappings |
1729 | 1418 |
]. |
1419 |
FileSuffixToImageReaderClassMapping at:aSuffix asLowercase put:aReaderClass |
|
1420 |
||
1421 |
"Created: / 30.6.1997 / 21:59:43 / cg" |
|
1422 |
"Modified: / 1.8.1998 / 17:02:14 / cg" |
|
1423 |
! |
|
1424 |
||
1425 |
imageReaderForType:mimeTypeString |
|
4074 | 1426 |
"given a MIME type, return an appropriate image reader class" |
1729 | 1427 |
|
2724
8e834e62dbbc
Initialize when querying for image type and not yet initialized
Stefan Vogel <sv@exept.de>
parents:
2710
diff
changeset
|
1428 |
TypeToImageReaderClassMapping isNil ifTrue:[ |
8e834e62dbbc
Initialize when querying for image type and not yet initialized
Stefan Vogel <sv@exept.de>
parents:
2710
diff
changeset
|
1429 |
self initializeImageReaderMappings |
8e834e62dbbc
Initialize when querying for image type and not yet initialized
Stefan Vogel <sv@exept.de>
parents:
2710
diff
changeset
|
1430 |
]. |
1729 | 1431 |
^ TypeToImageReaderClassMapping at:mimeTypeString asLowercase ifAbsent:nil |
1432 |
||
4074 | 1433 |
"Created: / 30-06-1997 / 21:56:01 / cg" |
1434 |
"Modified: / 01-08-1998 / 17:02:28 / cg" |
|
1435 |
"Modified (format): / 01-03-2018 / 18:58:10 / mawalch" |
|
1729 | 1436 |
! |
1437 |
||
1438 |
imageReaderForType:mimeTypeString put:aReaderClass |
|
4074 | 1439 |
"register an image reader for a MIME type" |
1729 | 1440 |
|
1441 |
TypeToImageReaderClassMapping isNil ifTrue:[ |
|
2724
8e834e62dbbc
Initialize when querying for image type and not yet initialized
Stefan Vogel <sv@exept.de>
parents:
2710
diff
changeset
|
1442 |
self initializeImageReaderMappings |
1729 | 1443 |
]. |
4074 | 1444 |
TypeToImageReaderClassMapping |
3870 | 1445 |
at:(MIMEType fromString:mimeTypeString asLowercase) |
1446 |
put:aReaderClass |
|
1729 | 1447 |
|
3870 | 1448 |
"Created: / 30-06-1997 / 21:56:11 / cg" |
1449 |
"Modified: / 01-08-1998 / 17:02:40 / cg" |
|
1450 |
"Modified: / 09-02-2017 / 15:32:58 / stefan" |
|
4074 | 1451 |
"Modified (comment): / 01-03-2018 / 18:58:27 / mawalch" |
1729 | 1452 |
! ! |
1453 |
||
1454 |
!MIMETypes class methodsFor:'queries-language syntax'! |
|
1455 |
||
4087 | 1456 |
commentStringsForFilename:aFilenameOrString |
1729 | 1457 |
"return a useful comment definition; heuristics for now. |
1458 |
The returned value is an array of 2 elements; |
|
1459 |
the first is the end-of-line comment string (or nil); |
|
1460 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
1461 |
||
4087 | 1462 |
|filename mime| |
1729 | 1463 |
|
4087 | 1464 |
filename := aFilenameOrString asFilename. |
1465 |
mime := MIMETypes mimeTypeForFilename:filename. |
|
1466 |
^ self commentStringsForMimeType:mime suffix:(filename suffix) |
|
1729 | 1467 |
|
1468 |
" |
|
1469 |
MIMETypes commentStringsForFilename:'Makefile'. |
|
4074 | 1470 |
MIMETypes commentStringsForFilename:'Object.st'. |
1471 |
MIMETypes commentStringsForFilename:'Foo.java'. |
|
1472 |
MIMETypes commentStringsForFilename:'Foo.html'. |
|
1729 | 1473 |
" |
1474 |
! |
|
1475 |
||
1476 |
commentStringsForFilename:aFilename ifUnknown:alternativeBlockReturningCommentString |
|
1477 |
"return a useful comment definition; heuristics for now. |
|
1478 |
The returned value is an array of 2 elements; |
|
1479 |
the first is the end-of-line comment string (or nil); |
|
1480 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
1481 |
||
1482 |
|mime| |
|
1483 |
||
1484 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
1485 |
^ self commentStringsForMimeType:mime suffix:(aFilename asFilename suffix) ifUnknown:alternativeBlockReturningCommentString |
|
1486 |
||
1487 |
" |
|
1488 |
MIMETypes commentStringsForFilename:'Makefile'. |
|
4074 | 1489 |
MIMETypes commentStringsForFilename:'Object.st'. |
1490 |
MIMETypes commentStringsForFilename:'Foo.java'. |
|
1729 | 1491 |
" |
1492 |
! |
|
1493 |
||
1494 |
commentStringsForMimeType:mime suffix:suff |
|
1495 |
"return a useful comment definition; heuristics for now. |
|
1496 |
The returned value is an array of 2 elements; |
|
1497 |
the first is the end-of-line comment string (or nil); |
|
1498 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
1499 |
||
1500 |
^ self |
|
4074 | 1501 |
commentStringsForMimeType:mime suffix:suff |
1502 |
ifUnknown: #(';' (nil nil)) |
|
1729 | 1503 |
|
1504 |
" |
|
1505 |
|mime| |
|
1506 |
||
1507 |
mime := MIMETypes mimeTypeForFilename:'Makefile'. |
|
4074 | 1508 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
1729 | 1509 |
" |
1510 |
||
1511 |
" |
|
1512 |
|mime| |
|
1513 |
||
1514 |
mime := MIMETypes mimeTypeForFilename:'Object.st'. |
|
4074 | 1515 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
1729 | 1516 |
" |
1517 |
! |
|
1518 |
||
1519 |
commentStringsForMimeType:mime suffix:suff ifUnknown:alternativeBlockReturningCommentString |
|
1520 |
"return a useful comment definition; heuristics for now. |
|
1521 |
The returned value is an array of 2 elements; |
|
1522 |
the first is the end-of-line comment string (or nil); |
|
1523 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
1524 |
||
1525 |
|commentSpec| |
|
1526 |
||
1527 |
commentSpec := TypeToCommentStringMapping at:mime ifAbsent:nil. |
|
1528 |
commentSpec notNil ifTrue:[ |
|
1529 |
^ commentSpec |
|
1530 |
]. |
|
3492 | 1531 |
suff notNil ifTrue:[ |
1532 |
commentSpec := SuffixToCommentStringMapping at:suff ifAbsent:nil. |
|
1533 |
commentSpec notNil ifTrue:[ |
|
1534 |
^ commentSpec |
|
1535 |
]. |
|
1729 | 1536 |
]. |
1537 |
^ alternativeBlockReturningCommentString value |
|
1538 |
||
1539 |
" |
|
1540 |
|mime| |
|
1541 |
||
1542 |
mime := MIMETypes mimeTypeForFilename:'Makefile'. |
|
4074 | 1543 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
1729 | 1544 |
" |
1545 |
||
1546 |
" |
|
1547 |
|mime| |
|
1548 |
||
1549 |
mime := MIMETypes mimeTypeForFilename:'Object.st'. |
|
4074 | 1550 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
1729 | 1551 |
" |
2298 | 1552 |
! |
1553 |
||
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
1554 |
parenthesisSpecForFilename:aFilename |
2298 | 1555 |
"return a useful parentesis spec; heuristics for now. |
1556 |
The returned value is a dictionary to be used as parentesis spec in an editor" |
|
1557 |
||
1558 |
|mime| |
|
1559 |
||
1560 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
1561 |
^ self parenthesisSpecForMimeType:mime suffix:(aFilename asFilename suffix) |
2298 | 1562 |
|
1563 |
" |
|
4074 | 1564 |
MIMETypes parenthesisSpecForFilename:'Object.st'. |
1565 |
MIMETypes parenthesisSpecForFilename:'Foo.java'. |
|
1566 |
MIMETypes parenthesisSpecForFilename:'Foo.html'. |
|
1567 |
MIMETypes parenthesisSpecForFilename:'Foo.lsp'. |
|
2298 | 1568 |
" |
1569 |
||
1570 |
"Created: / 10-04-2007 / 15:18:41 / cg" |
|
1571 |
! |
|
1572 |
||
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
1573 |
parenthesisSpecForFilename:aFilename ifUnknown:alternative |
2298 | 1574 |
|mime| |
1575 |
||
1576 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
1577 |
^ self parenthesisSpecForMimeType:mime suffix:(aFilename asFilename suffix) ifUnknown:alternative |
2298 | 1578 |
|
1579 |
"Created: / 10-04-2007 / 15:26:20 / cg" |
|
1580 |
! |
|
1581 |
||
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
1582 |
parenthesisSpecForMimeType:mime suffix:suff |
2298 | 1583 |
^ self |
4074 | 1584 |
parenthesisSpecForMimeType:mime suffix:suff |
1585 |
ifUnknown:nil |
|
2298 | 1586 |
|
1587 |
"Created: / 10-04-2007 / 15:19:39 / cg" |
|
4074 | 1588 |
"Modified (format): / 01-03-2018 / 19:03:58 / mawalch" |
2298 | 1589 |
! |
1590 |
||
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
1591 |
parenthesisSpecForMimeType:mime suffix:suff ifUnknown:alternativeValue |
2298 | 1592 |
|spec| |
1593 |
||
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
1594 |
spec := TypeToParenthesisSpecMapping at:mime ifAbsent:nil. |
2298 | 1595 |
spec notNil ifTrue:[ |
1596 |
^ spec |
|
1597 |
]. |
|
1598 |
||
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
1599 |
spec := SuffixToParenthesisSpecMapping at:suff ifAbsent:nil. |
2298 | 1600 |
spec notNil ifTrue:[ |
1601 |
^ spec |
|
1602 |
]. |
|
1603 |
||
1604 |
^ alternativeValue value |
|
1605 |
||
1606 |
"Created: / 10-04-2007 / 15:20:38 / cg" |
|
1729 | 1607 |
! ! |
1608 |
||
1612 | 1609 |
!MIMETypes::MIMEType class methodsFor:'documentation'! |
1610 |
||
1611 |
documentation |
|
1612 |
" |
|
1864 | 1613 |
like a string, but knows that it represents a mimeType. |
3359 | 1614 |
mimetypes are singletons, remembered in the class variable CachedTypes. |
1612 | 1615 |
" |
1616 |
! ! |
|
1617 |
||
1618 |
!MIMETypes::MIMEType class methodsFor:'instance creation'! |
|
1619 |
||
1620 |
fromString:aString |
|
1621 |
|cachedType newType| |
|
1622 |
||
1623 |
aString class == self ifTrue:[^ aString]. |
|
1624 |
||
3011
f2af94d78383
delay initialization of cachedTypes
Claus Gittinger <cg@exept.de>
parents:
3008
diff
changeset
|
1625 |
CachedTypes isNil ifTrue:[ |
3012 | 1626 |
CachedTypes := Dictionary new:100. |
3011
f2af94d78383
delay initialization of cachedTypes
Claus Gittinger <cg@exept.de>
parents:
3008
diff
changeset
|
1627 |
]. |
1612 | 1628 |
cachedType := CachedTypes at:aString ifAbsent:nil. |
1629 |
cachedType notNil ifTrue:[^ cachedType]. |
|
3011
f2af94d78383
delay initialization of cachedTypes
Claus Gittinger <cg@exept.de>
parents:
3008
diff
changeset
|
1630 |
|
1612 | 1631 |
newType := aString copy changeClassTo:self. |
1632 |
CachedTypes at:aString put:newType. |
|
1633 |
^ newType |
|
1634 |
||
1635 |
" |
|
3870 | 1636 |
CachedTypes := nil. |
1612 | 1637 |
self fromString:'text/html' |
1638 |
" |
|
3011
f2af94d78383
delay initialization of cachedTypes
Claus Gittinger <cg@exept.de>
parents:
3008
diff
changeset
|
1639 |
|
3012 | 1640 |
"Modified: / 20-07-2012 / 17:36:31 / cg" |
3870 | 1641 |
"Modified (comment): / 09-02-2017 / 15:36:06 / stefan" |
1612 | 1642 |
! ! |
1643 |
||
1644 |
!MIMETypes::MIMEType methodsFor:'queries'! |
|
1645 |
||
3359 | 1646 |
fileTypeInfo |
4074 | 1647 |
^ MIMETypes fileInfoForMimeType:self |
3359 | 1648 |
|
1649 |
" |
|
4074 | 1650 |
(MIMETypes mimeTypeFromString:'application/x-smalltalk-source') fileTypeInfo |
3359 | 1651 |
" |
4074 | 1652 |
|
1653 |
"Modified: / 01-03-2018 / 19:16:49 / mawalch" |
|
3359 | 1654 |
! |
1655 |
||
1693 | 1656 |
isArchive |
3260 | 1657 |
<resource: #obsolete> |
1658 |
"return true, if I represent an archive type (such as zip or tar)" |
|
1659 |
||
1660 |
^ self isArchiveType |
|
1661 |
! |
|
1662 |
||
1663 |
isArchiveType |
|
1864 | 1664 |
"return true, if I represent an archive type (such as zip or tar)" |
1665 |
||
1612 | 1666 |
|archivTypes| |
1667 |
||
1729 | 1668 |
archivTypes := MIMETypes applicationCompressorsAndArchiveTypeList. |
1612 | 1669 |
archivTypes pairWiseDo:[: ext : type | |
1670 |
self = type ifTrue:[ ^ true]. |
|
1671 |
]. |
|
1672 |
^ false |
|
1673 |
! |
|
1674 |
||
2024 | 1675 |
isBinary |
3260 | 1676 |
<resource: #obsolete> |
1677 |
"return true, if I represent a binary (non-text) type" |
|
1678 |
||
1679 |
^ self isBinaryType |
|
1680 |
! |
|
1681 |
||
1682 |
isBinaryType |
|
2024 | 1683 |
"return true, if I represent a binary (non-text) type" |
1684 |
||
1685 |
^ self isTextType not |
|
1686 |
! |
|
1687 |
||
1612 | 1688 |
isHtml |
3260 | 1689 |
<resource: #obsolete> |
1690 |
"return true, if I represent the html text type" |
|
1691 |
||
1692 |
^ self isHtmlType |
|
1693 |
! |
|
1694 |
||
1695 |
isHtmlType |
|
1864 | 1696 |
"return true, if I represent the html text type" |
1612 | 1697 |
|
1698 |
^ (self = 'text/html') |
|
1699 |
! |
|
1700 |
||
1701 |
isImage |
|
3260 | 1702 |
<resource: #obsolete> |
1703 |
"return true, if I represent an image type (such as gif or jpg)" |
|
1704 |
||
1705 |
^ self isImageType |
|
1706 |
! |
|
1707 |
||
1708 |
isImageType |
|
1864 | 1709 |
"return true, if I represent an image type (such as gif or jpg)" |
1612 | 1710 |
|
1693 | 1711 |
^ (self startsWith:'image/') |
1612 | 1712 |
! |
1713 |
||
1714 |
isPdf |
|
3260 | 1715 |
<resource: #obsolete> |
1716 |
"return true, if I represent the pdf type" |
|
1717 |
||
1718 |
^ self isPdfType |
|
1719 |
! |
|
1720 |
||
1721 |
isPdfType |
|
1864 | 1722 |
"return true, if I represent the pdf type" |
1723 |
||
1612 | 1724 |
^ (self = 'application/pdf') |
1725 |
! |
|
1726 |
||
1727 |
isSmalltalkSource |
|
3260 | 1728 |
<resource: #obsolete> |
1729 |
"return true, if I represent the smalltalk sourcecode type" |
|
1730 |
||
1731 |
^ self isSmalltalkSourceType |
|
1732 |
! |
|
1733 |
||
1734 |
isSmalltalkSourceType |
|
1864 | 1735 |
"return true, if I represent the smalltalk sourcecode type" |
1736 |
||
3359 | 1737 |
^ (self startsWith: 'application/x-smalltalk-source') |
1783 | 1738 |
! |
1739 |
||
2024 | 1740 |
isTextType |
1741 |
"return true, if I represent some text type" |
|
1742 |
||
1743 |
^ self startsWith:'text/' |
|
1744 |
! |
|
1745 |
||
1783 | 1746 |
isXml |
3260 | 1747 |
<resource: #obsolete> |
1748 |
"return true, if I represent the xml text type" |
|
1749 |
||
1750 |
^ self isXmlType |
|
1751 |
! |
|
1752 |
||
1753 |
isXmlType |
|
1864 | 1754 |
"return true, if I represent the xml text type" |
1755 |
||
3941 | 1756 |
^ self = 'text/xml' or:[self = 'application/xml'] |
1757 |
||
1758 |
"Modified (format): / 13-03-2017 / 09:41:52 / stefan" |
|
2490 | 1759 |
! |
1760 |
||
1761 |
suffix |
|
1762 |
^ MIMETypes suffixForMimeType:self |
|
1763 |
||
1764 |
" |
|
4074 | 1765 |
(MIMETypes mimeTypeFromString:'application/x-expecco-testsuite') suffix |
2490 | 1766 |
" |
643 | 1767 |
! ! |
1768 |
||
1769 |
!MIMETypes class methodsFor:'documentation'! |
|
1770 |
||
1771 |
version |
|
3482 | 1772 |
^ '$Header$' |
2758
66e62ceecb67
comment/format in: #defaultCommandForMimeType:
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
1773 |
! |
66e62ceecb67
comment/format in: #defaultCommandForMimeType:
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
1774 |
|
66e62ceecb67
comment/format in: #defaultCommandForMimeType:
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
1775 |
version_CVS |
3482 | 1776 |
^ '$Header$' |
643 | 1777 |
! ! |
1666 | 1778 |
|
3104 | 1779 |
|
643 | 1780 |
MIMETypes initialize! |