Commit 11f80857 authored by Nicolas Delaby's avatar Nicolas Delaby

Conversion from html to odt was working only by chance.

because convertToBaseFormat was not able to import html.
Now OOoDocument is able to successfully convertToBaseFormat html content (or any other),
thanks to content_type parameter which is now given to conversion tool.
Previous implementation was storing html content into
base_data instead of data, but convertToBaseFormat was never called.

* The method convert on oood_commandtransform was useless.
* Call convertToBaseFormat once temp_document is created




git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39049 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ed3f2c35
...@@ -45,7 +45,6 @@ class HTMLToOdt: ...@@ -45,7 +45,6 @@ class HTMLToOdt:
orig = html.tostring(html_tree, encoding='utf-8') orig = html.tostring(html_tree, encoding='utf-8')
doc = OOOdCommandTransform(context, filename, orig, self.inputs[0]) doc = OOOdCommandTransform(context, filename, orig, self.inputs[0])
doc.convert()
odt = doc.convertTo('odt') odt = doc.convertTo('odt')
if cache is not None: if cache is not None:
cache.setData(odt) cache.setData(odt)
......
# -*- coding: utf-8 -*-
from Products.PortalTransforms.interfaces import itransform from Products.PortalTransforms.interfaces import itransform
from zope.interface import implements from zope.interface import implements
from oood_commandtransform import OOOdCommandTransform, OOoDocumentDataStream from oood_commandtransform import OOOdCommandTransform, OOoDocumentDataStream
...@@ -28,7 +29,6 @@ class OdtToDoc: ...@@ -28,7 +29,6 @@ class OdtToDoc:
def convert(self, orig, data, cache=None, filename=None, context=None, **kwargs): def convert(self, orig, data, cache=None, filename=None, context=None, **kwargs):
data = str(orig) data = str(orig)
doc = OOOdCommandTransform(context, filename, data, self.inputs[0]) doc = OOOdCommandTransform(context, filename, data, self.inputs[0])
doc.convert()
msword = doc.convertTo('doc') msword = doc.convertTo('doc')
if cache is not None: if cache is not None:
cache.setData(msword) cache.setData(msword)
......
# -*- coding: utf-8 -*-
from Products.PortalTransforms.interfaces import itransform from Products.PortalTransforms.interfaces import itransform
from zope.interface import implements from zope.interface import implements
from oood_commandtransform import OOOdCommandTransform, OOoDocumentDataStream from oood_commandtransform import OOOdCommandTransform, OOoDocumentDataStream
...@@ -28,7 +29,6 @@ class OdtToPdf: ...@@ -28,7 +29,6 @@ class OdtToPdf:
def convert(self, orig, data, cache=None, filename=None, context=None, **kwargs): def convert(self, orig, data, cache=None, filename=None, context=None, **kwargs):
data = str(orig) data = str(orig)
doc = OOOdCommandTransform(context, filename, data, self.inputs[0]) doc = OOOdCommandTransform(context, filename, data, self.inputs[0])
doc.convert()
pdf = doc.convertTo('pdf') pdf = doc.convertTo('pdf')
if cache is not None: if cache is not None:
cache.setData(pdf) cache.setData(pdf)
......
# -*- coding: utf-8 -*-
from Products.PortalTransforms.interfaces import itransform from Products.PortalTransforms.interfaces import itransform
from zope.interface import implements from zope.interface import implements
from oood_commandtransform import OOOdCommandTransform, OOoDocumentDataStream from oood_commandtransform import OOOdCommandTransform, OOoDocumentDataStream
...@@ -29,7 +30,6 @@ class OdtToXml: ...@@ -29,7 +30,6 @@ class OdtToXml:
def convert(self, orig, data, cache=None, filename=None, context=None, **kwargs): def convert(self, orig, data, cache=None, filename=None, context=None, **kwargs):
data = str(orig) data = str(orig)
doc = OOOdCommandTransform(context, filename, data, self.inputs[0]) doc = OOOdCommandTransform(context, filename, data, self.inputs[0])
doc.convert()
builder = OOoBuilder(doc) builder = OOoBuilder(doc)
content = builder.extract('content.xml') content = builder.extract('content.xml')
if cache is not None: if cache is not None:
......
...@@ -68,7 +68,14 @@ class OOOdCommandTransform(commandtransform): ...@@ -68,7 +68,14 @@ class OOOdCommandTransform(commandtransform):
self.context = context self.context = context
if self.mimetype == 'text/html': if self.mimetype == 'text/html':
data = self.includeExternalCssList(data) data = self.includeExternalCssList(data)
self.data = data tmp_ooo = newTempOOoDocument(context, name)
tmp_ooo.edit( data=data,
fname=self.name(),
source_reference=self.name(),
filename=self.name(),
content_type=self.mimetype,)
tmp_ooo.convertToBaseFormat()
self.ooo = tmp_ooo
def name(self): def name(self):
return self.__name__ return self.__name__
...@@ -186,18 +193,6 @@ class OOOdCommandTransform(commandtransform): ...@@ -186,18 +193,6 @@ class OOOdCommandTransform(commandtransform):
return etree.tostring(xml_doc, encoding='utf-8', return etree.tostring(xml_doc, encoding='utf-8',
xml_declaration=False, pretty_print=False, ) xml_declaration=False, pretty_print=False, )
def convert(self):
tmp_ooo = newTempOOoDocument(self.context, self.name())
# XXX We store the same content inside data and base_data
# otherwise conversion server fails to convert html=>odt for example.
# deeper investigation is required inside oood to understand this issue.
tmp_ooo.edit( base_data=self.data,
fname=self.name(),
source_reference=self.name(),
base_content_type=self.mimetype,
content_type=self.mimetype,)
self.ooo = tmp_ooo
def convertTo(self, format): def convertTo(self, format):
if self.ooo.isTargetFormatAllowed(format): if self.ooo.isTargetFormatAllowed(format):
mime, data = self.ooo.convert(format) mime, data = self.ooo.convert(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