Commit 84f326f2 authored by Thibaut Deheunynck's avatar Thibaut Deheunynck

Now the method getSourceCode uses portal transforms if it exists otherwise we...

Now the method getSourceCode uses portal transforms if it exists otherwise we return the source code itself without conversion. We use portal_transform in order to transform python script to html if the portal skin is View or to xml if the portal skin is ODT. If the portal skin is ODT so we have the content.xml from the odt file and parse this file to retreive the adéquate code

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24249 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6312a6c9
...@@ -31,6 +31,14 @@ from AccessControl import ClassSecurityInfo ...@@ -31,6 +31,14 @@ from AccessControl import ClassSecurityInfo
from Globals import InitializeClass from Globals import InitializeClass
from DocumentationHelper import DocumentationHelper from DocumentationHelper import DocumentationHelper
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.CMFCore.utils import getToolByName
try:
from libxml2 import parseDoc, parserError
import_succeed = 1
except ImportError:
from xml.dom.minidom import parseString
from xml.xpath import Evaluate
import_succeed = 0
class PortalTypePropertySheetDocumentationHelper(DocumentationHelper): class PortalTypePropertySheetDocumentationHelper(DocumentationHelper):
""" """
...@@ -75,20 +83,53 @@ class PortalTypePropertySheetDocumentationHelper(DocumentationHelper): ...@@ -75,20 +83,53 @@ class PortalTypePropertySheetDocumentationHelper(DocumentationHelper):
if property_sheet_file is not None: if property_sheet_file is not None:
property_sheet_file.seek(0) property_sheet_file.seek(0)
source_code = property_sheet_file.read() source_code = property_sheet_file.read()
portal_transforms = getattr(self, 'portal_transforms', None) portal_transforms = getToolByName(self, 'portal_transforms')
if portal_transforms is not None: REQUEST = getattr(self, 'REQUEST', None)
REQUEST = getattr(self, 'REQUEST', None) if REQUEST is not None:
if REQUEST is not None: view_mode = REQUEST.get('portal_skin', 'View' )
if REQUEST.get('portal_skin', 'View' ) != 'View': if portal_transforms is None:
return source_code
else:
LOG('DCWorkflowScriptDocumentationHelper', INFO, LOG('DCWorkflowScriptDocumentationHelper', INFO,
'Transformation Tool is not installed. No convertion of python script to html') 'Transformation Tool is not installed. No convertion of python script to html')
return source_code return source_code
src_mimetype='text/x-python' else:
mime_type = 'text/html' if view_mode == 'View':
source_html = portal_transforms.convertTo(mime_type, source_code, mimetype = src_mimetype) src_mimetype = 'text/x-python'
return source_html.getData() mime_type = 'text/html'
source_html = portal_transforms.convertTo(mime_type, source_code, mimetype=src_mimetype)
return source_html
else:
src_mimetype = 'text/x-python'
mime_type = 'text/xml'
source_xml = portal_transforms.convertToData(mime_type, source_code,
mimetype=src_mimetype,
context=self, object=self,
filename=self.title_or_id()
)
xpath = '//*[name() = "office:text"]//*[name() = "text:p"]'
if import_succeed:
#libxml2
# parse content.xml
xml_doc = parseDoc(source_xml)
# the name space text
text_ns = xml_doc.getRootElement().searchNs(xml_doc, 'text')
# all element text:p
text_list = xml_doc.xpathEval(xpath)
# all element wich have an text:style-name attribut
parent_tag_list = xml_doc.xpathEval('//*[@*[name() = "text:style-name"]]')
# Change the attribut text:style-name with a default value
[parent_tag.setNsProp(text_ns, 'style-name', 'Preformatted_20_Text') \
for parent_tag in parent_tag_list]
xml = ''.join([text.serialize('utf-8', 0) for text in text_list])
xml_doc.freeDoc()
return xml
else:
# minidom
xml_doc = parseString(source_xml)
tag_list = Evaluate (xpath , xml_doc)
xml = ''.join(tag.toxml('utf-8') for tag in tag_list)
return xml
else:
return source_code
......
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