Filename.st
changeset 11406 af2c2118e164
parent 11397 872cd41bbe05
child 11424 c169cc34afe9
--- a/Filename.st	Thu Dec 11 15:11:40 2008 +0100
+++ b/Filename.st	Fri Dec 12 13:56:12 2008 +0100
@@ -3994,21 +3994,11 @@
     |type buffer lcBuffer s size idx idx2|
 
     type := self type.
-    type isNil ifTrue:[
-        ^ nil.
-    ].
-    type == #directory ifTrue:[
-        ^ nil
-    ].                                                              
-    type == #characterSpecial ifTrue:[
-        ^ nil
-    ].
-    type == #blockSpecial ifTrue:[                                     
-        ^ nil
-    ].
-    type == #socket ifTrue:[
-        ^ nil
-    ].
+    type isNil ifTrue:[ ^ nil ].
+    type == #directory ifTrue:[ ^ nil ].                                                              
+    type == #characterSpecial ifTrue:[ ^ nil ].
+    type == #blockSpecial ifTrue:[ ^ nil ].
+    type == #socket ifTrue:[ ^ nil ].
     self fileSize == 0 ifTrue:[^ nil].
 
     s := self readStreamOrNil.
@@ -4023,91 +4013,94 @@
         size := s nextBytes:buffer size into:buffer.
     ].
     s close.
-    lcBuffer := buffer asLowercase.
-
-    (idx := lcBuffer findString:'mimetype:') ~~ 0 ifTrue:[
-        idx := idx + 'mimetype:' size.
-        idx := lcBuffer indexOfNonSeparatorStartingAt:idx.
-        idx2 := lcBuffer indexOfSeparatorStartingAt:idx.
-        idx2 > idx ifTrue:[
-            ^ lcBuffer copyFrom:idx to:idx2-1
-        ].
-    ].
-
-    #(
-        ( 'lnk' #[16r4C 16r00 16r00 16r00 16r01 16r14 16r02 16r00 16r00 16r00 16r00 16r00 16rC0 16r00 16r00 16r00 16r00 16r00 16r00 16r46] 
-                #'application/x-ms-shortcut' )
-        ( 'top' 'WALTOP' 
-                #'application/x-waltop-digital-notepad' )
-     ) triplesDo:[:suffixMatch :pattern :what |
-        |patternString|
-
-        (suffixMatch isNil or:[suffixMatch match:self suffix ignoreCase:true]) ifTrue:[
-            patternString := pattern asString.
-            (buffer startsWith:patternString) ifTrue:[
-                ^ what
-            ]
-        ]
-    ].
-
-    #(
-            ('<body:'                   #'text/html')
-            ('%!!ps-adobe'               #'application/postscript')
-            ('%PDF-'                    #'application/pdf')
-            ('#!! /bin/sh'               #'application/x-sh')
-            ('#!!/bin/sh'                #'application/x-sh')
-            "/ ('#!! /bin/bash'              'application/x-bash')
-            "/ ('#!!/bin/bash'               'application/x-bash')
-            ('<?xml version='           #'text/xml')
-        
-            ('from dolphin'             #'application/x-smalltalk-source')
-            ('from visualworks'         #'application/x-smalltalk-source')
-            ('categoriesforclass'       #'application/x-smalltalk-source')
-            ('methodsfor!!'              #'application/x-smalltalk-source')
-            ('subclass:'                #'application/x-smalltalk-source')
-            ('methodsfor:'              #'application/x-smalltalk-source')
-            ('interchangeversion:'      #'application/x-smalltalk-source-sif')
-            ('subclass:'                #'application/x-smalltalk-source')
-            ('methodsfor:'              #'application/x-smalltalk-source')
-
-     ) pairsDo:[:pattern :what | 
-        (lcBuffer findString:pattern) ~~ 0 ifTrue:[
-            ^ what
-        ]
-    ].
-
-    (idx := lcBuffer findString:'<h') ~~ 0 ifTrue:[
-        ((lcBuffer continuesWith:'<head' startingAt:idx)
-        or:[(lcBuffer continuesWith:'<html' startingAt:idx)
-        or:[(lcBuffer continuesWith:'<h1' startingAt:idx)
-        or:[(lcBuffer continuesWith:'<h2' startingAt:idx)
-        or:[(lcBuffer continuesWith:'<h3' startingAt:idx)
-        or:[(lcBuffer continuesWith:'<h4' startingAt:idx)
-        or:[(lcBuffer continuesWith:'<h5' startingAt:idx)
-        or:[(lcBuffer continuesWith:'<h6' startingAt:idx)]]]]]]])
-        ifTrue:[
-            ^ #'text/html'
-        ]
-    ].
-
-    [size ~~ 0 and:[(buffer at:size) isPrintable]] whileTrue:[size := size - 1].
-
-    size == 0 ifTrue:[
-        ^ #'text/plain'
-    ].
-    ^ nil
+
+    ^ MIMETypes mimeTypeOfData:buffer
+
+"/    lcBuffer := buffer asLowercase.
+"/
+"/    (idx := lcBuffer findString:'mimetype:') ~~ 0 ifTrue:[
+"/        idx := idx + 'mimetype:' size.
+"/        idx := lcBuffer indexOfNonSeparatorStartingAt:idx.
+"/        idx2 := lcBuffer indexOfSeparatorStartingAt:idx.
+"/        idx2 > idx ifTrue:[
+"/            ^ lcBuffer copyFrom:idx to:idx2-1
+"/        ].
+"/    ].
+"/
+"/    #(
+"/        ( 'lnk' #[16r4C 16r00 16r00 16r00 16r01 16r14 16r02 16r00 16r00 16r00 16r00 16r00 16rC0 16r00 16r00 16r00 16r00 16r00 16r00 16r46] 
+"/                #'application/x-ms-shortcut' )
+"/        ( 'top' 'WALTOP' 
+"/                #'application/x-waltop-digital-notepad' )
+"/     ) triplesDo:[:suffixMatch :pattern :what |
+"/        |patternString|
+"/
+"/        (suffixMatch isNil or:[suffixMatch match:self suffix ignoreCase:true]) ifTrue:[
+"/            patternString := pattern asString.
+"/            (buffer startsWith:patternString) ifTrue:[
+"/                ^ what
+"/            ]
+"/        ]
+"/    ].
+"/
+"/    #(
+"/            ('<body:'                   #'text/html')
+"/            ('%!!ps-adobe'               #'application/postscript')
+"/            ('%PDF-'                    #'application/pdf')
+"/            ('#!! /bin/sh'               #'application/x-sh')
+"/            ('#!!/bin/sh'                #'application/x-sh')
+"/            "/ ('#!! /bin/bash'              'application/x-bash')
+"/            "/ ('#!!/bin/bash'               'application/x-bash')
+"/            ('<?xml version='           #'text/xml')
+"/        
+"/            ('from dolphin'             #'application/x-smalltalk-source')
+"/            ('from visualworks'         #'application/x-smalltalk-source')
+"/            ('categoriesforclass'       #'application/x-smalltalk-source')
+"/            ('methodsfor!!'              #'application/x-smalltalk-source')
+"/            ('subclass:'                #'application/x-smalltalk-source')
+"/            ('methodsfor:'              #'application/x-smalltalk-source')
+"/            ('interchangeversion:'      #'application/x-smalltalk-source-sif')
+"/            ('subclass:'                #'application/x-smalltalk-source')
+"/            ('methodsfor:'              #'application/x-smalltalk-source')
+"/
+"/     ) pairsDo:[:pattern :what | 
+"/        (lcBuffer findString:pattern) ~~ 0 ifTrue:[
+"/            ^ what
+"/        ]
+"/    ].
+"/
+"/    (idx := lcBuffer findString:'<h') ~~ 0 ifTrue:[
+"/        ((lcBuffer continuesWith:'<head' startingAt:idx)
+"/        or:[(lcBuffer continuesWith:'<html' startingAt:idx)
+"/        or:[(lcBuffer continuesWith:'<h1' startingAt:idx)
+"/        or:[(lcBuffer continuesWith:'<h2' startingAt:idx)
+"/        or:[(lcBuffer continuesWith:'<h3' startingAt:idx)
+"/        or:[(lcBuffer continuesWith:'<h4' startingAt:idx)
+"/        or:[(lcBuffer continuesWith:'<h5' startingAt:idx)
+"/        or:[(lcBuffer continuesWith:'<h6' startingAt:idx)]]]]]]])
+"/        ifTrue:[
+"/            ^ #'text/html'
+"/        ]
+"/    ].
+"/
+"/    [size ~~ 0 and:[(buffer at:size) isPrintable]] whileTrue:[size := size - 1].
+"/
+"/    size == 0 ifTrue:[
+"/        ^ #'text/plain'
+"/    ].
+"/    ^ nil
 
     "
      'Makefile' asFilename mimeTypeOfContents     
      '.' asFilename mimeTypeOfContents            
-     '/dev/null' asFilename mimeTypeOfContents 
+     '/dev/null' asFilename mimeTypeOfContents  
      '/tmp/.X11-unix/X0' asFilename mimeTypeOfContents   
-     'smalltalk.rc' asFilename mimeTypeOfContents     
+     'smalltalk.rc' asFilename mimeTypeOfContents      
      'bitmaps/SBrowser.xbm' asFilename mimeTypeOfContents    
      '../../rules/stmkmf' asFilename mimeTypeOfContents 
-     '/bläh' asFilename mimeTypeOfContents      
+     '/bläh' asFilename mimeTypeOfContents              
      'C:\Dokumente und Einstellungen\cg\Favoriten\languages.lnk' asFilename mimeTypeOfContents
-     'G:\A\A01.TOP' asFilename mimeTypeOfContents  
+     'G:\A\A01.TOP' asFilename mimeTypeOfContents       
     "
 
     "Modified: / 06-11-2006 / 11:44:58 / cg"
@@ -5576,7 +5569,7 @@
 !Filename class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.331 2008-12-09 13:59:41 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.332 2008-12-12 12:56:12 cg Exp $'
 ! !
 
 Filename initialize!