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