Commit a0057254 authored by Nicolas Delaby's avatar Nicolas Delaby

- Fix non asXML recursion for subobjects introduce in r25154

 - Store Marshaler tree in a CDATA node to be compliant with erp5diff


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25190 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 85578ab1
...@@ -2817,11 +2817,11 @@ class Base( CopyContainer, ...@@ -2817,11 +2817,11 @@ class Base( CopyContainer,
self.reindexObject(*args, **kw) self.reindexObject(*args, **kw)
security.declareProtected( Permissions.AccessContentsInformation, 'asXML' ) security.declareProtected( Permissions.AccessContentsInformation, 'asXML' )
def asXML(self): def asXML(self, root=None):
""" """
Generate an xml text corresponding to the content of this object Generate an xml text corresponding to the content of this object
""" """
return Base_asXML(self) return Base_asXML(self, root=root)
# Optimized Menu System # Optimized Menu System
security.declarePublic('allowedContentTypes') security.declarePublic('allowedContentTypes')
......
...@@ -1224,11 +1224,11 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn, ...@@ -1224,11 +1224,11 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn,
return error_list return error_list
security.declareProtected(Permissions.AccessContentsInformation, 'asXML') security.declareProtected(Permissions.AccessContentsInformation, 'asXML')
def asXML(self, omit_xml_declaration=True): def asXML(self, omit_xml_declaration=True, root=None):
""" """
Generate an xml text corresponding to the content of this object Generate an xml text corresponding to the content of this object
""" """
return Folder_asXML(self, omit_xml_declaration=omit_xml_declaration) return Folder_asXML(self, omit_xml_declaration=omit_xml_declaration, root=root)
# Optimized Menu System # Optimized Menu System
security.declarePublic('getVisibleAllowedContentTypeList') security.declarePublic('getVisibleAllowedContentTypeList')
......
...@@ -98,8 +98,7 @@ def Base_asXML(object, root=None): ...@@ -98,8 +98,7 @@ def Base_asXML(object, root=None):
ascii_data = msg.get_payload() ascii_data = msg.get_payload()
sub_object.text = ascii_data sub_object.text = ascii_data
elif prop_type in ('lines', 'tokens',): elif prop_type in ('lines', 'tokens',):
value_as_node = etree.XML(marshaler(value)) sub_object.text = etree.CDATA(marshaler(value))
sub_object.append(value_as_node)
elif prop_type in ('text', 'string',): elif prop_type in ('text', 'string',):
sub_object.text = unicode(escape(value), 'utf-8') sub_object.text = unicode(escape(value), 'utf-8')
elif prop_type != 'None': elif prop_type != 'None':
...@@ -132,43 +131,41 @@ def Base_asXML(object, root=None): ...@@ -132,43 +131,41 @@ def Base_asXML(object, root=None):
for user_role in self.get_local_roles(): for user_role in self.get_local_roles():
local_role_node = SubElement(object, 'local_role', local_role_node = SubElement(object, 'local_role',
attrib=dict(id=user_role[0], type='tokens')) attrib=dict(id=user_role[0], type='tokens'))
role_list_node = etree.XML(marshaler(user_role[1])) local_role_node.text = etree.CDATA(marshaler(user_role[1]))
local_role_node.append(role_list_node)
if getattr(self, 'get_local_permissions', None) is not None: if getattr(self, 'get_local_permissions', None) is not None:
for user_permission in self.get_local_permissions(): for user_permission in self.get_local_permissions():
local_permission_node = SubElement(object, 'local_permission', local_permission_node = SubElement(object, 'local_permission',
attrib=dict(id=user_permission[0], type='tokens')) attrib=dict(id=user_permission[0], type='tokens'))
permission_list_node = etree.XML(marshaler(user_permission[1])) local_permission_node.text = etree.CDATA(marshaler(user_permission[1]))
local_permission_node.append(permission_list_node)
# Sometimes theres is roles specified for groups, like with CPS # Sometimes theres is roles specified for groups, like with CPS
if getattr(self, 'get_local_group_roles', None) is not None: if getattr(self, 'get_local_group_roles', None) is not None:
for group_role in self.get_local_group_roles(): for group_role in self.get_local_group_roles():
local_group_node = SubElement(object, 'local_group', local_group_node = SubElement(object, 'local_group',
attrib=dict(id=group_role[0], type='tokens')) attrib=dict(id=group_role[0], type='tokens'))
group_role_node = etree.XML(marshaler(group_role[1])) local_group_node.text = etree.CDATA(marshaler(group_role[1]))
local_group_node.append(group_role_node)
if return_as_object: if return_as_object:
return root return root
return etree.tostring(root, encoding='utf-8', return etree.tostring(root, encoding='utf-8',
xml_declaration=True, pretty_print=True) xml_declaration=True, pretty_print=True)
def Folder_asXML(object, omit_xml_declaration=True): def Folder_asXML(object, omit_xml_declaration=True, root=None):
""" """
Generate an xml text corresponding to the content of this object Generate an xml text corresponding to the content of this object
""" """
xml_declaration = not omit_xml_declaration xml_declaration = not omit_xml_declaration
from Products.ERP5Type.Base import Base from Products.ERP5Type.Base import Base
self = object self = object
if root is None:
root = Element('erp5') root = Element('erp5')
Base_asXML(self, root=root) Base_asXML(self, root=root)
root_node = root.xpath('/erp5/object')[0] root_node = root.find('object')
# Make sure the list of sub objects is ordered # Make sure the list of sub objects is ordered
id_list = sorted(self.objectIds()) id_list = sorted(self.objectIds())
# Append to the xml the xml of subobjects # Append to the xml the xml of subobjects
for id in id_list: for id in id_list:
o = self._getOb(id) o = self._getOb(id)
if issubclass(o.__class__, Base): if issubclass(o.__class__, Base):
Base_asXML(o, root=root_node) o.asXML(root=root_node)
return etree.tostring(root, encoding='utf-8', return etree.tostring(root, encoding='utf-8',
xml_declaration=xml_declaration, pretty_print=True) xml_declaration=xml_declaration, pretty_print=True)
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