From cbcc6be825a3c9f9b9d1f5691ffc67d7da739f84 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bartek=20G=C3=B3rny?= <bartek@gorny.edu.pl>
Date: Thu, 9 Nov 2006 21:26:43 +0000
Subject: [PATCH] utilities to convert and generate files outside OOoDocument
 objects (from raw data)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11237 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../ExtensionTemplateItem/documentUtils.py    | 25 +++++++++++++++++++
 bt5/erp5_dms/bt/revision                      |  2 +-
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/bt5/erp5_dms/ExtensionTemplateItem/documentUtils.py b/bt5/erp5_dms/ExtensionTemplateItem/documentUtils.py
index f10a56c344..e37af5a65b 100644
--- a/bt5/erp5_dms/ExtensionTemplateItem/documentUtils.py
+++ b/bt5/erp5_dms/ExtensionTemplateItem/documentUtils.py
@@ -1,4 +1,6 @@
 import zipfile, cStringIO, re
+import xmlrpclib, base64
+from Products.CMFCore.utils import getToolByName
 
 rx_atr='([\w]+)###([\w/]+)'
 rx_atr=re.compile(rx_atr)
@@ -23,4 +25,27 @@ def getDoctypeFromContent(data):
   atrs=getAttrFromContent(data)
   return atrs.get('doctype')
 
+def convertToOdf(name,data):
+  sp=mkProxy()
+  kw=sp.run_convert(name,data)
+  odf=base64.decodestring(kw['data'])
+  return odf
+
+def mkProxy(self):
+  pref=getToolByName(self,'portal_preferences')
+  adr=pref.getPreferredDmsOoodocServerAddress()
+  nr=pref.getPreferredDmsOoodocServerPortNumber()
+  if adr is None or nr is None:
+    raise Exception('you should set conversion server coordinates in preferences')
+  sp=xmlrpclib.ServerProxy('http://%s:%d' % (adr,nr),allow_none=True)
+  return sp
+
+def generateFile(self,name,data,format):
+  sp=mkProxy(self)
+  kw=sp.run_generate(name,data,None,format)
+  res=base64.decodestring(kw['data'])
+  return res
+
+
+
 # vim: syntax=python shiftwidth=2 
diff --git a/bt5/erp5_dms/bt/revision b/bt5/erp5_dms/bt/revision
index 9573848579..98c1572f67 100644
--- a/bt5/erp5_dms/bt/revision
+++ b/bt5/erp5_dms/bt/revision
@@ -1 +1 @@
-326
\ No newline at end of file
+327
\ No newline at end of file
-- 
2.30.9