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 ...@@ -30,86 +30,165 @@ from AccessControl import ClassSecurityInfo
from Products.CMFCore.WorkflowCore import WorkflowMethod from Products.CMFCore.WorkflowCore import WorkflowMethod
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface 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.ERP5Type.Base import Base
from Products.CMFDefault.File import File as CMFFile from Products.CMFDefault.File import File as CMFFile
from zLOG import LOG 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 if kw.has_key('file'):
*Structured Text* or *HTML*. Text can be automatically translated file = kw.get('file')
through the use of 'message catalogs'. 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 security.declareProtected(Permissions.View, 'hasFile')
be synchronized accross multiple sites. 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' security.declarePrivate('_unpackData')
portal_type = 'File' def _unpackData(self,data):
add_permission = Permissions.AddPortalContent """
isPortalContent = 1 Unpack Pdata into string
isRADContent = 1 """
if isinstance(data, str):
# Declarative security return data
security = ClassSecurityInfo() else:
security.declareObjectProtected(Permissions.AccessContentsInformation) data_list = []
while data is not None:
# Default global values data_list.append(data.data)
content_type = '' # Required for WebDAV support (default value) data=data.next
return ''.join(data_list)
# Declarative properties
property_sheets = ( PropertySheet.Base security.declareProtected(Permissions.ModifyPortalContent, 'guessMimeType')
, PropertySheet.CategoryCore def guessMimeType(self, fname=''):
, PropertySheet.DublinCore """
, PropertySheet.Data get mime type from file name
) """
if fname == '': fname = self.getOriginalFilename()
# Declarative interfaces if fname:
#__implements__ = ( , ) content_type,enc = mimetypes.guess_type(fname)
if content_type is not None:
### Special edit method self.content_type = content_type
security.declarePrivate( '_edit' ) return content_type
def _edit(self, **kw):
"""\ security.declareProtected(Permissions.ModifyPortalContent,'PUT')
This is used to edit files def PUT(self,REQUEST,RESPONSE):
""" CMFFile.PUT(self,REQUEST,RESPONSE)
if kw.has_key('file'): self.DMS_ingestFile(fname=self.getId()) # XXX-JPS we should call here Document_discoverMetadata
file = kw.get('file') # with the filename as parameter
precondition = kw.get('precondition')
if self._isNotEmpty(file): # DAV Support
CMFFile._edit(self, precondition=precondition, file=file) index_html = CMFFile.index_html # XXX-JPS - Here we have a security issue - ask seb what to do
del kw['file'] PUT = CMFFile.PUT # XXX-JPS - Here we have a security issue - ask seb what to do
Base._edit(self, **kw) 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
security.declareProtected( Permissions.ModifyPortalContent, 'edit' ) manage_FTPlist = CMFFile.manage_FTPlist # XXX-JPS - Here we have a security issue - ask seb what to do
edit = WorkflowMethod( _edit ) manage_FTPstat = CMFFile.manage_FTPstat # XXX-JPS - Here we have a security issue - ask seb what to do
# Copy support needs to be implemented by ExtFile # vim: syntax=python shiftwidth=2
################################
# 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
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