--- a/MIMETypes.st Wed Sep 11 19:08:04 2002 +0200
+++ b/MIMETypes.st Wed Sep 11 19:32:19 2002 +0200
@@ -1,6 +1,6 @@
"
COPYRIGHT (c) 1997 by eXept Software AG
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -15,12 +15,19 @@
"{ Package: 'stx:libview2' }"
Object subclass:#MIMETypes
- instanceVariableNames:''
- classVariableNames:'TypeToImageReaderClassMapping FileSuffixToTypeMapping
- FilenameToTypeMapping FileSuffixToImageReaderClassMapping
- CharSetToFontMapping LastSuffix LastType'
- poolDictionaries:''
- category:'System-Documentation'
+ instanceVariableNames:''
+ classVariableNames:'TypeToImageReaderClassMapping FileSuffixToTypeMapping
+ FilenameToTypeMapping FileSuffixToImageReaderClassMapping
+ CharSetToFontMapping LastSuffix LastType'
+ poolDictionaries:''
+ category:'System-Documentation'
+!
+
+String variableByteSubclass:#MIMEType
+ instanceVariableNames:''
+ classVariableNames:'CachedTypes'
+ poolDictionaries:''
+ privateIn:MIMETypes
!
!MIMETypes class methodsFor:'documentation'!
@@ -28,7 +35,7 @@
copyright
"
COPYRIGHT (c) 1997 by eXept Software AG
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -599,18 +606,7 @@
FilenameToTypeMapping isNil ifTrue:[
FilenameToTypeMapping := Dictionary new
].
- FilenameToTypeMapping at:filename put:mimeType asLowercase
-
-!
-
-mimeTypeForFilenameByContents:filenameArg
- "given a filename, return the mime-type or nil, if unknown"
-
- |type filename|
-
- filename := filenameArg asFilename.
-
- ^ type
+ FilenameToTypeMapping at:filename put:(MIMEType fromString:mimeType asLowercase)
!
mimeTypeForSuffix:suffix
@@ -639,6 +635,9 @@
type == #unknown ifTrue:[
type := nil
].
+ type notNil ifTrue:[
+ ^ MIMEType fromString:type
+ ].
^ type
"Created: / 30.6.1997 / 21:55:51 / cg"
@@ -665,12 +664,84 @@
mimeTypeOfContents:filename
"given a filename, scan the contents, return the mime-type or nil, if unknown"
- ^ filename mimeTypeOfContents.
+ |typeString|
+
+ typeString := filename mimeTypeOfContents.
+ typeString isNil ifTrue:[^ nil].
+ ^ MIMEType fromString:typeString.
+! !
+
+!MIMETypes::MIMEType class methodsFor:'documentation'!
+
+documentation
+"
+ like a string, but knows that it represents a mimeType
+"
+! !
+
+!MIMETypes::MIMEType class methodsFor:'initialization'!
+
+initialize
+ CachedTypes := CacheDictionary new:30.
+
+ "
+ self initialize
+ "
+! !
+
+!MIMETypes::MIMEType class methodsFor:'instance creation'!
+
+fromString:aString
+ |cachedType newType|
+
+ aString class == self ifTrue:[^ aString].
+
+ cachedType := CachedTypes at:aString ifAbsent:nil.
+ cachedType notNil ifTrue:[^ cachedType].
+ newType := aString copy changeClassTo:self.
+ CachedTypes at:aString put:newType.
+ ^ newType
+
+ "
+ self fromString:'text/html'
+ "
+! !
+
+!MIMETypes::MIMEType methodsFor:'queries'!
+
+isArchiv
+
+ |archivTypes|
+
+ archivTypes := MIMETypes applicationComprAndArchiveTypeList.
+ archivTypes pairWiseDo:[: ext : type |
+ self = type ifTrue:[ ^ true].
+ ].
+ ^ false
+!
+
+isHtml
+
+ ^ (self = 'text/html')
+!
+
+isImage
+
+ ^ (self startsWith:'image')
+!
+
+isPdf
+ ^ (self = 'application/pdf')
+!
+
+isSmalltalkSource
+
+ ^ (self = 'application/x-smalltalk-source')
! !
!MIMETypes class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.41 2002-09-11 17:08:04 penk Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.42 2002-09-11 17:32:19 penk Exp $'
! !
MIMETypes initialize!