Commit ab293d32 authored by Nicolas Delaby's avatar Nicolas Delaby

Remove default namespace of syncml streams and declare a specific prefix.

This avoid conflict between SyncML Stream and carried Data in xml w/o prefix.
Carried data must never belong to SyncML namespace even for NonQualified XML.
before:
<SyncML xmlns="SYNCML:SYNCML1.2">
...<object portal_type="Person" id="1">
  ...
   </object>
</SyncML>
after:
<syncml:SyncML xmlns:syncml="SYNCML:SYNCML1.2">
...<object portal_type="Person" id="1">
  ...
   </object>
</syncml:SyncML>
 


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29478 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 822cab72
...@@ -641,7 +641,7 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -641,7 +641,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
if subnode.xpath('local-name()') == property: if subnode.xpath('local-name()') == property:
return self.convertXmlValue(subnode) return self.convertXmlValue(subnode)
return None return None
def replaceIdFromXML(self, xml, new_id): def replaceIdFromXML(self, xml, new_id):
""" """
return a xml with id replace by a new id return a xml with id replace by a new id
...@@ -652,16 +652,12 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -652,16 +652,12 @@ class ERP5Conduit(XMLSyncUtilsMixin):
#copy of xml object for modification #copy of xml object for modification
from copy import deepcopy from copy import deepcopy
xml_copy = deepcopy(xml) xml_copy = deepcopy(xml)
if xml.nsmap is None or xml.nsmap == {}: if xml_copy.tag == self.xml_object_tag:
object_element = xml_copy.find(self.xml_object_tag) object_element = xml_copy
if object_element is None and xml_copy.tag == self.xml_object_tag:
object_element = xml_copy
id_element = object_element.find('id')
else: else:
object_element = xml_copy.xpath('//syncml:object', object_element = xml_copy.xpath('//object')[0]
namespaces={'syncml':xml_copy.nsmap[xml_copy.prefix]})[0] #XXXElement id will be removed from asXML
id_element = object_element.xpath('//syncml:id', id_element = object_element.xpath('./id')[0]
namespaces={'syncml':xml_copy.nsmap[xml_copy.prefix]})[0]
object_element.attrib['id'] = new_id object_element.attrib['id'] = new_id
id_element.text = new_id id_element.text = new_id
return etree.tostring(xml_copy) return etree.tostring(xml_copy)
......
# -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2003 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2003 Nexedi SARL and Contributors. All Rights Reserved.
...@@ -39,8 +40,11 @@ from AccessControl.SecurityManagement import newSecurityManager ...@@ -39,8 +40,11 @@ from AccessControl.SecurityManagement import newSecurityManager
import commands import commands
from DateTime import DateTime from DateTime import DateTime
from zLOG import LOG, DEBUG, INFO, WARNING from zLOG import LOG, DEBUG, INFO, WARNING
from lxml.etree import Element, SubElement
from lxml import etree from lxml import etree
from lxml.builder import ElementMaker
from SyncCode import SYNCML_NAMESPACE
nsmap = {'syncml' : SYNCML_NAMESPACE}
E = ElementMaker(namespace=SYNCML_NAMESPACE, nsmap=nsmap)
class PublicationSynchronization(XMLSyncUtils): class PublicationSynchronization(XMLSyncUtils):
""" """
...@@ -78,18 +82,17 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -78,18 +82,17 @@ class PublicationSynchronization(XMLSyncUtils):
subscriber.setSourceURI(self.getTargetURI(xml_client)) subscriber.setSourceURI(self.getTargetURI(xml_client))
subscriber.setTargetURI(self.getSourceURI(xml_client)) subscriber.setTargetURI(self.getSourceURI(xml_client))
cmd_id = 1 # specifies a SyncML message-unique command identifier cmd_id = 1 # specifies a SyncML message-unique command identifier
#create element 'SyncML' with a default namespace #create element 'SyncML' with a default namespace
nsmap = {None : self.XHTML_NAMESPACE} xml = E.SyncML()
xml = Element('SyncML',nsmap=nsmap)
# syncml header # syncml header
xml.append(self.SyncMLHeader(subscriber.getSessionId(), xml.append(self.SyncMLHeader(subscriber.getSessionId(),
subscriber.getMessageId(), subscriber.getMessageId(),
subscriber.getSubscriptionUrl(), subscriber.getSubscriptionUrl(),
publication.getPublicationUrl())) publication.getPublicationUrl()))
# syncml body # syncml body
sync_body = SubElement(xml, 'SyncBody') sync_body = E.SyncBody()
xml.append(sync_body)
#at the begining, the code is initialised at UNAUTHORIZED #at the begining, the code is initialised at UNAUTHORIZED
auth_code = self.UNAUTHORIZED auth_code = self.UNAUTHORIZED
...@@ -197,7 +200,7 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -197,7 +200,7 @@ class PublicationSynchronization(XMLSyncUtils):
has been started from the server (forbiden)" has been started from the server (forbiden)"
# a synchronisation is always starded from a client and can't be from # a synchronisation is always starded from a client and can't be from
# a server ! # a server !
sync_body.append(Element('Final')) sync_body.append(E.Final())
xml_string = etree.tostring(xml, encoding='utf-8', pretty_print=True) xml_string = etree.tostring(xml, encoding='utf-8', pretty_print=True)
if publication.getSyncContentType() == self.CONTENT_TYPE['SYNCML_WBXML']: if publication.getSyncContentType() == self.CONTENT_TYPE['SYNCML_WBXML']:
xml_string = self.xml2wbxml(xml_string) xml_string = self.xml2wbxml(xml_string)
......
# -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2003 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2003 Nexedi SARL and Contributors. All Rights Reserved.
...@@ -35,8 +36,11 @@ from Conduit.ERP5Conduit import ERP5Conduit ...@@ -35,8 +36,11 @@ from Conduit.ERP5Conduit import ERP5Conduit
from AccessControl import getSecurityManager from AccessControl import getSecurityManager
from DateTime import DateTime from DateTime import DateTime
from zLOG import LOG, DEBUG, INFO from zLOG import LOG, DEBUG, INFO
from lxml.etree import Element, SubElement
from lxml import etree from lxml import etree
from lxml.builder import ElementMaker
from SyncCode import SYNCML_NAMESPACE
nsmap = {'syncml' : SYNCML_NAMESPACE}
E = ElementMaker(namespace=SYNCML_NAMESPACE, nsmap=nsmap)
class SubscriptionSynchronization(XMLSyncUtils): class SubscriptionSynchronization(XMLSyncUtils):
...@@ -54,17 +58,16 @@ class SubscriptionSynchronization(XMLSyncUtils): ...@@ -54,17 +58,16 @@ class SubscriptionSynchronization(XMLSyncUtils):
subscription.setZopeUser(user) subscription.setZopeUser(user)
subscription.setAuthenticated(True) subscription.setAuthenticated(True)
#create element 'SyncML' with a default namespace #create element 'SyncML'
nsmap = {None : self.XHTML_NAMESPACE} xml = E.SyncML()
xml = Element('SyncML',nsmap=nsmap)
# syncml header # syncml header
xml.append(self.SyncMLHeader(subscription.incrementSessionId(), xml.append(self.SyncMLHeader(subscription.incrementSessionId(),
subscription.incrementMessageId(), subscription.getPublicationUrl(), subscription.incrementMessageId(), subscription.getPublicationUrl(),
subscription.getSubscriptionUrl(), source_name=subscription.getLogin())) subscription.getSubscriptionUrl(), source_name=subscription.getLogin()))
# syncml body # syncml body
sync_body = SubElement(xml, 'SyncBody') sync_body = E.SyncBody()
xml.append(sync_body)
# We have to set every object as NOT_SYNCHRONIZED # We have to set every object as NOT_SYNCHRONIZED
subscription.startSynchronization() subscription.startSynchronization()
...@@ -96,8 +99,7 @@ class SubscriptionSynchronization(XMLSyncUtils): ...@@ -96,8 +99,7 @@ class SubscriptionSynchronization(XMLSyncUtils):
""" """
cmd_id = 1 # specifies a SyncML message-unique command identifier cmd_id = 1 # specifies a SyncML message-unique command identifier
#create element 'SyncML' with a default namespace #create element 'SyncML' with a default namespace
nsmap = {None : self.XHTML_NAMESPACE} xml = E.SyncML()
xml = Element('SyncML',nsmap=nsmap)
# syncml header # syncml header
data = "%s:%s" % (subscription.getLogin(), subscription.getPassword()) data = "%s:%s" % (subscription.getLogin(), subscription.getPassword())
data = subscription.encode(subscription.getAuthenticationFormat(), data) data = subscription.encode(subscription.getAuthenticationFormat(), data)
...@@ -112,7 +114,8 @@ class SubscriptionSynchronization(XMLSyncUtils): ...@@ -112,7 +114,8 @@ class SubscriptionSynchronization(XMLSyncUtils):
authentication_type=subscription.getAuthenticationType())) authentication_type=subscription.getAuthenticationType()))
# syncml body # syncml body
sync_body = SubElement(xml, 'SyncBody') sync_body = E.SyncBody()
xml.append(sync_body)
# We have to set every object as NOT_SYNCHRONIZED # We have to set every object as NOT_SYNCHRONIZED
subscription.startSynchronization() subscription.startSynchronization()
...@@ -128,7 +131,7 @@ class SubscriptionSynchronization(XMLSyncUtils): ...@@ -128,7 +131,7 @@ class SubscriptionSynchronization(XMLSyncUtils):
if syncml_put is not None: if syncml_put is not None:
sync_body.append(syncml_put) sync_body.append(syncml_put)
cmd_id += 1 cmd_id += 1
sync_body.append(Element('Final')) sync_body.append(E.Final())
xml_string = etree.tostring(xml, encoding='utf-8', xml_declaration=True, xml_string = etree.tostring(xml, encoding='utf-8', xml_declaration=True,
pretty_print=True) pretty_print=True)
self.sendResponse(from_url=subscription.subscription_url, self.sendResponse(from_url=subscription.subscription_url,
......
# -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
...@@ -30,6 +31,8 @@ from Products.ERP5Type.Accessor.TypeDefinition import list_types ...@@ -30,6 +31,8 @@ from Products.ERP5Type.Accessor.TypeDefinition import list_types
from Globals import Persistent from Globals import Persistent
import re import re
SYNCML_NAMESPACE = 'SYNCML:SYNCML1.2'
class SyncCode(Persistent): class SyncCode(Persistent):
""" """
Class giving the Synchronization's Constants Class giving the Synchronization's Constants
...@@ -133,7 +136,6 @@ class SyncCode(Persistent): ...@@ -133,7 +136,6 @@ class SyncCode(Persistent):
#Namespace #Namespace
#In SyncML Representation Protocol OMA #In SyncML Representation Protocol OMA
#we use URN as format of namespace #we use URN as format of namespace
XHTML_NAMESPACE = 'SYNCML:SYNCML1.2'
# List namespaces supported # List namespaces supported
URN_LIST = ('SYNCML:SYNCML1.1', 'SYNCML:SYNCML1.2') URN_LIST = ('SYNCML:SYNCML1.1', 'SYNCML:SYNCML1.2')
# -*- coding: utf-8 -*-
## Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved. ## Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
# Sebastien Robin <seb@nexedi.com> # Sebastien Robin <seb@nexedi.com>
# #
...@@ -35,8 +36,6 @@ from Products.CMFCore.utils import UniqueObject ...@@ -35,8 +36,6 @@ from Products.CMFCore.utils import UniqueObject
from Globals import InitializeClass, DTMLFile, PersistentMapping, Persistent from Globals import InitializeClass, DTMLFile, PersistentMapping, Persistent
from AccessControl import ClassSecurityInfo, getSecurityManager from AccessControl import ClassSecurityInfo, getSecurityManager
from Products.CMFCore import CMFCorePermissions from Products.CMFCore import CMFCorePermissions
from Products.ERP5SyncML import _dtmldir
from Products.ERP5SyncML import Conduit
from Publication import Publication, Subscriber from Publication import Publication, Subscriber
from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2 from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2
from Subscription import Subscription from Subscription import Subscription
......
This diff is collapsed.
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