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