• Nicolas Delaby's avatar
    Conversion from html to odt was working only by chance. · 11f80857
    Nicolas Delaby authored
    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
    11f80857
odt_to_xml.py 1.19 KB
# -*- coding: utf-8 -*-
from Products.PortalTransforms.interfaces import itransform
from zope.interface import implements
from oood_commandtransform import OOOdCommandTransform, OOoDocumentDataStream
from zLOG import LOG
from Products.ERP5OOo.OOoUtils import OOoBuilder
import re

class OdtToXml:
  """Transforms ODT to Doc by using oood"""

  implements(itransform)

  __name__ = 'odt_to_xml'
  inputs   = ('application/vnd.oasis.opendocument.text',)
  output = 'text/xml'

  tranform_engine = OOOdCommandTransform.__module__

  def name(self):
    return self.__name__

  def __getattr__(self, attr):
    if attr == 'inputs':
      return self.config['inputs']
    if attr == 'output':
      return self.config['output']
    raise AttributeError(attr)

  def convert(self, orig, data, cache=None, filename=None, context=None, **kwargs):
    data = str(orig)
    doc = OOOdCommandTransform(context, filename, data, self.inputs[0])
    builder = OOoBuilder(doc)
    content = builder.extract('content.xml')
    if cache is not None:
      cache.setData(content)
      return cache
    else:
      stream = OOoDocumentDataStream()
      stream.setData(content)
      return stream

def register():
  return OdtToXml()