Mime Type class inherited from string
authorpenk
Wed, 11 Sep 2002 14:52:31 +0200
changeset 1608 2708d3ca0b56
parent 1607 432b696242ea
child 1609 090ee7aa4cab
Mime Type class inherited from string has his own protocoll
MIMEType.st
--- a/MIMEType.st	Wed Sep 11 14:50:38 2002 +0200
+++ b/MIMEType.st	Wed Sep 11 14:52:31 2002 +0200
@@ -1,60 +1,37 @@
 "{ Package: 'stx:libview2' }"
 
-MIMETypes subclass:#MIMEType
-	instanceVariableNames:'fileName mimeType'
-	classVariableNames:''
-	poolDictionaries:''
-	category:'System-Documentation'
+String variableByteSubclass:#MIMEType
+        instanceVariableNames:''
+        classVariableNames:'CachedTypes'
+        poolDictionaries:''
+        category:'System-Documentation'
 !
 
 
+!MIMEType class methodsFor:'initialization'!
+
+initialize
+    CachedTypes := CacheDictionary new:30.
+
+    "
+     self initialize
+    "
+! !
+
 !MIMEType class methodsFor:'instance creation'!
 
-for:fileName
-
-    | instance |
-
-    instance := self basicNew.
-    instance fileName:fileName.
-    ^ instance.
-! !
-
-!MIMEType methodsFor:'accessing'!
-
-fileName
-    "return the value of the instance variable 'fileName' (automatically generated)"
-
-    ^ fileName
-!
-
-fileName:something
-    "set the value of the instance variable 'fileName' (automatically generated)"
-
-    fileName := something.
-!
+fromString:aString
+    |cachedType newType|
 
-mimeType
-    "return the value of the instance variable 'mimeType' (automatically generated)"
-
-    mimeType isNil ifTrue:[
-        mimeType := self mimeTypeBySuffix.
-    ].
-    ^ mimeType
-!
+    cachedType := CachedTypes at:aString ifAbsent:nil.
+    cachedType notNil ifTrue:[^ cachedType].
+    newType := aString copy changeClassTo:self.
+    CachedTypes at:aString put:newType.
+    ^ newType
 
-mimeTypeByContents
-    "return the value of the instance variable 'mimeTypeByContents' (automatically generated)"
-
-    ^ nil
-!
-
-mimeTypeBySuffix
-    "return the value of the instance variable 'mimeType' (automatically generated)"
-
-    mimeType isNil ifTrue:[
-        mimeType := self class mimeTypeForSuffix:(self fileName suffix).
-    ].
-    ^ mimeType
+    "
+     self fromString:'text/html'
+    "
 ! !
 
 !MIMEType methodsFor:'queries'!
@@ -66,31 +43,28 @@
     mimeType isNil ifTrue:[^ false].
     archivTypes := self class applicationComprAndArchiveTypeList.
     archivTypes pairWiseDo:[: ext : type |
-        type = mimeType ifTrue:[ ^ true].
+        self = type ifTrue:[ ^ true].
     ].
     ^ false
 !
 
 isHtml
 
-    self mimeType isNil ifTrue:[^ false].
-    ^ (mimeType = 'text/html')
+    ^ (self = 'text/html')
 !
 
 isImage
 
-    self mimeType isNil ifTrue:[^ false].
-    ^ (mimeType startsWith:'image')
+    ^ (self startsWith:'image')
 !
 
 isPdf
-
-    self mimeType isNil ifTrue:[^ false].
-    ^ (mimeType = 'application/pdf')
+    ^ (self = 'application/pdf')
 ! !
 
 !MIMEType class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/Attic/MIMEType.st,v 1.2 2002-09-10 14:22:23 penk Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/Attic/MIMEType.st,v 1.3 2002-09-11 12:52:31 penk Exp $'
 ! !
+MIMEType initialize!