author | Claus Gittinger <cg@exept.de> |
Fri, 28 Jun 2019 08:48:50 +0200 | |
changeset 4282 | 22f5625bfa52 |
parent 4279 | 0c07b6f38d45 |
child 4388 | 20e3d76cf3aa |
permissions | -rw-r--r-- |
643 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
1612 | 3 |
All Rights Reserved |
643 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
1410 | 12 |
"{ Package: 'stx:libview2' }" |
13 |
||
3451 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
643 | 16 |
Object subclass:#MIMETypes |
1612 | 17 |
instanceVariableNames:'' |
3691 | 18 |
classVariableNames:'CharSetToFontMapping DefaultCommandPerMIMEPerOS |
19 |
DefaultPrintCommandPerMIMEPerOS |
|
20 |
FileSuffixToImageReaderClassMapping FileSuffixToTypeMapping |
|
21 |
FilenameToTypeMapping LastSuffix LastType |
|
22 |
SuffixToCommentStringMapping SuffixToParenthesisSpecMapping |
|
23 |
TypeFromContentsDetectors TypeToCommentStringMapping |
|
24 |
TypeToFileSuffixMapping TypeToImageReaderClassMapping |
|
25 |
TypeToInfoMapping TypeToParenthesisSpecMapping |
|
26 |
TypeToViewerApplicationMapping' |
|
1612 | 27 |
poolDictionaries:'' |
1800 | 28 |
category:'Net-Communication-Support' |
1612 | 29 |
! |
30 |
||
3359 | 31 |
ImmutableString variableByteSubclass:#MIMEType |
1612 | 32 |
instanceVariableNames:'' |
33 |
classVariableNames:'CachedTypes' |
|
34 |
poolDictionaries:'' |
|
35 |
privateIn:MIMETypes |
|
643 | 36 |
! |
37 |
||
38 |
!MIMETypes class methodsFor:'documentation'! |
|
39 |
||
40 |
copyright |
|
41 |
" |
|
42 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
1612 | 43 |
All Rights Reserved |
643 | 44 |
|
45 |
This software is furnished under a license and may be used |
|
46 |
only in accordance with the terms of that license and with the |
|
47 |
inclusion of the above copyright notice. This software may not |
|
48 |
be provided or otherwise made available to, or used by, any |
|
49 |
other person. No title to or ownership of the software is |
|
50 |
hereby transferred. |
|
51 |
||
52 |
||
53 |
" |
|
54 |
! |
|
55 |
||
56 |
documentation |
|
57 |
" |
|
58 |
just a place to keep MIME information |
|
59 |
(avoid spreading things at many places) |
|
60 |
||
1021 | 61 |
MIMETypes is abstract and functional. |
62 |
Actually, in some OperatingSystems, this information may |
|
63 |
be found in some config files (or registries). |
|
64 |
Therefore, this class may have to be extended to support this |
|
65 |
and fetch the information from there eventually. |
|
66 |
||
643 | 67 |
[author:] |
68 |
Claus Gittinger |
|
69 |
" |
|
1311 | 70 |
! |
71 |
||
2486
42063a7fc3db
mimeType: x-expecco-testSuite (extension: ets)
Claus Gittinger <cg@exept.de>
parents:
2479
diff
changeset
|
72 |
examples |
42063a7fc3db
mimeType: x-expecco-testSuite (extension: ets)
Claus Gittinger <cg@exept.de>
parents:
2479
diff
changeset
|
73 |
" |
2970
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
74 |
[exBegin] |
4074 | 75 |
MIMETypes mimeTypeFromString:'text/plain' |
3210 | 76 |
[exEnd] |
77 |
[exBegin] |
|
4074 | 78 |
MIMETypes mimeTypeFromString:'application/x-expecco-testsuite' |
2970
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
79 |
[exEnd] |
2486
42063a7fc3db
mimeType: x-expecco-testSuite (extension: ets)
Claus Gittinger <cg@exept.de>
parents:
2479
diff
changeset
|
80 |
|
2970
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
81 |
[exBegin] |
4074 | 82 |
MIMETypes mimeTypeForSuffix:'gif' |
2970
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
83 |
MIMETypes mimeTypeForSuffix:'ets' |
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
84 |
MIMETypes mimeTypeForSuffix:'xlsx' |
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
85 |
[exEnd] |
2486
42063a7fc3db
mimeType: x-expecco-testSuite (extension: ets)
Claus Gittinger <cg@exept.de>
parents:
2479
diff
changeset
|
86 |
" |
42063a7fc3db
mimeType: x-expecco-testSuite (extension: ets)
Claus Gittinger <cg@exept.de>
parents:
2479
diff
changeset
|
87 |
! |
42063a7fc3db
mimeType: x-expecco-testSuite (extension: ets)
Claus Gittinger <cg@exept.de>
parents:
2479
diff
changeset
|
88 |
|
1311 | 89 |
knownTypes |
90 |
" |
|
91 |
simply a reminder for me ... |
|
92 |
||
93 |
application mime file extentsions |
|
94 |
||
4074 | 95 |
powerpoint application/ms-powerpoint .pot, .ppz, .ppt, .pps, |
96 |
application/mspowerpoint |
|
97 |
application/vnd.ms-powerpoint |
|
1311 | 98 |
application/x-mspowerpoint |
99 |
||
4074 | 100 |
shockwave application/x-shockwave-flash .swf |
1311 | 101 |
|
1312 | 102 |
futuresplash application/futuresplash .spl |
1311 | 103 |
" |
643 | 104 |
! ! |
105 |
||
106 |
!MIMETypes class methodsFor:'initialization'! |
|
107 |
||
3691 | 108 |
addMimeTypeDetector:aMimeTypeFromContentsDetectorBlock |
109 |
"any class (especially: image readers) may add a block |
|
4074 | 110 |
that detects the MIME type from a given content. |
3691 | 111 |
The block is called with two arguments, some data (usually the first few kilobytes |
112 |
of a file) and the suffix of the file, or nil if unknown. |
|
4074 | 113 |
The block should return the MIME type or nil." |
114 |
||
115 |
TypeFromContentsDetectors isNil ifTrue:[ TypeFromContentsDetectors := OrderedCollection new ]. |
|
3691 | 116 |
TypeFromContentsDetectors add:aMimeTypeFromContentsDetectorBlock. |
4074 | 117 |
|
118 |
"Modified (comment): / 01-03-2018 / 19:06:46 / mawalch" |
|
3691 | 119 |
! |
120 |
||
1729 | 121 |
initialize |
122 |
"initialize wellKnown facts" |
|
4074 | 123 |
|
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
124 |
MIMEType initialize. "must be initialized first" |
1729 | 125 |
LastSuffix := LastType := nil. |
126 |
self initializeFileNameToMimeTypeMapping. |
|
127 |
self initializeImageReaderMappings. |
|
128 |
self initializeCommentStringMappings. |
|
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
129 |
self initializeParenthesisSpecMappings. |
4074 | 130 |
|
1729 | 131 |
" |
2970
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
132 |
self initialize |
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
133 |
" |
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
134 |
|
2298 | 135 |
"Modified: / 10-04-2007 / 15:16:44 / cg" |
2970
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
136 |
"Modified (comment): / 29-11-2011 / 19:11:51 / cg" |
1729 | 137 |
! |
138 |
||
139 |
initializeCommentStringMappings |
|
3359 | 140 |
"these are used by the editor's comment/uncomment functions" |
141 |
||
1729 | 142 |
TypeToCommentStringMapping := Dictionary new. |
143 |
SuffixToCommentStringMapping := Dictionary new. |
|
144 |
||
4074 | 145 |
TypeToCommentStringMapping |
1729 | 146 |
at:'application/x-make' |
3359 | 147 |
put:#('#' (nil nil)). "/ '#' EOL comments only |
1729 | 148 |
|
4074 | 149 |
TypeToCommentStringMapping |
1729 | 150 |
at:'application/x-sh' |
3359 | 151 |
put:#('#' (nil nil)). "/ '#' EOL comments only |
1729 | 152 |
|
4074 | 153 |
#('text/html' 'text/xml' |
154 |
'application/xml' |
|
2489
b891d96fd496
elf extension: x-expecco-logfile
Claus Gittinger <cg@exept.de>
parents:
2487
diff
changeset
|
155 |
'application/x-expecco-testsuite' |
b891d96fd496
elf extension: x-expecco-logfile
Claus Gittinger <cg@exept.de>
parents:
2487
diff
changeset
|
156 |
'application/x-expecco-logfile' |
b891d96fd496
elf extension: x-expecco-logfile
Claus Gittinger <cg@exept.de>
parents:
2487
diff
changeset
|
157 |
) |
1729 | 158 |
do:[:eachXMLType | |
4074 | 159 |
TypeToCommentStringMapping |
1729 | 160 |
at:eachXMLType |
161 |
put:#(nil ('<!!-- ' ' -->')). "/ '<!!-- ... -->' delimited comments only |
|
162 |
]. |
|
163 |
||
4074 | 164 |
TypeToCommentStringMapping |
2055 | 165 |
at:'text/css' |
4074 | 166 |
put:#('//' ('/*' '*/')). |
2055 | 167 |
|
4074 | 168 |
TypeToCommentStringMapping |
1729 | 169 |
at:'application/x-batch-script' |
2937
67ef44218dc0
changed: #initializeCommentStringMappings
Claus Gittinger <cg@exept.de>
parents:
2924
diff
changeset
|
170 |
put:#('@REM ' '@rem ' 'REM ' 'rem ' (nil nil)). "/ 'rem ' for EOL comments only |
1729 | 171 |
|
172 |
"/ the following is ST/X specific |
|
4074 | 173 |
TypeToCommentStringMapping |
1729 | 174 |
at:'application/x-smalltalk-source' |
175 |
put:#('"/' ('"' '"')). "/ '"/ ' for EOL; ".." for delimited comments |
|
176 |
||
177 |
"/ this is for standard smalltalk |
|
4074 | 178 |
"/ TypeToCommentStringMapping |
1729 | 179 |
"/ at:'application/x-smalltalk-source' |
180 |
"/ put:#(nil ('"' '"')). "/ ".." for delimited comments only |
|
181 |
||
182 |
||
4074 | 183 |
TypeToCommentStringMapping |
1729 | 184 |
at:'application/x-pascal-source' |
185 |
put:#(nil ('{' '}')). "/ '{'..'}' for delimited comments |
|
186 |
||
187 |
"/ this is ANSI-c |
|
4074 | 188 |
TypeToCommentStringMapping |
1729 | 189 |
at:'application/x-c-source' |
4074 | 190 |
put:#('//' ('/*' '*/')). |
1729 | 191 |
|
4074 | 192 |
TypeToCommentStringMapping |
1729 | 193 |
at:'application/x-cpp-source' |
4074 | 194 |
put:#('//' ('/*' '*/')). |
1729 | 195 |
|
4074 | 196 |
TypeToCommentStringMapping |
2479 | 197 |
at:'application/x-csharp-source' |
4074 | 198 |
put:#('//' ('/*' '*/')). |
2479 | 199 |
|
4074 | 200 |
TypeToCommentStringMapping |
1729 | 201 |
at:'application/x-java-source' |
4074 | 202 |
put:#('//' ('/*' '*/')). |
1729 | 203 |
|
4074 | 204 |
TypeToCommentStringMapping |
2048
dbb361dd9c5f
comment strings for javascript files
Claus Gittinger <cg@exept.de>
parents:
2028
diff
changeset
|
205 |
at:'application/x-javascript' |
4074 | 206 |
put:#('//' ('/*' '*/')). |
2048
dbb361dd9c5f
comment strings for javascript files
Claus Gittinger <cg@exept.de>
parents:
2028
diff
changeset
|
207 |
|
4074 | 208 |
TypeToCommentStringMapping |
4043 | 209 |
at:'application/x-scheme-source' |
210 |
put:#(';' ('#| ' ' |#')). "/ ';' for EOL comments only |
|
211 |
||
4074 | 212 |
TypeToCommentStringMapping |
2298 | 213 |
at:'application/x-lisp-source' |
3482 | 214 |
put:#(';' (nil nil)). "/ ';' for EOL comments only |
215 |
||
4074 | 216 |
TypeToCommentStringMapping |
3482 | 217 |
at:'application/x-python-source' |
218 |
put:#('#' (nil nil)). "/ '#' for EOL comments only |
|
2298 | 219 |
|
4074 | 220 |
TypeToCommentStringMapping |
1729 | 221 |
at:'application/x-asn1-source' |
4074 | 222 |
put:#('--' ('--' '--')). |
1729 | 223 |
|
224 |
||
225 |
"/ st/x support files |
|
4074 | 226 |
SuffixToCommentStringMapping |
1729 | 227 |
at:'style' |
4074 | 228 |
put:#(';' (nil nil)). |
1604 | 229 |
|
4074 | 230 |
SuffixToCommentStringMapping |
1729 | 231 |
at:'rs' |
2298 | 232 |
put:#(';' (nil nil)). |
233 |
||
2937
67ef44218dc0
changed: #initializeCommentStringMappings
Claus Gittinger <cg@exept.de>
parents:
2924
diff
changeset
|
234 |
"Modified: / 06-09-2011 / 10:46:27 / cg" |
1729 | 235 |
! |
236 |
||
237 |
initializeDefaultCommands |
|
3359 | 238 |
"these are used to select an application to be opened when a file of a particular |
239 |
type is double clicked in the browser. |
|
240 |
TODO: move this to OS" |
|
1729 | 241 |
|
3253 | 242 |
|unixCommands win32Commands unixPrintCommands win32PrintCommands listToTry| |
1729 | 243 |
|
244 |
DefaultCommandPerMIMEPerOS := Dictionary new. |
|
245 |
DefaultCommandPerMIMEPerOS at:#unix put:(unixCommands := Dictionary new). |
|
246 |
DefaultCommandPerMIMEPerOS at:#win32 put:(win32Commands := Dictionary new). |
|
247 |
||
3187 | 248 |
unixCommands at:'application/x-tar-compressed' put:'tar tvf -'. |
1729 | 249 |
|
2141 | 250 |
OperatingSystem isMSWINDOWSlike ifFalse:[ |cmd| |
3253 | 251 |
OperatingSystem isOSXlike ifTrue:[ |
4219 | 252 |
"/ unixCommands at:'text/html' put:('open -a Safari "%1"'). |
253 |
unixCommands at:'text/html' put:('open -a Firefox "%1"'). |
|
4074 | 254 |
unixCommands at:'application/pdf' put:('open -a Preview "%1"'). |
3253 | 255 |
] ifFalse:[ |
3322 | 256 |
listToTry := #('firefox' 'chrome' 'chromium' 'konqueror' 'opera'). |
257 |
cmd := listToTry |
|
258 |
detect:[:aCmd| (OperatingSystem pathOfCommand:aCmd) notEmptyOrNil ] |
|
259 |
ifNone:nil. |
|
260 |
cmd notNil ifTrue:[ |
|
4074 | 261 |
unixCommands at:'text/html' put:(cmd, ' "%1"') |
3322 | 262 |
]. |
3187 | 263 |
|
3322 | 264 |
listToTry := #('acroread' 'okular' 'evince' 'kpdf' 'xpdf'). |
265 |
cmd := listToTry |
|
266 |
detect:[:aCmd| (OperatingSystem pathOfCommand:aCmd) notEmptyOrNil ] |
|
267 |
ifNone:nil. |
|
268 |
cmd notNil ifTrue:[ |
|
4074 | 269 |
unixCommands at:'application/pdf' put:(cmd, ' "%1"') |
3322 | 270 |
]. |
4073 | 271 |
|
272 |
listToTry := #('xdg-open'). |
|
273 |
cmd := listToTry |
|
274 |
detect:[:aCmd| (OperatingSystem pathOfCommand:aCmd) notEmptyOrNil ] |
|
275 |
ifNone:nil. |
|
276 |
cmd notNil ifTrue:[ |
|
4074 | 277 |
unixCommands at:'text/plain' put:(cmd , ' "%1"') |
4073 | 278 |
]. |
279 |
||
3187 | 280 |
]. |
2141 | 281 |
]. |
282 |
||
283 |
||
2116 | 284 |
DefaultPrintCommandPerMIMEPerOS := Dictionary new. |
285 |
DefaultPrintCommandPerMIMEPerOS at:#unix put:(unixPrintCommands := Dictionary new). |
|
286 |
DefaultPrintCommandPerMIMEPerOS at:#win32 put:(win32PrintCommands := Dictionary new). |
|
287 |
||
288 |
"/ if you have a good (intelligent) spooler ;-) |
|
2904
bb555534881e
changed: #initializeDefaultCommands
Stefan Vogel <sv@exept.de>
parents:
2892
diff
changeset
|
289 |
unixPrintCommands at:'application/pdf' put:'lpr "%1"'. |
2116 | 290 |
"/ if not, you may need more... |
291 |
"/ unixPrintCommands at:'application/pdf' put:'pdfToPS %1 | lpr'. |
|
292 |
||
1729 | 293 |
" |
294 |
self initializeDefaultCommands |
|
295 |
" |
|
1979
0612875a95c1
acroread command from registry (win32)
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
296 |
|
0612875a95c1
acroread command from registry (win32)
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
297 |
"Modified: / 12-05-2004 / 11:43:23 / cg" |
4073 | 298 |
"Modified: / 01-03-2018 / 18:42:42 / mawalch" |
4219 | 299 |
"Modified: / 07-02-2019 / 17:53:24 / Claus Gittinger" |
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' |
|
4179 | 673 |
'cbl' 'application/x-cobol-source' |
1604 | 674 |
) |
2298 | 675 |
|
3961 | 676 |
"Modified: / 23-06-2017 / 13:34:37 / cg" |
4074 | 677 |
"Modified (comment): / 01-03-2018 / 19:07:43 / mawalch" |
4179 | 678 |
"Modified: / 18-09-2018 / 21:07:27 / Claus Gittinger" |
1604 | 679 |
! |
1561 | 680 |
|
1604 | 681 |
applicationTextTypeList |
1606 | 682 |
"text applications" |
1604 | 683 |
|
684 |
^ #( |
|
4074 | 685 |
"/ the first column is a list of extensions, the second the more-or-less official MIME type |
3862 | 686 |
|
1604 | 687 |
('ps' 'eps') 'application/postscript' |
1778 | 688 |
"/ 'ai' 'application/postscript' |
1604 | 689 |
'pdf' 'application/pdf' |
690 |
'rtf' 'application/rtf' |
|
1778 | 691 |
"/ 'rtf' 'text/rtf' ???? |
3008 | 692 |
'ics' 'text/calendar' |
693 |
'doc' 'application/ms-word-document' |
|
1778 | 694 |
"/ 'doc' 'application/winword' |
695 |
'swf' 'application/x-shockwave-flash' |
|
696 |
('ppt' 'ppz' 'pot' 'pps') 'application/mspowerpoint' |
|
4074 | 697 |
'xls' 'application/x-excel' |
2028 | 698 |
'slk' 'application/vnd.ms-excel' |
2911
7afaf1fdae8b
comment/format in: #mimeTypeForFilename:
Claus Gittinger <cg@exept.de>
parents:
2904
diff
changeset
|
699 |
'txt' 'text/plain' |
2970
8b91ec204044
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
2968
diff
changeset
|
700 |
'xlsx' 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' |
3476 | 701 |
'xltx' 'application/vnd.openxmlformats-officedocument.spreadsheetml.template' |
702 |
'potx' 'application/vnd.openxmlformats-officedocument.presentationml.template' |
|
703 |
'ppsx' 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' |
|
704 |
'pptx' 'application/vnd.openxmlformats-officedocument.presentationml.presentation' |
|
705 |
'sldx' 'application/vnd.openxmlformats-officedocument.presentationml.slide' |
|
706 |
'docx' 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' |
|
707 |
'dotx' 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' |
|
708 |
'xlam' 'application/vnd.ms-excel.addin.macroEnabled.12' |
|
709 |
'xlsb' 'application/vnd.ms-excel.sheet.binary.macroEnabled.12' |
|
4279 | 710 |
'chm' 'application/vnd.ms-htmlhelp' |
3952 | 711 |
'xhtml' 'application/xhtml+xml' |
3482 | 712 |
|
713 |
'edi' 'application/EDIFACT' |
|
4136 | 714 |
'json' 'application/json' |
1604 | 715 |
) |
2911
7afaf1fdae8b
comment/format in: #mimeTypeForFilename:
Claus Gittinger <cg@exept.de>
parents:
2904
diff
changeset
|
716 |
|
3008 | 717 |
"Modified: / 26-05-2012 / 15:27:30 / cg" |
3476 | 718 |
"Modified: / 18-05-2015 / 09:46:47 / sr" |
3862 | 719 |
"Modified (format): / 05-02-2017 / 19:37:20 / cg" |
4074 | 720 |
"Modified (comment): / 01-03-2018 / 19:07:51 / mawalch" |
4279 | 721 |
"Modified: / 27-06-2019 / 16:31:45 / Claus Gittinger" |
1604 | 722 |
! |
723 |
||
724 |
applicationTypeList |
|
1606 | 725 |
"applications" |
1604 | 726 |
|
4074 | 727 |
|typeList| |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
728 |
|
1729 | 729 |
typeList := OrderedCollection new. |
730 |
typeList addAll:self applicationProgLangTypeList. |
|
731 |
typeList addAll:self applicationTextTypeList. |
|
732 |
typeList addAll:self applicationCompressorsAndArchiveTypeList. |
|
733 |
typeList addAll:self applicationMiscTypeList. |
|
1616 | 734 |
|
1729 | 735 |
^ typeList |
1604 | 736 |
! |
737 |
||
738 |
audioTypeList |
|
1606 | 739 |
"audio formats ..." |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
740 |
|
1604 | 741 |
^ #( |
4074 | 742 |
"/ the first column is a list of extensions, the second the more-or-less official MIME type |
3862 | 743 |
|
1720 | 744 |
('au' 'snd') 'audio/basic' |
3870 | 745 |
'ra' 'audio/x-realaudio' |
1778 | 746 |
('ram' 'rm') 'audio/x-pn-realaudio' |
3862 | 747 |
"/ cg: see unixSpecific / windowsSpecific |
748 |
"/ 'rpm' 'audio/x-pn-realaudio-plugin' |
|
3008 | 749 |
('mpa' 'mpega' 'mpga') 'audio/mpeg' |
3862 | 750 |
"/ 'mp3' 'audio/x-mp3' |
1778 | 751 |
('mp3' 'mp2') 'audio/mpeg' |
1604 | 752 |
'wav' 'audio/x-wav' |
753 |
('aif' 'aiff' 'aifc') 'audio/x-aiff' |
|
1778 | 754 |
('midi' 'mid') 'audio/midi' |
1604 | 755 |
) |
3008 | 756 |
|
757 |
"Modified: / 26-05-2012 / 15:23:45 / cg" |
|
3862 | 758 |
"Modified (comment): / 05-02-2017 / 19:37:48 / cg" |
3870 | 759 |
"Modified: / 09-02-2017 / 14:29:59 / stefan" |
4074 | 760 |
"Modified (comment): / 01-03-2018 / 19:07:54 / mawalch" |
1604 | 761 |
! |
762 |
||
763 |
imageTypeList |
|
4013 | 764 |
"/ wellknown image formats ... |
1604 | 765 |
|
766 |
^ #( |
|
4074 | 767 |
"/ the first column is a list of extensions, the second the more-or-less official MIME type |
768 |
||
1216 | 769 |
('jpg' 'jpeg') 'image/jpeg' |
1188 | 770 |
'gif' 'image/gif' |
771 |
('tif' 'tiff') 'image/tiff' |
|
3295 | 772 |
('xbm' 'bm') 'image/x-xbitmap' |
1188 | 773 |
'xpm' 'image/x-xpixmap' |
1720 | 774 |
'png' 'image/png' |
1188 | 775 |
'pcd' 'image/x-photo-cd' |
776 |
'bmp' 'image/x-MS-bmp' |
|
777 |
'rgb' 'image/x-rgb' |
|
778 |
'ppm' 'image/x-portable-pixmap' |
|
779 |
'pgm' 'image/x-portable-graymap' |
|
780 |
'pbm' 'image/x-portable-bitmap' |
|
781 |
'pnm' 'image/x-portable-anymap' |
|
782 |
'xwd' 'image/x-xwindowdump' |
|
783 |
'ras' 'image/x-cmu-raster' |
|
1216 | 784 |
'tga' 'image/x-targa' |
4013 | 785 |
'ico' 'image/x-icon' |
4074 | 786 |
'icns' 'image/icns' |
3978 | 787 |
'dng' 'image/x-adobe-dng' |
3862 | 788 |
) |
789 |
||
4013 | 790 |
"Modified: / 13-09-2017 / 09:05:15 / cg" |
4074 | 791 |
"Modified (comment): / 01-03-2018 / 19:08:18 / mawalch" |
1604 | 792 |
! |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
793 |
|
1609 | 794 |
miscFilenameList |
3104 | 795 |
"other formats (not by suffix, but by fileName instead) ..." |
1609 | 796 |
|
797 |
^ #( |
|
4074 | 798 |
"/ the first column is a list of extensions, the second the more-or-less official MIME type |
3862 | 799 |
|
2113 | 800 |
('makefile' 'make.proto' 'make.spec' 'nt.mak') 'application/x-make' |
4146 | 801 |
('exe' 'bin' 'com') 'vnd.microsoft.portable-executable' |
2113 | 802 |
('class') 'application/octet-stream' |
2375 | 803 |
('top') 'application/x-waltop-digital-notepad' |
1609 | 804 |
) |
3862 | 805 |
|
806 |
"Modified (comment): / 05-02-2017 / 19:38:00 / cg" |
|
4074 | 807 |
"Modified (comment): / 01-03-2018 / 19:09:17 / mawalch" |
4146 | 808 |
"Modified: / 09-07-2018 / 10:53:43 / Stefan Vogel" |
1609 | 809 |
! |
810 |
||
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
811 |
osSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
812 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
813 |
^ self windowsSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
814 |
]. |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
815 |
^ self unixSpecificTypeList |
2023 | 816 |
|
817 |
" |
|
818 |
self osSpecificTypeList |
|
819 |
" |
|
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
820 |
! |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
821 |
|
1604 | 822 |
textTypeList |
823 |
"/ misc text ... |
|
824 |
||
825 |
^ #( |
|
4074 | 826 |
"/ the first column is a list of extensions, the second the more-or-less official MIME type |
3862 | 827 |
|
1887 | 828 |
('html' 'htm' 'shtml') 'text/html' |
1604 | 829 |
('txt' 'text') 'text/plain' |
1680 | 830 |
'xml' 'text/xml' |
3862 | 831 |
'fxml' 'text/xml' |
3517 | 832 |
'xsd' 'text/xml' |
1777 | 833 |
'css' 'text/css' |
2432 | 834 |
'csv' 'text/csv' |
1604 | 835 |
) |
3862 | 836 |
|
837 |
"Modified: / 05-02-2017 / 19:38:12 / cg" |
|
4074 | 838 |
"Modified (comment): / 01-03-2018 / 19:09:34 / mawalch" |
1604 | 839 |
! |
840 |
||
1888
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
841 |
unixSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
842 |
|
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
843 |
^ #( |
4074 | 844 |
"/ the first column is a list of extensions, the second the more-or-less official MIME type |
3862 | 845 |
|
846 |
"/ cg: RPM is 'audio/x-pn-realaudio-plugin' for WIN32 |
|
847 |
"/ 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
|
848 |
'rpm' 'application/x-rpm' |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
849 |
) |
3862 | 850 |
|
851 |
"Modified (comment): / 05-02-2017 / 19:38:23 / cg" |
|
4074 | 852 |
"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
|
853 |
! |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
854 |
|
1604 | 855 |
videoTypeList |
856 |
"/ video formats ... |
|
857 |
||
858 |
^ #( |
|
3862 | 859 |
"/ the first column is a list of extensions, the second the more-or-less official mimetype |
860 |
||
1720 | 861 |
('qt' 'mov' 'moov') 'video/quicktime' |
862 |
('mpv' 'mpegv' 'mpg' 'mpeg' 'mpe') 'video/mpeg' |
|
1604 | 863 |
'movie' 'video/x-sgi-movie' |
1820 | 864 |
('avi' 'wmv' 'asf') 'video/x-msvideo' |
1604 | 865 |
('mpv2' 'mp2v' 'mp2' 'mpeg2') 'video/x-mpeg2' |
3367 | 866 |
('mp4') 'video/mp4' |
1680 | 867 |
'rm' 'application/vnd.rn-realmedia' |
868 |
'rv' 'video/x-pn-realvideo' |
|
3295 | 869 |
'fli' 'video/x-fli' |
3367 | 870 |
'flv' 'video/x-flv' "/ macromedia flash video |
1778 | 871 |
) |
3862 | 872 |
|
873 |
"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
|
874 |
! |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
875 |
|
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
876 |
windowsSpecificTypeList |
ef0f346b8f43
rpm suffix is RPM-package under unix (realplayer under windows)
Claus Gittinger <cg@exept.de>
parents:
1887
diff
changeset
|
877 |
^ #( |
4074 | 878 |
"/ the first column is a list of extensions, the second the more-or-less official MIME type |
3862 | 879 |
|
880 |
"/ cg: RPM is 'audio/x-pn-realaudio-plugin' for WIN32 |
|
881 |
"/ 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
|
882 |
'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
|
883 |
) |
3862 | 884 |
|
885 |
"Modified (comment): / 05-02-2017 / 19:38:42 / cg" |
|
4074 | 886 |
"Modified (comment): / 01-03-2018 / 19:09:41 / mawalch" |
643 | 887 |
! ! |
888 |
||
1729 | 889 |
!MIMETypes class methodsFor:'obsolete'! |
1489 | 890 |
|
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
891 |
defaultCommandForMimeType:mimeType |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
892 |
<resource: #obsolete> |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
893 |
self obsoleteMethodWarning:'use #defaultCommandTemplateToOpenMimeType:'. |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
894 |
|
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
895 |
^ self defaultCommandTemplateToOpenMimeType:mimeType |
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 |
" |
4074 | 898 |
MIMETypes defaultCommandTemplateToOpenMimeType:'application/pdf' |
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
899 |
" |
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 |
"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
|
902 |
"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
|
903 |
! |
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
904 |
|
1729 | 905 |
fontForCharset:aCharSetName |
906 |
"return the font-encoding for an iso-charset" |
|
1489 | 907 |
|
1981 | 908 |
<resource:#obsolete> |
1729 | 909 |
self obsoleteMethodWarning:'use FontDescription >> fontNamePatternForCharset:'. |
910 |
^ FontDescription fontNamePatternForCharset:aCharSetName. |
|
1489 | 911 |
|
912 |
" |
|
4074 | 913 |
MIMETypes fontForCharset:'iso2022-jp' |
914 |
MIMETypes fontForCharset:'euc-jp' |
|
1472 | 915 |
" |
916 |
||
1729 | 917 |
"Modified: / 1.8.1998 / 17:00:57 / cg" |
918 |
! ! |
|
1472 | 919 |
|
1729 | 920 |
!MIMETypes class methodsFor:'queries'! |
1472 | 921 |
|
647 | 922 |
defineImageType:mimeType suffix:aSuffix reader:aReaderClass |
923 |
"register an image reader." |
|
924 |
||
3981 | 925 |
self defineImageType:mimeType suffix:aSuffix reader:aReaderClass info:nil |
926 |
||
927 |
"Modified: / 26-08-2017 / 10:30:00 / cg" |
|
928 |
! |
|
929 |
||
930 |
defineImageType:mimeType suffix:aSuffix reader:aReaderClass info:info |
|
931 |
"register an image reader." |
|
932 |
||
4080 | 933 |
"/ flush caches |
934 |
LastSuffix := LastType := nil. |
|
935 |
||
647 | 936 |
aSuffix notNil ifTrue:[ |
937 |
self imageReaderForSuffix:aSuffix put:aReaderClass. |
|
938 |
]. |
|
939 |
||
940 |
mimeType notNil ifTrue:[ |
|
941 |
self imageReaderForType:mimeType put:aReaderClass |
|
942 |
]. |
|
943 |
||
944 |
(aSuffix notNil and:[mimeType notNil]) ifTrue:[ |
|
945 |
self mimeTypeForSuffix:aSuffix put:mimeType |
|
946 |
]. |
|
4074 | 947 |
|
3981 | 948 |
(info notNil and:[mimeType notNil]) ifTrue:[ |
3982 | 949 |
self typeToInfoMapping at:mimeType put:info. |
3981 | 950 |
]. |
951 |
||
952 |
"Created: / 26-08-2017 / 10:29:11 / cg" |
|
3982 | 953 |
"Modified: / 27-08-2017 / 14:30:53 / cg" |
647 | 954 |
! |
955 |
||
3359 | 956 |
fileInfoForMimeType:mimeType |
957 |
"given a mimeType, return an info string similar to what the unix 'file' command |
|
958 |
provides. This info here is returned by systems which have no file (i.e. MSDOS) and |
|
959 |
for types of which file does not know about (smalltalk files, for example)" |
|
960 |
||
3982 | 961 |
^ self typeToInfoMapping at:mimeType ifAbsent:nil |
3359 | 962 |
|
963 |
" |
|
4074 | 964 |
self fileInfoForMimeType:(MIMEType fromString:'text/html') |
965 |
self fileInfoForMimeType:(MIMEType fromString:'image/gif') |
|
3359 | 966 |
" |
3982 | 967 |
|
968 |
"Modified (comment): / 27-08-2017 / 14:31:33 / cg" |
|
3359 | 969 |
! |
970 |
||
643 | 971 |
fileSuffixToImageReaderMapping |
1021 | 972 |
"return the suffix-to-imageReader mapping" |
973 |
||
643 | 974 |
^ FileSuffixToImageReaderClassMapping ? #() |
975 |
||
1021 | 976 |
"Modified: / 1.8.1998 / 17:00:11 / cg" |
643 | 977 |
! |
978 |
||
979 |
imageFileSuffixes |
|
1021 | 980 |
"return a collection with known file suffixes" |
981 |
||
643 | 982 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[^ #()]. |
983 |
^ FileSuffixToImageReaderClassMapping keys |
|
984 |
||
1021 | 985 |
"Created: / 30.6.1997 / 22:04:48 / cg" |
986 |
"Modified: / 1.8.1998 / 17:01:26 / cg" |
|
643 | 987 |
! |
988 |
||
3014
e6d9a204da08
comment/format in: #mimeTypeForFilename:
Claus Gittinger <cg@exept.de>
parents:
3012
diff
changeset
|
989 |
mimeTypeForFilename:filenameOrString |
4074 | 990 |
"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
|
991 |
|
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
992 |
|type filename lcFilename suff suff2| |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
993 |
|
3014
e6d9a204da08
comment/format in: #mimeTypeForFilename:
Claus Gittinger <cg@exept.de>
parents:
3012
diff
changeset
|
994 |
filename := filenameOrString asFilename. |
1474 | 995 |
|
996 |
lcFilename := filename baseName asLowercase. |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
997 |
type := FilenameToTypeMapping at:lcFilename ifAbsent:nil. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
998 |
type isNil ifTrue:[ |
3962 | 999 |
"/ 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
|
1000 |
type := OperatingSystem mimeTypeForFilename:lcFilename. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1001 |
"/ 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
|
1002 |
"/ 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
|
1003 |
"/ the OS. |
1275 | 1004 |
"/ type isNil ifTrue:[ |
1005 |
"/ FilenameToTypeMapping at:lcFilename put:#unknown |
|
1006 |
"/ ]. |
|
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1007 |
]. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1008 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1009 |
type == #unknown ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1010 |
type := nil. |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1011 |
]. |
1273
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
1012 |
|
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
1013 |
type isNil ifTrue:[ |
1473 | 1014 |
suff := filename suffix. |
3962 | 1015 |
suff notEmpty ifTrue:[ |
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1016 |
"/ sigh - special code for multiple-suffices... |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1017 |
"/ .tar.gz -> tgz |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1018 |
suff2 := filename withoutSuffix suffix. |
3962 | 1019 |
suff2 notEmpty ifTrue:[ |
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1020 |
type := self mimeTypeForSuffix:(suff2 , '.' , suff). |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1021 |
]. |
3983 | 1022 |
(type isNil or:[type == #unknown]) ifTrue:[ |
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1023 |
type := self mimeTypeForSuffix:suff |
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1024 |
]. |
1273
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
1025 |
] |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
1026 |
]. |
7a52d4bcdb10
filenames mime query falls back to suffix query.
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
1027 |
|
3871 | 1028 |
type == #unknown ifTrue:[ |
1029 |
type := nil. |
|
1030 |
]. |
|
1031 |
||
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1032 |
^ type |
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1033 |
|
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1034 |
" |
4074 | 1035 |
MIMETypes mimeTypeForFilename:'typeinst.dvi' |
2820 | 1036 |
MIMETypes mimeTypeForFilename:'foo.tar' |
1037 |
MIMETypes mimeTypeForFilename:'foo.tgz' |
|
1038 |
MIMETypes mimeTypeForFilename:'foo.tar.gz' |
|
4074 | 1039 |
MIMETypes mimeTypeForFilename:'foo.txt' |
1040 |
MIMETypes mimeTypeForFilename:'foo.pkg' |
|
1041 |
MIMETypes mimeTypeForFilename:'foo.sm' |
|
4179 | 1042 |
MIMETypes mimeTypeForFilename:'foo.cbl' |
3983 | 1043 |
MIMETypes mimeTypeForFilename:'/Users/cg/work/stx/goodies/bitmaps/tiffimages/moreSamples/multi-channel.ome.tif' |
1044 |
MIMETypes mimeTypeForFilename:'multi-channel.ome.tif' |
|
1045 |
MIMETypes mimeTypeForFilename:'multi-channel.tif' |
|
1780
ba94d562efe8
support double-suffix such as '.tar.gz'
Claus Gittinger <cg@exept.de>
parents:
1779
diff
changeset
|
1046 |
" |
2911
7afaf1fdae8b
comment/format in: #mimeTypeForFilename:
Claus Gittinger <cg@exept.de>
parents:
2904
diff
changeset
|
1047 |
|
3962 | 1048 |
"Modified (format): / 27-06-2017 / 16:25:40 / stefan" |
3983 | 1049 |
"Modified: / 27-08-2017 / 16:35:37 / cg" |
4074 | 1050 |
"Modified (comment): / 01-03-2018 / 18:52:25 / mawalch" |
4179 | 1051 |
"Modified (comment): / 18-09-2018 / 21:10:13 / Claus Gittinger" |
1272
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1052 |
! |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1053 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1054 |
mimeTypeForFilename:filename put:mimeType |
4074 | 1055 |
"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
|
1056 |
|
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1057 |
FilenameToTypeMapping isNil ifTrue:[ |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1058 |
FilenameToTypeMapping := Dictionary new |
91ba4078b690
additional mime table for filenames without suffix.
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
1059 |
]. |
1612 | 1060 |
FilenameToTypeMapping at:filename put:(MIMEType fromString:mimeType asLowercase) |
4074 | 1061 |
|
1062 |
"Modified (comment): / 01-03-2018 / 18:52:42 / mawalch" |
|
1611 | 1063 |
! |
1064 |
||
643 | 1065 |
mimeTypeForSuffix:suffix |
4074 | 1066 |
"given a file suffix, return the MIME type" |
1021 | 1067 |
|
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
1068 |
|type lcSuffix| |
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
1069 |
|
1837 | 1070 |
suffix = LastSuffix ifTrue:[ |
1071 |
^ LastType |
|
1072 |
]. |
|
1073 |
||
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
1074 |
lcSuffix := suffix asLowercase. |
1837 | 1075 |
type := FileSuffixToTypeMapping at:lcSuffix ifAbsent:nil. |
1076 |
type isNil ifTrue:[ |
|
1077 |
"/ allow for fallback ... |
|
1078 |
type := OperatingSystem mimeTypeForSuffix:lcSuffix. |
|
1079 |
"/ the special value #unknown is returned as nil; |
|
4074 | 1080 |
"/ this avoids constant retry if a suffix is not known in the OS. |
3870 | 1081 |
type := type isNil ifTrue:[#unknown] ifFalse:[MIMEType fromString:type]. |
1837 | 1082 |
FileSuffixToTypeMapping at:lcSuffix put:type. |
1180
c3309b30d14f
code cleanup & added mimeType aquire fallBack via OS
Claus Gittinger <cg@exept.de>
parents:
1023
diff
changeset
|
1083 |
]. |
1837 | 1084 |
|
3870 | 1085 |
LastSuffix := suffix. |
1086 |
LastType := type. |
|
1841 | 1087 |
^ type |
643 | 1088 |
|
1666 | 1089 |
" |
4074 | 1090 |
self mimeTypeForSuffix:'gif' |
1091 |
self mimeTypeForSuffix:'rpm' |
|
1092 |
self mimeTypeForSuffix:'zip' |
|
1666 | 1093 |
" |
1094 |
||
2891 | 1095 |
"Created: / 30-06-1997 / 21:55:51 / cg" |
1096 |
"Modified: / 14-02-2011 / 17:14:34 / cg" |
|
3870 | 1097 |
"Modified: / 09-02-2017 / 14:57:52 / stefan" |
4074 | 1098 |
"Modified (comment): / 01-03-2018 / 18:51:35 / mawalch" |
643 | 1099 |
! |
1100 |
||
1101 |
mimeTypeForSuffix:suffix put:mimeType |
|
4074 | 1102 |
"register a MIME type for a file suffix" |
1021 | 1103 |
|
643 | 1104 |
FileSuffixToTypeMapping isNil ifTrue:[ |
1105 |
FileSuffixToTypeMapping := Dictionary new |
|
1106 |
]. |
|
3870 | 1107 |
FileSuffixToTypeMapping at:suffix ifAbsentPut:[MIMEType fromString:mimeType asLowercase]. |
643 | 1108 |
|
3870 | 1109 |
"Created: / 30-06-1997 / 21:56:20 / cg" |
1110 |
"Modified: / 01-08-1998 / 17:03:18 / cg" |
|
1111 |
"Modified: / 09-02-2017 / 15:09:17 / stefan" |
|
4074 | 1112 |
"Modified (comment): / 01-03-2018 / 18:51:17 / mawalch" |
1593 | 1113 |
! |
1114 |
||
1115 |
mimeTypeForSuffixMapping |
|
1116 |
||
1117 |
^ FileSuffixToTypeMapping |
|
1611 | 1118 |
! |
1119 |
||
2023 | 1120 |
mimeTypeFromString:mimeTypeString |
4074 | 1121 |
"given a MIME type for a string" |
2023 | 1122 |
|
1123 |
^ MIMEType fromString:mimeTypeString |
|
1124 |
||
1125 |
" |
|
4074 | 1126 |
MIMETypes mimeTypeFromString:'text/html' |
1127 |
MIMETypes mimeTypeFromString:'image/gif' |
|
1128 |
MIMETypes mimeTypeFromString:'application/x-expecco-testsuite' |
|
2023 | 1129 |
" |
4074 | 1130 |
|
1131 |
"Modified (comment): / 01-03-2018 / 18:49:50 / mawalch" |
|
2023 | 1132 |
! |
1133 |
||
1611 | 1134 |
mimeTypeOfContents:filename |
4074 | 1135 |
"given a filename, scan the contents, return the MIME type or nil, if unknown" |
1611 | 1136 |
|
1612 | 1137 |
|typeString| |
1138 |
||
1139 |
typeString := filename mimeTypeOfContents. |
|
1140 |
typeString isNil ifTrue:[^ nil]. |
|
1141 |
^ MIMEType fromString:typeString. |
|
4074 | 1142 |
|
1143 |
"Modified (comment): / 01-03-2018 / 18:50:06 / mawalch" |
|
1887 | 1144 |
! |
1145 |
||
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1146 |
mimeTypeOfData:someData |
4074 | 1147 |
"this tries to guess the MIME type of contents of someData. |
1148 |
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
|
1149 |
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
|
1150 |
|
3400 | 1151 |
^ self mimeTypeOfData:someData suffix:nil |
4074 | 1152 |
|
1153 |
"Modified (comment): / 01-03-2018 / 18:50:22 / mawalch" |
|
3400 | 1154 |
! |
1155 |
||
1156 |
mimeTypeOfData:someData suffix:fileNameSuffixOrNilIfUnknown |
|
4074 | 1157 |
"this tries to guess the MIME type of someData. |
1158 |
Returns nil if unknown. |
|
3691 | 1159 |
In addition to registered detectors (see addMimeTypeDetector:), |
4072 | 1160 |
this is done using heuristics, and may need some improvement" |
3400 | 1161 |
|
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1162 |
|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
|
1163 |
|
2583 | 1164 |
someData isEmptyOrNil ifTrue:[^ nil]. |
1165 |
||
3691 | 1166 |
TypeFromContentsDetectors notNil ifTrue:[ |
1167 |
TypeFromContentsDetectors do:[:eachDetector | |
|
1168 |
|m| |
|
1169 |
||
1170 |
m := eachDetector value:someData value:fileNameSuffixOrNilIfUnknown. |
|
1171 |
m notNil ifTrue:[^ m] |
|
1172 |
] |
|
1173 |
]. |
|
1174 |
||
2583 | 1175 |
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
|
1176 |
|
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1177 |
"/ read some data from the file ... |
2583 | 1178 |
buffer := (someData copyTo:size) asString. |
3691 | 1179 |
|
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1180 |
lcBuffer := buffer asLowercase. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1181 |
|
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1182 |
(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
|
1183 |
idx := idx + 'mimetype:' size. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1184 |
idx := lcBuffer indexOfNonSeparatorStartingAt:idx. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1185 |
idx2 := lcBuffer indexOfSeparatorStartingAt:idx. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1186 |
idx2 > idx ifTrue:[ |
2583 | 1187 |
^ 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
|
1188 |
]. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1189 |
]. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1190 |
|
2924 | 1191 |
"/ real starters |
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1192 |
#( |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1193 |
( #[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
|
1194 |
#'application/x-ms-shortcut' ) |
2924 | 1195 |
( 'ITOLITLS' |
1196 |
#'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
|
1197 |
( 'WALTOP' |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1198 |
#'application/x-waltop-digital-notepad' ) |
2892 | 1199 |
('PK' |
1200 |
#'application/x-zip-compressed') |
|
4065 | 1201 |
('LZIP' |
1202 |
#'application/lzip') |
|
4279 | 1203 |
('ITSF' |
1204 |
#'application/vnd.ms-htmlhelp' |
|
1205 |
) |
|
3113 | 1206 |
('<?xml' |
1207 |
#'text/xml') |
|
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1208 |
) pairsDo:[:pattern :what | |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1209 |
|patternString| |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1210 |
|
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1211 |
patternString := pattern asString. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1212 |
(buffer startsWith:patternString) ifTrue:[ |
3400 | 1213 |
what = #'application/x-zip-compressed' ifTrue:[ |
1214 |
fileNameSuffixOrNilIfUnknown = 'jar' ifTrue:[ |
|
1215 |
^ MIMEType fromString: #'application/java-archive' |
|
1216 |
]. |
|
1217 |
]. |
|
2583 | 1218 |
^ MIMEType fromString:what |
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1219 |
] |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1220 |
]. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1221 |
|
2924 | 1222 |
"/ 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
|
1223 |
#( |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1224 |
('<body:' #'text/html') |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1225 |
('%!!ps-adobe' #'application/postscript') |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1226 |
('%PDF-' #'application/pdf') |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1227 |
('#!! /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
|
1228 |
('#!!/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
|
1229 |
"/ ('#!! /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
|
1230 |
"/ ('#!!/bin/bash' 'application/x-bash') |
3482 | 1231 |
('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
|
1232 |
|
3113 | 1233 |
('---- encoding: ' #'application/x-smalltalk-source') |
1234 |
('---- 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
|
1235 |
('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
|
1236 |
('from visualworks' #'application/x-smalltalk-source') |
3359 | 1237 |
('from squeak' #'application/x-smalltalk-source') |
1238 |
('from smalltalk/x' #'application/x-smalltalk-source') |
|
4245 | 1239 |
('"{ package:' #'application/x-smalltalk-source') |
1240 |
('"{ encoding: ' #'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
|
1241 |
('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
|
1242 |
('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
|
1243 |
('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
|
1244 |
('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
|
1245 |
('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
|
1246 |
('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
|
1247 |
('methodsfor:' #'application/x-smalltalk-source') |
4245 | 1248 |
('application create:' #'application/x-smalltalk-source') |
3332 | 1249 |
('becomeDefault!!' #'application/x-smalltalk-source') |
3451 | 1250 |
('(reader defineClass:' #'application/x-smalltalk-source') "/ gravel smalltalk |
4072 | 1251 |
('(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
|
1252 |
|
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1253 |
) pairsDo:[:pattern :what | |
4245 | 1254 |
(lcBuffer findString:pattern caseSensitive:false) ~~ 0 ifTrue:[ |
2583 | 1255 |
^ MIMEType fromString:what |
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1256 |
] |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1257 |
]. |
3691 | 1258 |
|
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1259 |
(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
|
1260 |
((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
|
1261 |
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
|
1262 |
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
|
1263 |
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
|
1264 |
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
|
1265 |
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
|
1266 |
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
|
1267 |
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
|
1268 |
ifTrue:[ |
2583 | 1269 |
^ 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
|
1270 |
] |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1271 |
]. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1272 |
|
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1273 |
[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
|
1274 |
|
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1275 |
size == 0 ifTrue:[ |
2583 | 1276 |
^ 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
|
1277 |
]. |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1278 |
^ nil |
2891 | 1279 |
|
2924 | 1280 |
"Modified: / 12-07-2011 / 19:08:17 / cg" |
4074 | 1281 |
"Modified (comment): / 01-03-2018 / 18:50:36 / mawalch" |
4279 | 1282 |
"Modified: / 27-06-2019 / 16:33:41 / Claus Gittinger" |
2582
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1283 |
! |
298203fdb64d
mime type detection from conents moved from fileName to here
Claus Gittinger <cg@exept.de>
parents:
2570
diff
changeset
|
1284 |
|
1887 | 1285 |
suffixForMimeType:mimeType |
4074 | 1286 |
"given a file suffix, return the MIME type" |
1887 | 1287 |
|
1288 |
^ TypeToFileSuffixMapping at:mimeType ifAbsent:nil |
|
1289 |
||
1290 |
" |
|
4074 | 1291 |
self suffixForMimeType:(MIMEType fromString:'image/gif') |
1887 | 1292 |
" |
1293 |
||
4074 | 1294 |
"Created: / 30-06-1997 / 21:55:51 / cg" |
1295 |
"Modified: / 23-12-1999 / 22:30:55 / cg" |
|
1296 |
"Modified (comment): / 01-03-2018 / 18:50:50 / mawalch" |
|
1887 | 1297 |
! |
1298 |
||
1299 |
suffixForMimeTypeString:mimeTypeString |
|
4074 | 1300 |
"given a file suffix, return the MIME type" |
1887 | 1301 |
|
4074 | 1302 |
^ self suffixForMimeType:(MIMEType fromString:mimeTypeString) |
1887 | 1303 |
|
1304 |
" |
|
4074 | 1305 |
self suffixForMimeTypeString:'image/gif' |
1887 | 1306 |
" |
1307 |
||
4074 | 1308 |
"Created: / 30-06-1997 / 21:55:51 / cg" |
1309 |
"Modified: / 23-12-1999 / 22:30:55 / cg" |
|
1310 |
"Modified (comment): / 01-03-2018 / 18:51:06 / mawalch" |
|
3982 | 1311 |
! |
1312 |
||
1313 |
typeToInfoMapping |
|
1314 |
TypeToInfoMapping isNil ifTrue:[ |
|
1315 |
self initializeFileInfoMappings |
|
1316 |
]. |
|
1317 |
^ TypeToInfoMapping |
|
1318 |
||
1319 |
"Created: / 27-08-2017 / 14:30:44 / cg" |
|
1612 | 1320 |
! ! |
1321 |
||
2116 | 1322 |
!MIMETypes class methodsFor:'queries-applications'! |
1323 |
||
2117 | 1324 |
defaultCommandPerMIME |
4074 | 1325 |
"returns the collection which is used to map MIME type to command-templates." |
2117 | 1326 |
|
1327 |
"TODO: move this to OS/UserPreferences" |
|
1328 |
||
1329 |
DefaultCommandPerMIMEPerOS isNil ifTrue:[ |
|
1330 |
self initializeDefaultCommands |
|
1331 |
]. |
|
1332 |
OperatingSystem isUNIXlike ifTrue:[ |
|
1333 |
^ DefaultCommandPerMIMEPerOS at:#unix |
|
1334 |
]. |
|
1335 |
^ DefaultCommandPerMIMEPerOS at:#win32 |
|
2942
693d381bc775
comment/format in: #defaultCommandPerMIME
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1336 |
|
693d381bc775
comment/format in: #defaultCommandPerMIME
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1337 |
" |
693d381bc775
comment/format in: #defaultCommandPerMIME
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1338 |
MIMETypes defaultCommandPerMIME |
693d381bc775
comment/format in: #defaultCommandPerMIME
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1339 |
" |
693d381bc775
comment/format in: #defaultCommandPerMIME
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1340 |
|
693d381bc775
comment/format in: #defaultCommandPerMIME
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1341 |
"Modified (comment): / 16-09-2011 / 16:20:12 / cg" |
4074 | 1342 |
"Modified (comment): / 01-03-2018 / 19:06:54 / mawalch" |
2117 | 1343 |
! |
1344 |
||
2116 | 1345 |
defaultCommandTemplateToOpenMimeType:mimeType |
1346 |
|cmd| |
|
1347 |
||
1348 |
cmd := self defaultCommandPerMIME at:mimeType ifAbsent:nil. |
|
1349 |
cmd isNil ifTrue:[ |
|
1350 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
|
1351 |
cmd := Win32OperatingSystem::RegistryEntry commandTemplateToOpenMimeType:mimeType |
|
1352 |
]. |
|
1353 |
]. |
|
1354 |
^ cmd |
|
1355 |
||
1356 |
" |
|
1357 |
MIMETypes defaultCommandTemplateToOpenMimeType:'application/pdf' |
|
2118 | 1358 |
MIMETypes defaultCommandTemplateToOpenMimeType:'text/html' |
2116 | 1359 |
" |
1360 |
||
1361 |
"Created: / 12-05-2004 / 11:09:22 / cg" |
|
1362 |
"Modified: / 12-05-2004 / 11:16:53 / cg" |
|
1363 |
! |
|
1364 |
||
1365 |
defaultCommandTemplateToPrintMimeType:mimeType |
|
1366 |
|cmd| |
|
1367 |
||
1368 |
cmd := self defaultPrintCommandPerMIME at:mimeType ifAbsent:nil. |
|
1369 |
cmd isNil ifTrue:[ |
|
1370 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
|
1371 |
cmd := Win32OperatingSystem::RegistryEntry commandTemplateToPrintMimeType:mimeType |
|
1372 |
]. |
|
1373 |
]. |
|
1374 |
^ cmd |
|
1375 |
||
1376 |
" |
|
1377 |
MIMETypes defaultCommandTemplateToPrintMimeType:'application/pdf' |
|
1378 |
" |
|
2117 | 1379 |
! |
1380 |
||
1381 |
defaultPrintCommandPerMIME |
|
4074 | 1382 |
"returns the collection which is used to map MIME type to printing command-templates." |
2117 | 1383 |
|
1384 |
"TODO: move this to OS/UserPreferences" |
|
1385 |
||
1386 |
DefaultPrintCommandPerMIMEPerOS isNil ifTrue:[ |
|
1387 |
self initializeDefaultCommands |
|
1388 |
]. |
|
1389 |
OperatingSystem isUNIXlike ifTrue:[ |
|
1390 |
^ DefaultPrintCommandPerMIMEPerOS at:#unix |
|
1391 |
]. |
|
1392 |
^ DefaultPrintCommandPerMIMEPerOS at:#win32 |
|
2116 | 1393 |
! ! |
1394 |
||
1729 | 1395 |
!MIMETypes class methodsFor:'queries-image formats'! |
1396 |
||
1397 |
imageReaderClasses |
|
1398 |
"return a collection of registered image reader classes" |
|
1399 |
||
3870 | 1400 |
TypeToImageReaderClassMapping notNil ifTrue:[ |
1401 |
^ TypeToImageReaderClassMapping values asSet. |
|
1729 | 1402 |
]. |
3870 | 1403 |
^ #(). |
1729 | 1404 |
|
3870 | 1405 |
"Created: / 30-06-1997 / 22:03:42 / cg" |
1406 |
"Modified: / 01-08-1998 / 16:59:52 / cg" |
|
1407 |
"Modified: / 09-02-2017 / 15:23:52 / stefan" |
|
1729 | 1408 |
! |
1409 |
||
1410 |
imageReaderForSuffix:aSuffix |
|
4074 | 1411 |
"given a file suffix, return an appropriate image reader class" |
1729 | 1412 |
|
2724
8e834e62dbbc
Initialize when querying for image type and not yet initialized
Stefan Vogel <sv@exept.de>
parents:
2710
diff
changeset
|
1413 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[ |
8e834e62dbbc
Initialize when querying for image type and not yet initialized
Stefan Vogel <sv@exept.de>
parents:
2710
diff
changeset
|
1414 |
self initializeImageReaderMappings |
8e834e62dbbc
Initialize when querying for image type and not yet initialized
Stefan Vogel <sv@exept.de>
parents:
2710
diff
changeset
|
1415 |
]. |
1729 | 1416 |
^ FileSuffixToImageReaderClassMapping at:aSuffix asLowercase ifAbsent:nil |
1417 |
||
4080 | 1418 |
" |
1419 |
self imageReaderForSuffix:'wbmp' |
|
1420 |
" |
|
1421 |
||
4074 | 1422 |
"Created: / 30-06-1997 / 21:59:11 / cg" |
1423 |
"Modified: / 01-08-1998 / 17:01:58 / cg" |
|
1424 |
"Modified (comment): / 01-03-2018 / 18:57:59 / mawalch" |
|
1729 | 1425 |
! |
1426 |
||
1427 |
imageReaderForSuffix:aSuffix put:aReaderClass |
|
1428 |
"register an image reader for a file suffix" |
|
1429 |
||
1430 |
FileSuffixToImageReaderClassMapping isNil ifTrue:[ |
|
2724
8e834e62dbbc
Initialize when querying for image type and not yet initialized
Stefan Vogel <sv@exept.de>
parents:
2710
diff
changeset
|
1431 |
self initializeImageReaderMappings |
1729 | 1432 |
]. |
1433 |
FileSuffixToImageReaderClassMapping at:aSuffix asLowercase put:aReaderClass |
|
1434 |
||
1435 |
"Created: / 30.6.1997 / 21:59:43 / cg" |
|
1436 |
"Modified: / 1.8.1998 / 17:02:14 / cg" |
|
1437 |
! |
|
1438 |
||
1439 |
imageReaderForType:mimeTypeString |
|
4074 | 1440 |
"given a MIME type, return an appropriate image reader class" |
1729 | 1441 |
|
2724
8e834e62dbbc
Initialize when querying for image type and not yet initialized
Stefan Vogel <sv@exept.de>
parents:
2710
diff
changeset
|
1442 |
TypeToImageReaderClassMapping isNil ifTrue:[ |
8e834e62dbbc
Initialize when querying for image type and not yet initialized
Stefan Vogel <sv@exept.de>
parents:
2710
diff
changeset
|
1443 |
self initializeImageReaderMappings |
8e834e62dbbc
Initialize when querying for image type and not yet initialized
Stefan Vogel <sv@exept.de>
parents:
2710
diff
changeset
|
1444 |
]. |
1729 | 1445 |
^ TypeToImageReaderClassMapping at:mimeTypeString asLowercase ifAbsent:nil |
1446 |
||
4074 | 1447 |
"Created: / 30-06-1997 / 21:56:01 / cg" |
1448 |
"Modified: / 01-08-1998 / 17:02:28 / cg" |
|
1449 |
"Modified (format): / 01-03-2018 / 18:58:10 / mawalch" |
|
1729 | 1450 |
! |
1451 |
||
1452 |
imageReaderForType:mimeTypeString put:aReaderClass |
|
4074 | 1453 |
"register an image reader for a MIME type" |
1729 | 1454 |
|
1455 |
TypeToImageReaderClassMapping isNil ifTrue:[ |
|
2724
8e834e62dbbc
Initialize when querying for image type and not yet initialized
Stefan Vogel <sv@exept.de>
parents:
2710
diff
changeset
|
1456 |
self initializeImageReaderMappings |
1729 | 1457 |
]. |
4074 | 1458 |
TypeToImageReaderClassMapping |
3870 | 1459 |
at:(MIMEType fromString:mimeTypeString asLowercase) |
1460 |
put:aReaderClass |
|
1729 | 1461 |
|
3870 | 1462 |
"Created: / 30-06-1997 / 21:56:11 / cg" |
1463 |
"Modified: / 01-08-1998 / 17:02:40 / cg" |
|
1464 |
"Modified: / 09-02-2017 / 15:32:58 / stefan" |
|
4074 | 1465 |
"Modified (comment): / 01-03-2018 / 18:58:27 / mawalch" |
1729 | 1466 |
! ! |
1467 |
||
1468 |
!MIMETypes class methodsFor:'queries-language syntax'! |
|
1469 |
||
4087 | 1470 |
commentStringsForFilename:aFilenameOrString |
1729 | 1471 |
"return a useful comment definition; heuristics for now. |
1472 |
The returned value is an array of 2 elements; |
|
1473 |
the first is the end-of-line comment string (or nil); |
|
1474 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
1475 |
||
4087 | 1476 |
|filename mime| |
1729 | 1477 |
|
4087 | 1478 |
filename := aFilenameOrString asFilename. |
1479 |
mime := MIMETypes mimeTypeForFilename:filename. |
|
1480 |
^ self commentStringsForMimeType:mime suffix:(filename suffix) |
|
1729 | 1481 |
|
1482 |
" |
|
1483 |
MIMETypes commentStringsForFilename:'Makefile'. |
|
4074 | 1484 |
MIMETypes commentStringsForFilename:'Object.st'. |
1485 |
MIMETypes commentStringsForFilename:'Foo.java'. |
|
1486 |
MIMETypes commentStringsForFilename:'Foo.html'. |
|
1729 | 1487 |
" |
1488 |
! |
|
1489 |
||
1490 |
commentStringsForFilename:aFilename ifUnknown:alternativeBlockReturningCommentString |
|
1491 |
"return a useful comment definition; heuristics for now. |
|
1492 |
The returned value is an array of 2 elements; |
|
1493 |
the first is the end-of-line comment string (or nil); |
|
1494 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
1495 |
||
1496 |
|mime| |
|
1497 |
||
1498 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
1499 |
^ self commentStringsForMimeType:mime suffix:(aFilename asFilename suffix) ifUnknown:alternativeBlockReturningCommentString |
|
1500 |
||
1501 |
" |
|
1502 |
MIMETypes commentStringsForFilename:'Makefile'. |
|
4074 | 1503 |
MIMETypes commentStringsForFilename:'Object.st'. |
1504 |
MIMETypes commentStringsForFilename:'Foo.java'. |
|
1729 | 1505 |
" |
1506 |
! |
|
1507 |
||
1508 |
commentStringsForMimeType:mime suffix:suff |
|
1509 |
"return a useful comment definition; heuristics for now. |
|
1510 |
The returned value is an array of 2 elements; |
|
1511 |
the first is the end-of-line comment string (or nil); |
|
1512 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
1513 |
||
1514 |
^ self |
|
4074 | 1515 |
commentStringsForMimeType:mime suffix:suff |
1516 |
ifUnknown: #(';' (nil nil)) |
|
1729 | 1517 |
|
1518 |
" |
|
1519 |
|mime| |
|
1520 |
||
1521 |
mime := MIMETypes mimeTypeForFilename:'Makefile'. |
|
4074 | 1522 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
1729 | 1523 |
" |
1524 |
||
1525 |
" |
|
1526 |
|mime| |
|
1527 |
||
1528 |
mime := MIMETypes mimeTypeForFilename:'Object.st'. |
|
4074 | 1529 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
1729 | 1530 |
" |
1531 |
! |
|
1532 |
||
1533 |
commentStringsForMimeType:mime suffix:suff ifUnknown:alternativeBlockReturningCommentString |
|
1534 |
"return a useful comment definition; heuristics for now. |
|
1535 |
The returned value is an array of 2 elements; |
|
1536 |
the first is the end-of-line comment string (or nil); |
|
1537 |
the second an array of opening/closing delimiters (or an array of nils)" |
|
1538 |
||
1539 |
|commentSpec| |
|
1540 |
||
1541 |
commentSpec := TypeToCommentStringMapping at:mime ifAbsent:nil. |
|
1542 |
commentSpec notNil ifTrue:[ |
|
1543 |
^ commentSpec |
|
1544 |
]. |
|
3492 | 1545 |
suff notNil ifTrue:[ |
1546 |
commentSpec := SuffixToCommentStringMapping at:suff ifAbsent:nil. |
|
1547 |
commentSpec notNil ifTrue:[ |
|
1548 |
^ commentSpec |
|
1549 |
]. |
|
1729 | 1550 |
]. |
1551 |
^ alternativeBlockReturningCommentString value |
|
1552 |
||
1553 |
" |
|
1554 |
|mime| |
|
1555 |
||
1556 |
mime := MIMETypes mimeTypeForFilename:'Makefile'. |
|
4074 | 1557 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
1729 | 1558 |
" |
1559 |
||
1560 |
" |
|
1561 |
|mime| |
|
1562 |
||
1563 |
mime := MIMETypes mimeTypeForFilename:'Object.st'. |
|
4074 | 1564 |
MIMETypes commentStringsForMimeType:mime suffix:nil. |
1729 | 1565 |
" |
2298 | 1566 |
! |
1567 |
||
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
1568 |
parenthesisSpecForFilename:aFilename |
2298 | 1569 |
"return a useful parentesis spec; heuristics for now. |
1570 |
The returned value is a dictionary to be used as parentesis spec in an editor" |
|
1571 |
||
1572 |
|mime| |
|
1573 |
||
1574 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
1575 |
^ self parenthesisSpecForMimeType:mime suffix:(aFilename asFilename suffix) |
2298 | 1576 |
|
1577 |
" |
|
4074 | 1578 |
MIMETypes parenthesisSpecForFilename:'Object.st'. |
1579 |
MIMETypes parenthesisSpecForFilename:'Foo.java'. |
|
1580 |
MIMETypes parenthesisSpecForFilename:'Foo.html'. |
|
1581 |
MIMETypes parenthesisSpecForFilename:'Foo.lsp'. |
|
2298 | 1582 |
" |
1583 |
||
1584 |
"Created: / 10-04-2007 / 15:18:41 / cg" |
|
1585 |
! |
|
1586 |
||
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
1587 |
parenthesisSpecForFilename:aFilename ifUnknown:alternative |
2298 | 1588 |
|mime| |
1589 |
||
1590 |
mime := MIMETypes mimeTypeForFilename:aFilename. |
|
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
1591 |
^ self parenthesisSpecForMimeType:mime suffix:(aFilename asFilename suffix) ifUnknown:alternative |
2298 | 1592 |
|
1593 |
"Created: / 10-04-2007 / 15:26:20 / cg" |
|
1594 |
! |
|
1595 |
||
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
1596 |
parenthesisSpecForMimeType:mime suffix:suff |
2298 | 1597 |
^ self |
4074 | 1598 |
parenthesisSpecForMimeType:mime suffix:suff |
1599 |
ifUnknown:nil |
|
2298 | 1600 |
|
1601 |
"Created: / 10-04-2007 / 15:19:39 / cg" |
|
4074 | 1602 |
"Modified (format): / 01-03-2018 / 19:03:58 / mawalch" |
2298 | 1603 |
! |
1604 |
||
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
1605 |
parenthesisSpecForMimeType:mime suffix:suff ifUnknown:alternativeValue |
2298 | 1606 |
|spec| |
1607 |
||
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
1608 |
spec := TypeToParenthesisSpecMapping at:mime ifAbsent:nil. |
2298 | 1609 |
spec notNil ifTrue:[ |
1610 |
^ spec |
|
1611 |
]. |
|
1612 |
||
2491
831417cc1e5b
Change bas spelling: parentesis to good spellinge parenthesis
Stefan Vogel <sv@exept.de>
parents:
2490
diff
changeset
|
1613 |
spec := SuffixToParenthesisSpecMapping at:suff ifAbsent:nil. |
2298 | 1614 |
spec notNil ifTrue:[ |
1615 |
^ spec |
|
1616 |
]. |
|
1617 |
||
1618 |
^ alternativeValue value |
|
1619 |
||
1620 |
"Created: / 10-04-2007 / 15:20:38 / cg" |
|
1729 | 1621 |
! ! |
1622 |
||
1612 | 1623 |
!MIMETypes::MIMEType class methodsFor:'documentation'! |
1624 |
||
1625 |
documentation |
|
1626 |
" |
|
1864 | 1627 |
like a string, but knows that it represents a mimeType. |
3359 | 1628 |
mimetypes are singletons, remembered in the class variable CachedTypes. |
1612 | 1629 |
" |
1630 |
! ! |
|
1631 |
||
1632 |
!MIMETypes::MIMEType class methodsFor:'instance creation'! |
|
1633 |
||
1634 |
fromString:aString |
|
1635 |
|cachedType newType| |
|
1636 |
||
1637 |
aString class == self ifTrue:[^ aString]. |
|
1638 |
||
3011
f2af94d78383
delay initialization of cachedTypes
Claus Gittinger <cg@exept.de>
parents:
3008
diff
changeset
|
1639 |
CachedTypes isNil ifTrue:[ |
3012 | 1640 |
CachedTypes := Dictionary new:100. |
3011
f2af94d78383
delay initialization of cachedTypes
Claus Gittinger <cg@exept.de>
parents:
3008
diff
changeset
|
1641 |
]. |
1612 | 1642 |
cachedType := CachedTypes at:aString ifAbsent:nil. |
1643 |
cachedType notNil ifTrue:[^ cachedType]. |
|
3011
f2af94d78383
delay initialization of cachedTypes
Claus Gittinger <cg@exept.de>
parents:
3008
diff
changeset
|
1644 |
|
1612 | 1645 |
newType := aString copy changeClassTo:self. |
1646 |
CachedTypes at:aString put:newType. |
|
1647 |
^ newType |
|
1648 |
||
1649 |
" |
|
3870 | 1650 |
CachedTypes := nil. |
1612 | 1651 |
self fromString:'text/html' |
1652 |
" |
|
3011
f2af94d78383
delay initialization of cachedTypes
Claus Gittinger <cg@exept.de>
parents:
3008
diff
changeset
|
1653 |
|
3012 | 1654 |
"Modified: / 20-07-2012 / 17:36:31 / cg" |
3870 | 1655 |
"Modified (comment): / 09-02-2017 / 15:36:06 / stefan" |
1612 | 1656 |
! ! |
1657 |
||
4088 | 1658 |
!MIMETypes::MIMEType methodsFor:'converting'! |
1659 |
||
1660 |
asMimeType |
|
1661 |
^ self |
|
1662 |
! ! |
|
1663 |
||
1612 | 1664 |
!MIMETypes::MIMEType methodsFor:'queries'! |
1665 |
||
3359 | 1666 |
fileTypeInfo |
4074 | 1667 |
^ MIMETypes fileInfoForMimeType:self |
3359 | 1668 |
|
1669 |
" |
|
4074 | 1670 |
(MIMETypes mimeTypeFromString:'application/x-smalltalk-source') fileTypeInfo |
3359 | 1671 |
" |
4074 | 1672 |
|
1673 |
"Modified: / 01-03-2018 / 19:16:49 / mawalch" |
|
3359 | 1674 |
! |
1675 |
||
1693 | 1676 |
isArchive |
3260 | 1677 |
<resource: #obsolete> |
1678 |
"return true, if I represent an archive type (such as zip or tar)" |
|
1679 |
||
1680 |
^ self isArchiveType |
|
1681 |
! |
|
1682 |
||
1683 |
isArchiveType |
|
1864 | 1684 |
"return true, if I represent an archive type (such as zip or tar)" |
1685 |
||
1612 | 1686 |
|archivTypes| |
1687 |
||
1729 | 1688 |
archivTypes := MIMETypes applicationCompressorsAndArchiveTypeList. |
1612 | 1689 |
archivTypes pairWiseDo:[: ext : type | |
1690 |
self = type ifTrue:[ ^ true]. |
|
1691 |
]. |
|
1692 |
^ false |
|
1693 |
! |
|
1694 |
||
2024 | 1695 |
isBinary |
3260 | 1696 |
<resource: #obsolete> |
1697 |
"return true, if I represent a binary (non-text) type" |
|
1698 |
||
1699 |
^ self isBinaryType |
|
1700 |
! |
|
1701 |
||
1702 |
isBinaryType |
|
2024 | 1703 |
"return true, if I represent a binary (non-text) type" |
1704 |
||
1705 |
^ self isTextType not |
|
1706 |
! |
|
1707 |
||
4088 | 1708 |
isCHeaderType |
1709 |
"return true, if I represent a C header file type" |
|
1710 |
||
1711 |
^ (self startsWith: 'application/x-c-header') |
|
1712 |
! |
|
1713 |
||
1714 |
isCPPSourceType |
|
1715 |
"return true, if I represent a C++ sourcecode type" |
|
1716 |
||
1717 |
^ (self startsWith: 'application/x-cpp-source') |
|
1718 |
! |
|
1719 |
||
1720 |
isCSourceType |
|
1721 |
"return true, if I represent a C sourcecode type" |
|
1722 |
||
1723 |
^ (self startsWith: 'application/x-c-source') |
|
1724 |
! |
|
1725 |
||
1612 | 1726 |
isHtml |
3260 | 1727 |
<resource: #obsolete> |
1728 |
"return true, if I represent the html text type" |
|
1729 |
||
1730 |
^ self isHtmlType |
|
1731 |
! |
|
1732 |
||
1733 |
isHtmlType |
|
1864 | 1734 |
"return true, if I represent the html text type" |
1612 | 1735 |
|
1736 |
^ (self = 'text/html') |
|
1737 |
! |
|
1738 |
||
1739 |
isImage |
|
3260 | 1740 |
<resource: #obsolete> |
1741 |
"return true, if I represent an image type (such as gif or jpg)" |
|
1742 |
||
1743 |
^ self isImageType |
|
1744 |
! |
|
1745 |
||
1746 |
isImageType |
|
1864 | 1747 |
"return true, if I represent an image type (such as gif or jpg)" |
1612 | 1748 |
|
1693 | 1749 |
^ (self startsWith:'image/') |
1612 | 1750 |
! |
1751 |
||
1752 |
isPdf |
|
3260 | 1753 |
<resource: #obsolete> |
1754 |
"return true, if I represent the pdf type" |
|
1755 |
||
1756 |
^ self isPdfType |
|
1757 |
! |
|
1758 |
||
1759 |
isPdfType |
|
1864 | 1760 |
"return true, if I represent the pdf type" |
1761 |
||
1612 | 1762 |
^ (self = 'application/pdf') |
1763 |
! |
|
1764 |
||
1765 |
isSmalltalkSource |
|
3260 | 1766 |
<resource: #obsolete> |
1767 |
"return true, if I represent the smalltalk sourcecode type" |
|
1768 |
||
1769 |
^ self isSmalltalkSourceType |
|
1770 |
! |
|
1771 |
||
1772 |
isSmalltalkSourceType |
|
1864 | 1773 |
"return true, if I represent the smalltalk sourcecode type" |
1774 |
||
3359 | 1775 |
^ (self startsWith: 'application/x-smalltalk-source') |
1783 | 1776 |
! |
1777 |
||
2024 | 1778 |
isTextType |
1779 |
"return true, if I represent some text type" |
|
1780 |
||
1781 |
^ self startsWith:'text/' |
|
1782 |
! |
|
1783 |
||
1783 | 1784 |
isXml |
3260 | 1785 |
<resource: #obsolete> |
1786 |
"return true, if I represent the xml text type" |
|
1787 |
||
1788 |
^ self isXmlType |
|
1789 |
! |
|
1790 |
||
1791 |
isXmlType |
|
1864 | 1792 |
"return true, if I represent the xml text type" |
1793 |
||
3941 | 1794 |
^ self = 'text/xml' or:[self = 'application/xml'] |
1795 |
||
1796 |
"Modified (format): / 13-03-2017 / 09:41:52 / stefan" |
|
2490 | 1797 |
! |
1798 |
||
1799 |
suffix |
|
1800 |
^ MIMETypes suffixForMimeType:self |
|
1801 |
||
1802 |
" |
|
4074 | 1803 |
(MIMETypes mimeTypeFromString:'application/x-expecco-testsuite') suffix |
2490 | 1804 |
" |
643 | 1805 |
! ! |
1806 |
||
1807 |
!MIMETypes class methodsFor:'documentation'! |
|
1808 |
||
1809 |
version |
|
3482 | 1810 |
^ '$Header$' |
2758
66e62ceecb67
comment/format in: #defaultCommandForMimeType:
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
1811 |
! |
66e62ceecb67
comment/format in: #defaultCommandForMimeType:
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
1812 |
|
66e62ceecb67
comment/format in: #defaultCommandForMimeType:
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
1813 |
version_CVS |
3482 | 1814 |
^ '$Header$' |
643 | 1815 |
! ! |
1666 | 1816 |
|
3104 | 1817 |
|
643 | 1818 |
MIMETypes initialize! |