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