Commit d2a9efab authored by Sebastien Robin's avatar Sebastien Robin

do not break the start of ERP5 if the library Ft.Xml is missing, only raise...

do not break the start of ERP5 if the library Ft.Xml is missing, only raise ImportError when we want to use synchronization tool

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14660 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7f61d51a
......@@ -33,7 +33,7 @@ from Products.CMFCore.utils import getToolByName
from Products.ERP5SyncML.XupdateUtils import XupdateUtils
from Products.ERP5Type.Utils import convertToUpperCase
from Products.ERP5Type.Accessor.TypeDefinition import list_types
from Ft.Xml import Parse
from Products.ERP5SyncML.XMLSyncUtils import Parse
from DateTime.DateTime import DateTime
from email.MIMEBase import MIMEBase
from email import Encoders
......@@ -47,11 +47,19 @@ from cStringIO import StringIO
from xml.sax.saxutils import escape, unescape
import re, copy
import cStringIO
from Ft.Xml.Domlette import Print, PrettyPrint
from zLOG import LOG
try:
from Ft.Xml.Domlette import Print, PrettyPrint
except ImportError:
LOG('ERP5Conduit',0,"Can't import Print and PrettyPrint")
class Print:
def __init__(self, *args, **kw):
raise ImportError, "Sorry, it was not possible to import Ft library"
class PrettyPrint:
def __init__(self, *args, **kw):
raise ImportError, "Sorry, it was not possible to import Ft library"
class ERP5Conduit(XMLSyncUtilsMixin):
"""
......
......@@ -154,7 +154,7 @@ class Publication(Subscription):
# Constructor
def __init__(self, id, title, publication_url, destination_path,
query, xml_mapping, conduit, gpg_key, id_generator, gid_generator,
flow_type, auth_required=False, authentication_format='',
media_type, auth_required=False, authentication_format='',
authentication_type=''):
"""
constructor
......@@ -168,7 +168,7 @@ class Publication(Subscription):
self.domain_type = self.PUB
self.gpg_key = gpg_key
self.setGidGenerator(gid_generator)
self.setFlowType(flow_type)
self.setMediaType(media_type)
self.setSynchronizationIdGenerator(id_generator)
self.setConduit(conduit)
Folder.__init__(self, id)
......
......@@ -29,7 +29,7 @@
import smtplib # to send emails
from Publication import Publication,Subscriber
from Subscription import Signature
from Ft.Xml import Parse
from XMLSyncUtils import Parse
from XMLSyncUtils import XMLSyncUtils
from Conduit.ERP5Conduit import ERP5Conduit
from Products.CMFCore.utils import getToolByName
......
......@@ -644,7 +644,7 @@ class Subscription(Folder, SyncCode):
# Constructor
def __init__(self, id, title, publication_url, subscription_url,
destination_path, query, xml_mapping, conduit, gpg_key, id_generator,
gid_generator, flow_type, login, password):
gid_generator, media_type, login, password):
"""
We need to create a dictionnary of
signatures of documents which belong to the synchronisation
......@@ -661,7 +661,7 @@ class Subscription(Folder, SyncCode):
#self.signatures = PersistentMapping()
self.last_anchor = '00000000T000000Z'
self.next_anchor = '00000000T000000Z'
self.flow_type = flow_type
self.setMediaType(media_type)
self.login = login
self.password=password
self.domain_type = self.SUB
......@@ -884,19 +884,20 @@ class Subscription(Folder, SyncCode):
"""
return self.gid_generator
def getFlowType(self):
def getMediaType(self):
"""
This method return the type of the data within the xml message :
- text for VCard's
- xml for others
This method return the type of media used in this session,
for example, it could be "text/vcard" or "xml/text",...
"""
return getattr(self, 'flow_type', 'xml')
return getattr(self, 'media_type', self.MEDIA_TYPE['TEXT_XML'])
def setFlowType(self, flow_type):
def setMediaType(self, media_type):
"""
set the flow type (xml or text)
set the type of media used
"""
self.flow_type=flow_type
if media_type in (None,''):
media_type = self.MEDIA_TYPE['TEXT_XML']
self.media_type = media_type
def getLogin(self):
"""
......
......@@ -28,8 +28,7 @@
import smtplib # to send emails
from Subscription import Subscription,Signature
from Ft.Xml import Parse
from XMLSyncUtils import XMLSyncUtils
from XMLSyncUtils import XMLSyncUtils, Parse
import commands
from Conduit.ERP5Conduit import ERP5Conduit
from zLOG import LOG
......
......@@ -110,3 +110,10 @@ class SyncCode(Persistent):
bad_history_exp = "/%s\[@id='.*'\]/" % history_tag
local_role_and_group_list = (local_group_exp,local_role_exp)
bad_local_role_and_group_list = (bad_local_group_exp,bad_local_role_exp)
#media types :
MEDIA_TYPE = {}
MEDIA_TYPE['TEXT_XML'] = 'text/xml'
MEDIA_TYPE['TEXT_VCARD'] = 'text/vcard'
......@@ -40,7 +40,8 @@ from Products.ERP5SyncML import Conduit
from Publication import Publication,Subscriber
from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2
from Subscription import Subscription,Signature
from Ft.Xml import Parse
from XMLSyncUtils import Parse
#from Ft.Xml import Parse
from Products.ERP5Type import Permissions
from PublicationSynchronization import PublicationSynchronization
from SubscriptionSynchronization import SubscriptionSynchronization
......@@ -162,7 +163,7 @@ class SynchronizationTool( SubscriptionSynchronization,
def manage_addPublication(self, title, publication_url, destination_path,
query, xml_mapping, conduit, gpg_key,
synchronization_id_generator=None, gid_generator=None,
flow_type='xml', auth_required=0, authentication_format='',
media_type=None, auth_required=0, authentication_format='',
authentication_type='', RESPONSE=None):
"""
create a new publication
......@@ -174,7 +175,7 @@ class SynchronizationTool( SubscriptionSynchronization,
new_id = self.getPublicationIdFromTitle(title)
pub = Publication(new_id, title, publication_url, destination_path,
query, xml_mapping, conduit, gpg_key,
synchronization_id_generator, gid_generator, flow_type,
synchronization_id_generator, gid_generator, media_type,
auth_required, authentication_format, authentication_type)
folder._setObject( new_id, pub )
#if len(self.list_publications) == 0:
......@@ -188,7 +189,7 @@ class SynchronizationTool( SubscriptionSynchronization,
def manage_addSubscription(self, title, publication_url, subscription_url,
destination_path, query, xml_mapping, conduit, gpg_key,
synchronization_id_generator=None, gid_generator=None,
flow_type='xml', login=None, password=None,
media_type=None, login=None, password=None,
RESPONSE=None):
"""
XXX should be renamed as addSubscription
......@@ -201,7 +202,7 @@ class SynchronizationTool( SubscriptionSynchronization,
new_id = self.getSubscriptionIdFromTitle(title)
sub = Subscription(new_id, title, publication_url, subscription_url,
destination_path, query, xml_mapping, conduit, gpg_key,
synchronization_id_generator, gid_generator, flow_type,
synchronization_id_generator, gid_generator, media_type,
login, password)
folder._setObject( new_id, sub )
#if len(self.list_subscriptions) == 0:
......@@ -215,7 +216,7 @@ class SynchronizationTool( SubscriptionSynchronization,
def manage_editPublication(self, title, publication_url, destination_path,
query, xml_mapping, conduit, gpg_key,
synchronization_id_generator, gid_generator,
flow_type='xml', auth_required=0,
media_type=None, auth_required=0,
authentication_format='', authentication_type='',
RESPONSE=None):
"""
......@@ -231,7 +232,7 @@ class SynchronizationTool( SubscriptionSynchronization,
pub.setGPGKey(gpg_key)
pub.setSynchronizationIdGenerator(synchronization_id_generator)
pub.setGidGenerator(gid_generator)
pub.setFlowType(flow_type)
pub.setMediaType(media_type)
pub.setAuthentication(auth_required)
pub.setAuthenticationFormat(authentication_format)
pub.setAuthenticationType(authentication_type)
......@@ -243,7 +244,7 @@ class SynchronizationTool( SubscriptionSynchronization,
'manage_editSubscription')
def manage_editSubscription(self, title, publication_url, subscription_url,
destination_path, query, xml_mapping, conduit, gpg_key,
synchronization_id_generator, gid_generator, flow_type='xml', login='',
synchronization_id_generator, gid_generator, media_type=None,login='',
password='', RESPONSE=None):
"""
modify a subscription
......@@ -259,7 +260,7 @@ class SynchronizationTool( SubscriptionSynchronization,
sub.setSubscriptionUrl(subscription_url)
sub.setSynchronizationIdGenerator(synchronization_id_generator)
sub.setGidGenerator(gid_generator)
sub.setFlowType(flow_type)
sub.setMediaType(media_type)
sub.setLogin(login)
sub.setPassword(password)
if RESPONSE is not None:
......
......@@ -29,7 +29,6 @@
import smtplib
from Products.ERP5SyncML.SyncCode import SyncCode
from Products.ERP5SyncML.Subscription import Signature
from Ft.Xml import Parse
from DateTime import DateTime
from cStringIO import StringIO
from xml.dom.ext import PrettyPrint
......@@ -42,6 +41,13 @@ except ImportError:
pass
import commands
from zLOG import LOG
try:
from Ft.Xml import Parse
except ImportError:
LOG('XMLSyncUtils',0,"Can't import Parse")
class Parse:
def __init__(self, *args, **kw):
raise ImportError, "Sorry, it was not possible to import Ft library"
class XMLSyncUtilsMixin(SyncCode):
......@@ -191,7 +197,7 @@ class XMLSyncUtilsMixin(SyncCode):
server.quit()
def addXMLObject(self, cmd_id=0, object=None, xml_string=None,
more_data=0,gid=None):
more_data=0,gid=None, media_type=None):
"""
Add an object with the SyncML protocol
"""
......@@ -200,7 +206,7 @@ class XMLSyncUtilsMixin(SyncCode):
xml(' <Add>\n')
xml(' <CmdID>%s</CmdID>\n' % cmd_id)
xml(' <Meta>\n')
xml(' <Type>%s</Type>\n' % object.portal_type)
xml(' <Type>%s</Type>\n' % media_type)
xml(' </Meta>\n')
xml(' <Item>\n')
xml(' <Source>\n')
......@@ -236,7 +242,7 @@ class XMLSyncUtilsMixin(SyncCode):
return xml_a
def replaceXMLObject(self, cmd_id=0, object=None, xml_string=None,
more_data=0,gid=None):
more_data=0, gid=None, media_type=None):
"""
Replace an object with the SyncML protocol
"""
......@@ -245,7 +251,7 @@ class XMLSyncUtilsMixin(SyncCode):
xml(' <Replace>\n')
xml(' <CmdID>%s</CmdID>\n' % cmd_id)
xml(' <Meta>\n')
xml(' <Type>%s</Type>\n' % object.portal_type)
xml(' <Type>%s</Type>\n' % media_type)
xml(' </Meta>\n')
xml(' <Item>\n')
xml(' <Source>\n')
......@@ -663,6 +669,8 @@ class XMLSyncUtilsMixin(SyncCode):
status = self.SENT
#gid_generator = getattr(object,domain.getGidGenerator(),None)
object_gid = domain.getGidFromObject(object)
if object_gid in ('', None):
continue;
local_gid_list += [object_gid]
#if gid_generator is not None:
# object_gid = gid_generator()
......@@ -670,7 +678,6 @@ class XMLSyncUtilsMixin(SyncCode):
if syncml_data.count('\n') < self.MAX_LINES and not \
object.id.startswith('.'): # If not we have to cut
#LOG('getSyncMLData',0,'xml_mapping: %s' % str(domain.xml_mapping))
#LOG('getSyncMLData', 0, 'FlowType: %s' % str(subscriber.getFlowType()))
#LOG('getSyncMLData',0,'code: %s' % str(self.getAlertCode(remote_xml)))
#LOG('getSyncMLData',0,'gid_list: %s' % str(local_gid_list))
#LOG('getSyncMLData',0,'hasSignature: %s' % str(subscriber.hasSignature(object_gid)))
......@@ -712,7 +719,8 @@ class XMLSyncUtilsMixin(SyncCode):
signature.setAction('Add')
xml_string = '<!--' + short_string + '-->'
syncml_data += self.addXMLObject(cmd_id=cmd_id, object=object,
gid=object_gid, xml_string=xml_string, more_data=more_data)
gid=object_gid, xml_string=xml_string, more_data=more_data,
media_type=subscriber.getMediaType())
cmd_id += 1
signature.setStatus(status)
subscriber.addSignature(signature)
......@@ -748,11 +756,12 @@ class XMLSyncUtilsMixin(SyncCode):
signature.setAction('Replace')
xml_string = '<!--' + short_string + '-->'
signature.setStatus(status)
if(subscriber.getFlowType() == 'text'):
if subscriber.getMediaType() != self.MEDIA_TYPE['TEXT_XML']:
xml_string = self.getXMLObject(object=object,
xml_mapping=domain.xml_mapping)
syncml_data += self.replaceXMLObject(cmd_id=cmd_id, object=object,
gid=object_gid, xml_string=xml_string, more_data=more_data)
gid=object_gid, xml_string=xml_string, more_data=more_data,
media_type=subscriber.getMediaType())
cmd_id += 1
signature.setTempXML(xml_object)
# Now we can apply the xupdate from the subscriber
......@@ -771,7 +780,7 @@ class XMLSyncUtilsMixin(SyncCode):
signature.setStatus(self.SYNCHRONIZED)
elif signature.getStatus()==self.PUB_CONFLICT_CLIENT_WIN:
# We have decided to apply the update
# XXX previous_xml will be getXML instead of getTempXML because
# XXX previous_xml will be geXML instead of getTempXML because
# some modification was already made and the update
# may not apply correctly
xml_update = signature.getPartialXML()
......@@ -798,16 +807,18 @@ class XMLSyncUtilsMixin(SyncCode):
xml_string = xml_string.replace('--','@-@@-@')
xml_string = '<!--' + xml_string + '-->'
signature.setStatus(status)
if(subscriber.getFlowType() == 'text'):
if(subscriber.getMediaType() != self.MEDIA_TYPE['TEXT_XML']):
xml_string = self.getXMLObject(object=object,
xml_mapping=domain.xml_mapping)
LOG('xml_string =', 0, xml_string)
if signature.getAction()=='Replace':
syncml_data += self.replaceXMLObject(cmd_id=cmd_id, object=object,
gid=object_gid, xml_string=xml_string, more_data=more_data)
gid=object_gid, xml_string=xml_string, more_data=more_data,
media_type=subscriber.getMediaType())
elif signature.getAction()=='Add':
syncml_data += self.addXMLObject(cmd_id=cmd_id, object=object,
gid=object_gid, xml_string=xml_string, more_data=more_data)
gid=object_gid, xml_string=xml_string, more_data=more_data,
media_type=subscriber.getMediaType())
return (syncml_data,xml_confirmation,cmd_id)
def applyActionList(self, domain=None, subscriber=None,destination_path=None,
......@@ -846,12 +857,12 @@ class XMLSyncUtilsMixin(SyncCode):
data_subnode = partial_data
LOG('SyncModif',0,'data_subnode: %s' % data_subnode)
#data_subnode = FromXml(data_subnode)
if subscriber.getFlowType() == 'xml':
if subscriber.getMediaType() == self.MEDIA_TYPE['TEXT_XML']:
data_subnode = Parse(data_subnode)
data_subnode = data_subnode.childNodes[0] # Because we just created a new xml
# document, with childNodes[0] a DocumentType and childNodes[1] the Element Node
else:
if subscriber.getFlowType() == 'text':
if subscriber.getMediaType() != self.MEDIA_TYPE['TEXT_XML']:
data_subnode = self.getDataText(next_action)
else:
data_subnode = self.getDataSubNode(next_action)
......@@ -934,7 +945,7 @@ class XMLSyncUtilsMixin(SyncCode):
elif next_action.nodeName == 'Delete':
object_id = signature.getId()
if subscriber.getFlowType == 'text':
if subscriber.getMediaType() != self.MEDIA_TYPE['TEXT_XML']:
data_subnode = self.getDataText(next_action)
else:
data_subnode = self.getDataSubNode(next_action)
......
......@@ -130,19 +130,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<tr>
<td align="left" valign="top">
<div class="form-label">
Flow Type
Media Type
</label></div>
</td>
<td align="left" valign="top">
<SELECT name="flow_type" size="1">
<dtml-if expr="getFlowType() != 'text'">
<OPTION value="xml" selected>XML</option>
<OPTION value="text">text</option>
<dtml-else>
<OPTION value="xml">XML</option>
<OPTION value="text" selected>text</option>
</dtml-if>
</SELECT>
<input type="text" name="media_type" value="<dtml-var getMediaType>" size="40" />
</td>
</tr>
<tr>
......
......@@ -140,19 +140,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<tr>
<td align="left" valign="top">
<div class="form-label">
Flow Type
Media Type
</label></div>
</td>
<td align="left" valign="top">
<SELECT name="flow_type" size="1">
<dtml-if expr="getFlowType() != 'text'">
<OPTION value="xml" selected>XML</option>
<OPTION value="text">text</option>
<dtml-else>
<OPTION value="xml">XML</option>
<OPTION value="text" selected>text</option>
</dtml-if>
</SELECT>
<input type="text" name="media_type" value="<dtml-var getMediaType>" size="40" />
</td>
</tr>
<tr>
......
......@@ -126,14 +126,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<tr>
<td align="left" valign="top">
<div class="form-label">
Flow Type
Media Type
</label></div>
</td>
<td align="left" valign="top">
<SELECT name="flow_type" size="1">
<OPTION value="xml" selected>XML</option>
<OPTION value="text">text</option>
</SELECT>
<input type="text" name="media_type" size="40" />
</td>
</tr>
<tr>
......
......@@ -136,14 +136,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<tr>
<td align="left" valign="top">
<div class="form-label">
Flow Type
Media Type
</label></div>
</td>
<td align="left" valign="top">
<SELECT name="flow_type" size="1">
<OPTION value="xml" selected>XML</option>
<OPTION value="text">text</option>
</SELECT>
<input type="text" name="media_type" size="40" />
</td>
</tr>
<tr>
......
......@@ -745,7 +745,7 @@ class TestERP5SyncML(TestERP5SyncMLMixin, ERP5TypeTestCase):
sub_person1.edit(**kw)
sub_sub_person1 = sub_person1.newContent(id=self.id1,portal_type='Person')
kw = {'first_name':self.first_name1,'last_name':self.last_name1,
'description':self.description1}
'description':self.description1, 'default_telephone_text':'0689778308'}
sub_sub_person1.edit(**kw)
sub_sub_person2 = sub_person1.newContent(id=self.id2,portal_type='Person')
kw = {'first_name':self.first_name2,'last_name':self.last_name2,
......@@ -785,6 +785,7 @@ class TestERP5SyncML(TestERP5SyncMLMixin, ERP5TypeTestCase):
self.failUnless(sub_sub_person1.getDescription()==self.description1)
self.failUnless(sub_sub_person1.getFirstName()==self.first_name1)
self.failUnless(sub_sub_person1.getLastName()==self.last_name1)
self.failUnless(sub_sub_person1.getDefaultTelephoneText()=='+(0)-0689778308')
self.failUnless(sub_sub_person2.getDescription()==self.description2)
self.failUnless(sub_sub_person2.getFirstName()==self.first_name2)
self.failUnless(sub_sub_person2.getLastName()==self.last_name2)
......
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