Commit 54d5ed84 authored by Jean-Paul Smets's avatar Jean-Paul Smets

conversion API changed

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13052 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2ce54635
...@@ -26,16 +26,17 @@ ...@@ -26,16 +26,17 @@
############################################################################## ##############################################################################
import xmlrpclib import xmlrpclib
from xmlrpclib import Fault
import base64 import base64
import re import re
import zipfile import zipfile
import cStringIO import cStringIO
import socket
from DateTime import DateTime from DateTime import DateTime
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from OFS.Image import Pdata from OFS.Image import Pdata
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
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.Message import Message from Products.ERP5Type.Message import Message
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
...@@ -87,6 +88,9 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -87,6 +88,9 @@ class OOoDocument(File, ConversionCacheMixin):
- to stored pure images (use Image for that) - to stored pure images (use Image for that)
- as a general file conversion system (use portal_transforms for that) - as a general file conversion system (use portal_transforms for that)
TODO:
- better permissions
""" """
# CMF Type Definition # CMF Type Definition
meta_type = 'ERP5 OOo Document' meta_type = 'ERP5 OOo Document'
...@@ -173,7 +177,7 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -173,7 +177,7 @@ class OOoDocument(File, ConversionCacheMixin):
adr = pref.getPreferredOoodocServerAddress() adr = pref.getPreferredOoodocServerAddress()
nr = pref.getPreferredOoodocServerPortNumber() nr = pref.getPreferredOoodocServerPortNumber()
if adr is None or nr is None: if adr is None or nr is None:
raise Exception('you should set conversion server coordinates in preferences') raise ConversionError('You should set conversion server coordinates in preferences')
return adr, nr return adr, nr
def _mkProxy(self): def _mkProxy(self):
...@@ -184,30 +188,34 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -184,30 +188,34 @@ class OOoDocument(File, ConversionCacheMixin):
""" """
code > 0 indicates a problem code > 0 indicates a problem
we distinguish data return from message by checking if it is a tuple we distinguish data return from message by checking if it is a tuple
XXX - This is an error. UI translation is the responsability
of skins (scripts of page templates).
""" """
m = Message(domain='ui', message=msg) m = Message(domain='ui', message=msg)
return (code, m) return (code, m)
security.declareProtected(Permissions.View, 'convert') security.declareProtected(Permissions.View, 'convert')
def convertToBase(self, force=0, REQUEST=None): def convertToBase(self, REQUEST=None):
""" """
Converts from the initial format to base format (ODF); Converts from the initial format to base format (ODF);
communicates with the conversion server communicates with the conversion server
and gets converted file as well as metadata and gets converted file as well as metadata
""" """
def doConvert(force):
if force == 0 and self.hasOOFile():
return self.returnMessage('OOo file is up do date', 1)
try: try:
self._convertToBase() self._convertToBase()
except Exception, e: msg = 'Converted to Open Document Format.'
return self.returnMessage('Problem: %s' % (str(e) or 'undefined'), 2) self.convertFile(comment=msg) # Invoke workflow method
return self.returnMessage('converted to Open Document Format') except ConversionError, e:
msg_ob = doConvert(force) msg = 'Problem: %s' % (str(e) or 'undefined.')
msg = str(msg_ob[1]) self.processFile(comment=msg)
portal_workflow = getToolByName(self, 'portal_workflow') except Fault, e:
portal_workflow.doActionFor(self, 'process', comment=msg) msg = 'Problem: %s' % (repr(e) or 'undefined.')
return msg_ob self.processFile(comment=msg)
except socket.error, e:
msg = 'Problem: %s' % (repr(e) or 'undefined.')
self.processFile(comment=msg)
return msg
security.declareProtected(Permissions.AccessContentsInformation,'getTargetFormatList') security.declareProtected(Permissions.AccessContentsInformation,'getTargetFormatList')
def getTargetFormatItemList(self): def getTargetFormatItemList(self):
...@@ -239,6 +247,8 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -239,6 +247,8 @@ class OOoDocument(File, ConversionCacheMixin):
def reset(self): def reset(self):
""" """
make the object a non-converted one, as if it was brand new make the object a non-converted one, as if it was brand new
XXX-JPS more explicit name needed
""" """
self.clearConversionCache() self.clearConversionCache()
self.oo_data = None self.oo_data = None
...@@ -252,6 +262,8 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -252,6 +262,8 @@ class OOoDocument(File, ConversionCacheMixin):
""" """
Checks if the current document can be converted Checks if the current document can be converted
into the specified format. into the specified format.
XXX-JPS more explicit name needed
""" """
allowed = self.getTargetFormatItemList() allowed = self.getTargetFormatItemList()
if allowed is None: return False if allowed is None: return False
...@@ -469,6 +481,8 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -469,6 +481,8 @@ class OOoDocument(File, ConversionCacheMixin):
TODO: TODO:
* support of images in html conversion (as subobjects for example) * support of images in html conversion (as subobjects for example)
XXX-JPS more explicit name needed for method
""" """
if not self.isAllowed(format): if not self.isAllowed(format):
errstr = '%s format is not supported' % format errstr = '%s format is not supported' % format
......
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