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,23 +30,43 @@ 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 text that can be formatted using
*Structured Text* or *HTML*. Text can be automatically translated
through the use of 'message catalogs'.
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 can only contain role information.
File inherits from XMLObject and can be synchronized
accross multiple sites.
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'
......@@ -54,6 +74,7 @@ class File(XMLObject, CMFFile):
add_permission = Permissions.AddPortalContent
isPortalContent = 1
isRADContent = 1
__dav_collection__=0
# Declarative security
security = ClassSecurityInfo()
......@@ -62,13 +83,17 @@ class File(XMLObject, CMFFile):
# Default global values
content_type = '' # Required for WebDAV support (default value)
# Declarative properties
# Default Properties
property_sheets = ( PropertySheet.Base
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.Version
, PropertySheet.Reference
, PropertySheet.Document
, PropertySheet.Data
)
# Declarative interfaces
#__implements__ = ( , )
......@@ -105,11 +130,65 @@ class File(XMLObject, CMFFile):
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
getcontentlength = get_size
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
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
PUT = CMFFile.PUT
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
manage_FTPlist = CMFFile.manage_FTPlist
manage_FTPstat = CMFFile.manage_FTPstat
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