Commit 4b448f8a authored by Jean-Paul Smets's avatar Jean-Paul Smets

Early refactoring of document related classes.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11807 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 35f0ca7a
This diff is collapsed.
......@@ -30,86 +30,165 @@ from AccessControl import ClassSecurityInfo
from Products.CMFCore.WorkflowCore import WorkflowMethod
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.Cache import CachingMethod
from Products.ERP5.Document.Document import Document
from Products.ERP5Type.Base import Base
from Products.CMFDefault.File import File as CMFFile
from zLOG import LOG
class File(XMLObject, CMFFile):
import mimetypes, re
from DateTime import DateTime
mimetypes.init()
rs=[]
rs.append(re.compile('<HEAD>.*</HEAD>',re.DOTALL|re.MULTILINE|re.IGNORECASE))
rs.append(re.compile('<!DOCTYPE[^>]*>'))
rs.append(re.compile('<.?(HTML|BODY)[^>]*>',re.DOTALL|re.MULTILINE|re.IGNORECASE))
def stripHtml(txt): # XXX-JPS to be moved to TextDocument
for r in rs:
txt=r.sub('',txt)
return txt
class File(Document, CMFFile):
"""
A File can contain raw data which can be uploaded and downloaded.
It is the root class of Image, OOoDocument (ERP5OOo product),
etc. The main purpose of the File class is to handle efficiently
large files. It uses Pdata from OFS.File for this purpose.
File inherits from XMLObject and can be synchronized
accross multiple sites.
Subcontent: File can only contain role information.
TODO:
* make sure ZODB BLOBS are supported to prevent
feeding the ZODB cache with unnecessary large data
"""
meta_type = 'ERP5 File'
portal_type = 'File'
add_permission = Permissions.AddPortalContent
isPortalContent = 1
isRADContent = 1
__dav_collection__=0
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# Default global values
content_type = '' # Required for WebDAV support (default value)
# Default Properties
property_sheets = ( PropertySheet.Base
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.Version
, PropertySheet.Reference
, PropertySheet.Document
, PropertySheet.Data
)
# Declarative interfaces
#__implements__ = ( , )
### Special edit method
security.declarePrivate( '_edit' )
def _edit(self, **kw):
"""\
This is used to edit files
"""
A File can contain text that can be formatted using
*Structured Text* or *HTML*. Text can be automatically translated
through the use of 'message catalogs'.
if kw.has_key('file'):
file = kw.get('file')
precondition = kw.get('precondition')
if self._isNotEmpty(file):
CMFFile._edit(self, precondition=precondition, file=file)
del kw['file']
Base._edit(self, **kw)
security.declareProtected( Permissions.ModifyPortalContent, 'edit' )
edit = WorkflowMethod( _edit )
# Copy support needs to be implemented by ExtFile
################################
# Special management methods #
################################
def manage_afterClone(self, item):
Base.manage_afterClone(self, item)
CMFFile.manage_afterClone(self, item)
def manage_afterAdd(self, item, container):
Base.manage_afterAdd(self, item, container)
CMFFile.manage_afterAdd(self, item, container)
def manage_beforeDelete(self, item, container):
CMFFile.manage_beforeDelete(self, item, container)
def get_size(self):
"""
has to be overwritten here, otherwise WebDAV fails
"""
try:
return len(self.data)
except (AttributeError, TypeError):
return 0
File can only contain role information.
getcontentlength = get_size
File inherits from XMLObject and can
be synchronized accross multiple sites.
security.declareProtected(Permissions.View, 'hasFile')
def hasFile(self):
"""
Checks whether we have an initial file
"""
_marker = []
if getattr(self,'data', _marker) is not _marker: # XXX-JPS - use propertysheet accessors
return getattr(self,'data') is not None
return False
meta_type = 'ERP5 File'
portal_type = 'File'
add_permission = Permissions.AddPortalContent
isPortalContent = 1
isRADContent = 1
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# Default global values
content_type = '' # Required for WebDAV support (default value)
# Declarative properties
property_sheets = ( PropertySheet.Base
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.Data
)
# Declarative interfaces
#__implements__ = ( , )
### Special edit method
security.declarePrivate( '_edit' )
def _edit(self, **kw):
"""\
This is used to edit files
"""
if kw.has_key('file'):
file = kw.get('file')
precondition = kw.get('precondition')
if self._isNotEmpty(file):
CMFFile._edit(self, precondition=precondition, file=file)
del kw['file']
Base._edit(self, **kw)
security.declareProtected( Permissions.ModifyPortalContent, 'edit' )
edit = WorkflowMethod( _edit )
# Copy support needs to be implemented by ExtFile
################################
# Special management methods #
################################
def manage_afterClone(self, item):
Base.manage_afterClone(self, item)
CMFFile.manage_afterClone(self, item)
def manage_afterAdd(self, item, container):
Base.manage_afterAdd(self, item, container)
CMFFile.manage_afterAdd(self, item, container)
def manage_beforeDelete(self, item, container):
CMFFile.manage_beforeDelete(self, item, container)
# DAV Support
index_html = CMFFile.index_html
PUT = CMFFile.PUT
security.declareProtected('FTP access', 'manage_FTPget', 'manage_FTPstat', 'manage_FTPlist')
manage_FTPget = CMFFile.manage_FTPget
manage_FTPlist = CMFFile.manage_FTPlist
manage_FTPstat = CMFFile.manage_FTPstat
security.declarePrivate('_unpackData')
def _unpackData(self,data):
"""
Unpack Pdata into string
"""
if isinstance(data, str):
return data
else:
data_list = []
while data is not None:
data_list.append(data.data)
data=data.next
return ''.join(data_list)
security.declareProtected(Permissions.ModifyPortalContent, 'guessMimeType')
def guessMimeType(self, fname=''):
"""
get mime type from file name
"""
if fname == '': fname = self.getOriginalFilename()
if fname:
content_type,enc = mimetypes.guess_type(fname)
if content_type is not None:
self.content_type = content_type
return content_type
security.declareProtected(Permissions.ModifyPortalContent,'PUT')
def PUT(self,REQUEST,RESPONSE):
CMFFile.PUT(self,REQUEST,RESPONSE)
self.DMS_ingestFile(fname=self.getId()) # XXX-JPS we should call here Document_discoverMetadata
# with the filename as parameter
# DAV Support
index_html = CMFFile.index_html # XXX-JPS - Here we have a security issue - ask seb what to do
PUT = CMFFile.PUT # XXX-JPS - Here we have a security issue - ask seb what to do
security.declareProtected('FTP access', 'manage_FTPget', 'manage_FTPstat', 'manage_FTPlist')
manage_FTPget = CMFFile.manage_FTPget # XXX-JPS - Here we have a security issue - ask seb what to do
manage_FTPlist = CMFFile.manage_FTPlist # XXX-JPS - Here we have a security issue - ask seb what to do
manage_FTPstat = CMFFile.manage_FTPstat # XXX-JPS - Here we have a security issue - ask seb what to do
# vim: syntax=python shiftwidth=2
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment