Bugfix webdav. CF bug #1071431 sur launchpad.net.
[Plinn.git] / File.py
diff --git a/File.py b/File.py
index c0e37c7..dfb22c4 100755 (executable)
--- a/File.py
+++ b/File.py
@@ -21,8 +21,8 @@
        File. If exists, portal_transforms is called to extract text content, and publish
        attachments.
 
-$Id: File.py 1549 2010-02-04 13:04:22Z pin $
-$URL: http://svn.cri.ensmp.fr/svn/Plinn/branches/CMF-2.1/File.py $
+
+
 """
 
 from Globals import InitializeClass
@@ -30,22 +30,55 @@ from AccessControl import ClassSecurityInfo
 import OFS
 from zope.component.factory import Factory
 
-from Products.CMFDefault.File import File as BaseFile
+from Products.CMFDefault.File import File as CMFFile
+from Products.Photo.blobbases import File as BlobFile
+from Products.CMFDefault.DublinCore import DefaultDublinCoreImpl
 from Products.CMFCore.permissions import View, ModifyPortalContent
 from Products.CMFCore.utils import getToolByName
-from swfheader import parse as parseswf
+from hexagonit.swfheader import parse as parseswf
 
-class File(BaseFile) :
+class File(BlobFile, CMFFile) :
+#class File(CMFFile) :
        """ file class with portal_transforms support """
        
        security = ClassSecurityInfo()
        
-       _properties = BaseFile._properties + ({'id':'orig_name', 'type':'string', 'mode':'w', 'label':"Original Name"},)
+       _properties = CMFFile._properties + ({'id':'orig_name', 'type':'string', 'mode':'w', 'label':"Original Name"},)
        orig_name = ''
 
+       def __init__( self
+                               , id
+                               , title=''
+                               , file=''
+                               , content_type=''
+                               , precondition=''
+                               , subject=()
+                               , description=''
+                               , contributors=()
+                               , effective_date=None
+                               , expiration_date=None
+                               , format=None
+                               , language='en-US'
+                               , rights=''
+                               ):
+               BlobFile.__init__(self, id, title, file, content_type=content_type, precondition=precondition)
+               self._setId(id)
+               #delattr(self, '__name__')
+        #
+               # If no file format has been passed in, rely on what OFS.Image.File
+               # detected. Unlike Images, which have code to try and pick the content
+               # type out of the binary data, File objects only provide the correct
+               # type if a "hint" in the form of a filename extension is given.
+               if format is None:
+                       format = self.content_type 
+        
+               DefaultDublinCoreImpl.__init__( self, title, subject, description
+                                                          , contributors, effective_date, expiration_date
+                                                          , format, language, rights )
+
 
        def __getattr__(self, name) :
-               try : return BaseFile.__getattr__(self, name)
+               try : return CMFFile.__getattr__(self, name)
                except :
                        selfAttrs = self.__dict__
                        if selfAttrs.has_key('_v_transform_cache') :
@@ -54,10 +87,10 @@ class File(BaseFile) :
                                if cacheTuple :
                                        cacheData = cacheTuple[1]
                                
-                               subObDict = cacheData.getSubObjects()
-                               if subObDict.has_key(name) :
-                                       fileOb = OFS.Image.File(name, name, subObDict[name])
-                                       return fileOb
+                                       subObDict = cacheData.getSubObjects()
+                                       if subObDict.has_key(name) :
+                                               fileOb = OFS.Image.File(name, name, subObDict[name])
+                                               return fileOb
                                
                        raise AttributeError, name
        
@@ -92,7 +125,7 @@ class File(BaseFile) :
                orig_name = OFS.Image.cookId('', '', file)[0]
                if orig_name :
                        self.orig_name = orig_name
-               BaseFile.edit(self, precondition=precondition, file=file)
+               CMFFile.edit(self, precondition=precondition, file=file)
                if hasattr(self, '_v_transform_cache') :
                        del self._v_transform_cache
        
@@ -100,15 +133,18 @@ class File(BaseFile) :
        security.declareProtected(View, 'SearchableText')
        def SearchableText(self) :
                """ Return full text"""
-               baseSearchableText = BaseFile.SearchableText(self)
+               baseSearchableText = CMFFile.SearchableText(self)
                transformTool = getToolByName(self, 'portal_transforms', default=None)
                if transformTool is None :
                        return baseSearchableText
                else :
+                       f = self.bdata.open()
+                       orig = f.read()
                        datastream_text =  transformTool.convertTo('text/plain',
-                                                                                                               str(self.data),
+                                                                                                               orig,
                                                                                                                mimetype = self.content_type
                                                                                                                )
+                       f.close()
                        full_text = ''
                        if datastream_text is not None :
                                full_text = datastream_text.getData()
@@ -123,12 +159,14 @@ class File(BaseFile) :
                        return ''
                else :
                        filename = self.getId().replace(' ', '_')
+                       f = self.bdata.open()
+                       orig = f.read()
                        datastream = transformTool.convertTo('text/html',
-                                                                                               str(self.data),
+                                                                                               orig,
                                                                                                object=self,
                                                                                                mimetype = self.content_type,
                                                                                                filename = filename)
-
+                       f.close()
                        if datastream is not None : return datastream.getData()
                        else : return ''
 
@@ -156,10 +194,12 @@ class File(BaseFile) :
                """
                regTool = getToolByName(self, 'mimetypes_registry', default=None)
                if regTool :
-                       mime = regTool(str(self.data), mimetype=self.content_type)[2]
+                       f = self.bdata.open()
+                       mime = regTool(f, mimetype=self.content_type)[2]
+                       f.close()
                        return mime.icon_path
                else :
-                       return BaseFile.getIcon(self, relative_to_portal=relative_to_portal)
+                       return CMFFile.getIcon(self, relative_to_portal=relative_to_portal)
 
 
 InitializeClass(File)