From fff6b2797f2d68981ad6e3ca622f82314e03a9a0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bartek=20G=C3=B3rny?= <bartek@gorny.edu.pl>
Date: Sun, 13 Aug 2006 18:04:31 +0000
Subject: [PATCH] server coordinates drawn from preferences

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9189 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5OOo/Document/OOoDocument.py       | 16 ++++--
 .../ERP5OOo/PropertySheet/DMSPreference.py    | 49 +++++++++++++++++++
 2 files changed, 60 insertions(+), 5 deletions(-)
 create mode 100644 product/ERP5OOo/PropertySheet/DMSPreference.py

diff --git a/product/ERP5OOo/Document/OOoDocument.py b/product/ERP5OOo/Document/OOoDocument.py
index cbcde9b0a9..168b84d019 100644
--- a/product/ERP5OOo/Document/OOoDocument.py
+++ b/product/ERP5OOo/Document/OOoDocument.py
@@ -39,6 +39,7 @@ from DateTime import DateTime
 import xmlrpclib, base64, mimetypes
 # to overwrite WebDAV methods
 from Products.CMFDefault.File import File as CMFFile
+from Products.CMFCore.utils import getToolByName
 
 mimetypes.init()
 
@@ -147,10 +148,15 @@ class OOoDocument(XMLObject,File):
 
   def _getServerCoordinates(self):
     """
-    Returns OOo conversion server data from some
-    preferences. NOT IMPLEMENTED YET - XXX
+    Returns OOo conversion server data from 
+    preferences
     """
-    return '127.0.0.1',8080
+    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')
+    return adr,nr
 
   def _mkProxy(self):
     sp=xmlrpclib.ServerProxy('http://%s:%d' % self._getServerCoordinates(),allow_none=True)
@@ -165,13 +171,13 @@ class OOoDocument(XMLObject,File):
     return (code,m)
 
   security.declareProtected(Permissions.ModifyPortalContent,'convert')
-  def convert(self,REQUEST=None):
+  def convert(self,force=0,REQUEST=None):
     """
     Converts from the initial format to OOo format;
     communicates with the conversion server
     and gets converted file as well as metadata
     """
-    if not self.isFileUploaded():
+    if force==0 and not self.isFileUploaded():
       return self.returnMessage('OOo file is up do date')
     try:
       self._convert()
diff --git a/product/ERP5OOo/PropertySheet/DMSPreference.py b/product/ERP5OOo/PropertySheet/DMSPreference.py
new file mode 100644
index 0000000000..8ed13765bc
--- /dev/null
+++ b/product/ERP5OOo/PropertySheet/DMSPreference.py
@@ -0,0 +1,49 @@
+##############################################################################
+#
+## Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
+#
+## WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# # consequences resulting from its eventual inadequacies and bugs
+# # End users who are looking for a ready-to-use solution with commercial
+# # garantees and support are strongly adviced to contract a Free Software
+# # Service Company
+# #
+# # This program is Free Software; you can redistribute it and/or
+# # modify it under the terms of the GNU General Public License
+# # as published by the Free Software Foundation; either version 2
+# # of the License, or (at your option) any later version.
+# #
+# # This program is distributed in the hope that it will be useful,
+# # but WITHOUT ANY WARRANTY; without even the implied warranty of
+# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# # GNU General Public License for more details.
+# #
+# # You should have received a copy of the GNU General Public License
+# # along with this program; if not, write to the Free Software
+# # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+# #
+# ##############################################################################
+
+class DMSPreference:
+  """
+ 
+  """
+
+  _properties = (
+    { 'id'    : 'preferred_dms_ooodoc_server_address',
+    'description' : 'address of a server for converting docs (ip or domain)',
+    'type'    : 'string',
+    'preference':1,
+    'mode'    : '' },
+    { 'id'    : 'preferred_dms_ooodoc_server_port_number',
+    'description' : 'port number of a server for converting docs (ip or domain)',
+    'type'    : 'int',
+    'preference':1,
+    'mode'    : '' },
+    )
+
+ 
+
+# vim: shiftwidth=2
+
-- 
2.30.9