From e509082598477edce0b6c681697eded71c21de85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20G=C3=B3rny?= <bartek@gorny.edu.pl> Date: Thu, 9 Nov 2006 15:11:27 +0000 Subject: [PATCH] add serPropertyListFromContent method git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11233 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5OOo/Document/OOoDocument.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/product/ERP5OOo/Document/OOoDocument.py b/product/ERP5OOo/Document/OOoDocument.py index 276b51442a..f3ee39a6d1 100644 --- a/product/ERP5OOo/Document/OOoDocument.py +++ b/product/ERP5OOo/Document/OOoDocument.py @@ -106,6 +106,8 @@ class OOoDocument(DMSFile, CachingMixin): , PropertySheet.OOoDocument ) + # regexp for finding attrs in content + rx_atr=re.compile('([\w]+)###([\w/]+)') # regexps for stripping xml from docs rx_strip=re.compile('<[^>]*?>',re.DOTALL|re.MULTILINE) rx_compr=re.compile('\s+') @@ -243,6 +245,26 @@ class OOoDocument(DMSFile, CachingMixin): z.close() return s + security.declareProtected(Permissions.ModifyPortalContent,'setPropertyListFromContent') + def setPropertyListFromContent(self,data): + cs=cStringIO.StringIO() + cs.write(self._unpackData(data)) + try: + z=zipfile.ZipFile(cs) + except zipfile.BadZipfile: + cs.close() + return + s=z.read('content.xml') + cs.close() + z.close() + atrs=dict(self.rx_atr.findall(s)) + doctype=atrs.get('doctype','None') + if doctype!=self.getPortalType(): + raise Exception('portal type mismatch - content gave %s, I have %s' % (doctype,self.getPortalType())) + for a in atrs: + if a not in ('author','doctype'): + self.setProperty(a,atrs[a]) + security.declarePrivate('_setMetaData') def _setMetaData(self,meta): """ -- 2.30.9