Commit 281f6390 authored by Nicolas Delaby's avatar Nicolas Delaby

Using both library make conflicts, so each Lib should use his own...

Using both library make conflicts, so each Lib should use his own implementation. 4Suite require creating node by Qname (with namespace URI)
parent e427d5f0
......@@ -19,14 +19,18 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ?02111-1307, USA.
#
##############################################################################
try:
from Ft.Xml import Parse as parse
from Ft.Xml.Domlette import EntityReaderBase
parseString = EntityReaderBase().parseString
from Ft.Xml.Domlette import EntityReader, PrettyPrint
parseString = EntityReader.parseString
from Ft.Xml.Domlette import implementation
def getDOMImplementation():
return implementation
except:
from xml.dom.minidom import parse, parseString
from xml.dom.minidom import getDOMImplementation
from xml.dom.minidom import getDOMImplementation
from xml.dom.ext import PrettyPrint
import sys
import getopt
......@@ -56,6 +60,7 @@ class ERP5Diff:
"""
self._verbose = 0
self._result = None
self._ns = 'http://www.xmldb.org/xupdate'
def setVerbosity(self, verbose):
"""
......@@ -102,13 +107,13 @@ class ERP5Diff:
Append attributes to the element at 'path'.
"""
root = self._getResultRoot()
createElement = self._result.createElement
createElement = self._result.createElementNS
createTextNode = self._result.createTextNode
append_element = createElement('xupdate:append')
append_element.setAttribute('select', path)
append_element = createElement(self._ns, 'xupdate:append')
append_element.setAttributeNS(self._ns, 'select', path)
for name, val in dict.iteritems():
attr_element = createElement('xupdate:attribute')
attr_element.setAttribute('name', name)
attr_element = createElement(self._ns, 'xupdate:attribute')
attr_element.setAttributeNS(self._ns, 'name', name)
text_node = createTextNode(val)
attr_element.appendChild(text_node)
append_element.appendChild(attr_element)
......@@ -119,9 +124,9 @@ class ERP5Diff:
Remove an attribute from the element at 'path'.
"""
root = self._getResultRoot()
createElement = self._result.createElement
remove_element = createElement('xupdate:remove')
remove_element.setAttribute('select', self._concatPath(path, 'attribute::' + name))
createElement = self._result.createElementNS
remove_element = createElement(self._ns, 'xupdate:remove')
remove_element.setAttributeNS(self._ns, 'select', self._concatPath(path, 'attribute::' + name))
root.appendChild(remove_element)
def _xupdateUpdateAttribute(self, name, val, path):
......@@ -129,10 +134,10 @@ class ERP5Diff:
Update the value of an attribute of the element at 'path'.
"""
root = self._getResultRoot()
createElement = self._result.createElement
createElement = self._result.createElementNS
createTextNode = self._result.createTextNode
update_element = createElement('xupdate:update')
update_element.setAttribute('select', self._concatPath(path, 'attribute::' + name))
update_element = createElement(self._ns, 'xupdate:update')
update_element.setAttributeNS(self._ns, 'select', self._concatPath(path, 'attribute::' + name))
text_node = createTextNode(val)
update_element.appendChild(text_node)
root.appendChild(update_element)
......@@ -142,10 +147,10 @@ class ERP5Diff:
Rename an existing element at 'path'.
"""
root = self._getResultRoot()
createElement = self._result.createElement
createElement = self._result.createElementNS
createTextNode = self._result.createTextNode
rename_element = createElement('xupdate:rename')
rename_element.setAttribute('select', path)
rename_element = createElement(self._ns, 'xupdate:rename')
rename_element.setAttributeNS(self._ns, 'select', path)
text_node = createTextNode(name)
rename_element.appendChild(text_node)
root.appendChild(rename_element)
......@@ -155,9 +160,9 @@ class ERP5Diff:
Update the contents of an element at 'path' to that of 'element'.
"""
root = self._getResultRoot()
createElement = self._result.createElement
update_element = createElement('xupdate:update')
update_element.setAttribute('select', path)
createElement = self._result.createElementNS
update_element = createElement(self._ns, 'xupdate:update')
update_element.setAttributeNS(self._ns ,'select', path)
for node in element.childNodes:
#self._p("node is %s" % repr(node))
clone_node = node.cloneNode(1)
......@@ -169,9 +174,9 @@ class ERP5Diff:
Remove an element at 'path'.
"""
root = self._getResultRoot()
createElement = self._result.createElement
remove_element = createElement('xupdate:remove')
remove_element.setAttribute('select', path)
createElement = self._result.createElementNS
remove_element = createElement(self._ns, 'xupdate:remove')
remove_element.setAttributeNS(self._ns, 'select', path)
root.appendChild(remove_element)
def _xupdateInsertBefore(self, element_list, path):
......@@ -179,17 +184,17 @@ class ERP5Diff:
Insert elements before the element at 'path'.
"""
root = self._getResultRoot()
createElement = self._result.createElement
createElement = self._result.createElementNS
createTextNode = self._result.createTextNode
insert_element = createElement('xupdate:insert-before')
insert_element.setAttribute('select', path)
insert_element = createElement(self._ns, 'xupdate:insert-before')
insert_element.setAttributeNS(self._ns, 'select', path)
for element in element_list:
child_element = createElement('xupdate:element')
child_element.setAttribute('name', element.tagName)
child_element = createElement(self._ns, 'xupdate:element')
child_element.setAttributeNS(self._ns, 'name', element.tagName)
attr_map = element.attributes
for attr in attr_map.values():
attr_element = createElement('xupdate:attribute')
attr_element.setAttribute('name', attr.name)
attr_element = createElement(self._ns, 'xupdate:attribute')
attr_element.setAttributeNS(self._ns, 'name', attr.name)
text_node = createTextNode(attr.nodeValue)
attr_element.appendChild(text_node)
child_element.appendChild(attr_element)
......@@ -204,17 +209,17 @@ class ERP5Diff:
Append elements to the element at 'path'.
"""
root = self._getResultRoot()
createElement = self._result.createElement
createElement = self._result.createElementNS
createTextNode = self._result.createTextNode
append_element = createElement('xupdate:append')
append_element.setAttribute('select', path)
append_element = createElement(self._ns, 'xupdate:append')
append_element.setAttributeNS(self._ns, 'select', path)
for element in element_list:
child_element = createElement('xupdate:element')
child_element.setAttribute('name', element.tagName)
child_element = createElement(self._ns, 'xupdate:element')
child_element.setAttributeNS(self._ns, 'name', element.tagName)
attr_map = element.attributes
for attr in attr_map.values():
attr_element = createElement('xupdate:attribute')
attr_element.setAttribute('name', attr.name)
attr_element = createElement(self._ns, 'xupdate:attribute')
attr_element.setAttributeNS(self._ns, 'name', attr.name)
text_node = createTextNode(attr.nodeValue)
attr_element.appendChild(text_node)
child_element.appendChild(attr_element)
......@@ -434,8 +439,7 @@ class ERP5Diff:
# XXX So work around that problem when outputting the result.
if self._result is not None:
self._result.close()
self._result = impl.createDocument('http://www.xmldb.org/xupdate', 'xupdate:modifications', None)
self._result = impl.createDocument(self._ns, 'xupdate:modifications', None)
if self._testElements(old_root_element, new_root_element):
self._testAttributes(old_root_element, new_root_element, '/')
self._compareChildNodes(old_root_element, new_root_element, '/')
......@@ -460,15 +464,7 @@ class ERP5Diff:
# Make sure that the output will be encoded in UTF-8.
writer = codecs.getwriter('utf-8')
file = writer(file)
# XXX minidom is too buggy, so it is required to write this method myself.
file.write('''<?xml version="1.0"?>
<xupdate:modifications version="1.0" xmlns:xupdate="http://www.xmldb.org/xupdate">
''')
for node in self._result.documentElement.childNodes:
node.writexml(file)
file.write('''</xupdate:modifications>
''')
PrettyPrint(self._result.documentElement, stream=file, encoding='UTF-8')
def outputString(self):
"""
......
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