[REF] web: remove useless view_utils file
The helper json_node_to_xml won't be used outside of the legacy code.
This commit is contained in:
committed by
Mathieu Duckerts-Antoine
parent
dd8bf39d2a
commit
2ebddcc585
@@ -1,60 +0,0 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
/**
|
||||
* For debugging purpose, this function will convert a json node back to xml
|
||||
*
|
||||
* @param {Object} node
|
||||
* @param {boolean} [humanReadable]
|
||||
* @param {number} [indent]
|
||||
* @returns {string} the XML representation of the JSON node
|
||||
*/
|
||||
export function json_node_to_xml(node, humanReadable, indent) {
|
||||
indent = indent || 0;
|
||||
const sindent = humanReadable ? new Array(indent + 1).join("\t") : "";
|
||||
let r = sindent + "<" + node.tag;
|
||||
const cr = humanReadable ? "\n" : "";
|
||||
if (typeof node === "string") {
|
||||
return (
|
||||
sindent +
|
||||
node
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
);
|
||||
} else if (
|
||||
typeof node.tag !== "string" ||
|
||||
!(node.children instanceof Array) ||
|
||||
!(node.attrs instanceof Object)
|
||||
) {
|
||||
throw new Error(`Node [${JSON.stringify(node)}] is not a JSONified XML node`);
|
||||
}
|
||||
for (const attr in node.attrs) {
|
||||
let vattr = node.attrs[attr];
|
||||
if (typeof vattr !== "string") {
|
||||
// domains, ...
|
||||
vattr = JSON.stringify(vattr);
|
||||
}
|
||||
vattr = vattr
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """);
|
||||
if (humanReadable) {
|
||||
vattr = vattr.replace(/"/g, "'");
|
||||
}
|
||||
r += " " + attr + '="' + vattr + '"';
|
||||
}
|
||||
if (node.children && node.children.length) {
|
||||
r += ">" + cr;
|
||||
const childs = [];
|
||||
for (let i = 0, ii = node.children.length; i < ii; i++) {
|
||||
childs.push(json_node_to_xml(node.children[i], humanReadable, indent + 1));
|
||||
}
|
||||
r += childs.join(cr);
|
||||
r += cr + sindent + "</" + node.tag + ">";
|
||||
return r;
|
||||
} else {
|
||||
return r + "/>";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user