[Erp5-report] r24249 - /erp5/trunk/products/ERP5Type/DocumentationHelper/

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Oct 20 14:27:48 CEST 2008


Author: thibaut
Date: Mon Oct 20 14:27:38 2008
New Revision: 24249

URL: http://svn.erp5.org?rev=24249&view=rev
Log:
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

Modified:
    erp5/trunk/products/ERP5Type/DocumentationHelper/PortalTypePropertySheetDocumentationHelper.py

Modified: erp5/trunk/products/ERP5Type/DocumentationHelper/PortalTypePropertySheetDocumentationHelper.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/DocumentationHelper/PortalTypePropertySheetDocumentationHelper.py?rev=24249&r1=24248&r2=24249&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/DocumentationHelper/PortalTypePropertySheetDocumentationHelper.py (original)
+++ erp5/trunk/products/ERP5Type/DocumentationHelper/PortalTypePropertySheetDocumentationHelper.py Mon Oct 20 14:27:38 2008
@@ -31,6 +31,14 @@
 from Globals import InitializeClass
 from DocumentationHelper import DocumentationHelper
 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):
   """
@@ -75,20 +83,53 @@
     if property_sheet_file is not None:
       property_sheet_file.seek(0)
       source_code = property_sheet_file.read()
-      portal_transforms = getattr(self, 'portal_transforms', None)
-      if portal_transforms is not None:
-        REQUEST = getattr(self, 'REQUEST', None)
-        if REQUEST is not None:
-          if REQUEST.get('portal_skin', 'View' ) != 'View':
-            return source_code
-      else:
+      portal_transforms = getToolByName(self, 'portal_transforms')
+      REQUEST = getattr(self, 'REQUEST', None)
+      if REQUEST is not None:
+        view_mode = REQUEST.get('portal_skin', 'View' )
+      if portal_transforms is None:
         LOG('DCWorkflowScriptDocumentationHelper', INFO,
             'Transformation Tool is not installed. No convertion of python script to html')
         return source_code
-    src_mimetype='text/x-python'
-    mime_type = 'text/html'
-    source_html = portal_transforms.convertTo(mime_type, source_code, mimetype = src_mimetype)
-    return source_html.getData()
+      else:
+        if view_mode == 'View':
+          src_mimetype = 'text/x-python'
+          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
 
 
 




More information about the Erp5-report mailing list