Liferay.Loader.define("portal-workflow-kaleo-designer-web@5.0.92/designer/js/definition-builder/source-builder/xmlSchemaUtil",["module","exports","require","../util/utils"],(function(e,t,n){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var o=n("../util/utils");function getChildAttributes(e){const t=[];return Object.entries(e).map((e=>{const n=e[1].attributes;n&&Object.entries(n).map((e=>{t.push({[e[1].value]:e[1].ownerElement.textContent})}))})),t}function getLocationValue(e,t){let n=e.locator||e.key||e;"taskTimers"===n&&(n="task-timers");const o=t.ownerDocument||t;let r,a;const l={};if(void 0!==o.evaluate)for(r=o.evaluate(n,t,o.createNSResolver(t.ownerDocument?t.ownerDocument.documentElement:t.documentElement),0,null);a=r.iterateNext();){const e=getChildAttributes(a.childNodes);if(e.length)l.content=e;else if(a.children.length){const e=[];for(const t of a.children){const n={};if(t.children.length)for(const e of t.children)if(e.children.length){let t,o=[],r=[];for(const a of e.children){o=getChildAttributes(a.childNodes);for(const e of a.childNodes)if(e.children)for(const t of e.children){const o="name"===t.tagName?"".concat(e.tagName,"-name"):t.tagName;n[o]||(n[o]=[]),n[o].push(t.textContent)}const l=getChildAttributes(e.childNodes);let s;if(o.length)s=o;else{if(l.length){s=l,l.length&&(n[e.tagName]||(n[e.tagName]=[]),n[e.tagName]=s);break}if(a.children.length){t?t!==a.tagName&&(r=[]):t=a.tagName,t=a.tagName;const e={};for(const t of a.children)if(t.children.length)for(const e of t.children){const t={};t[e.tagName]=e.textContent,r.push(t)}else e[t.tagName]=t.textContent;r.push(e)}else s=a.textContent,n[a.tagName]||(n[a.tagName]=[]),n[a.tagName].push(s)}n[t]=r}const a=e.attributes;if(a&&a.length)for(let e=0;e<a.length;e++)n[a[e].name]||(n[a[e].name]=[]),n[a[e].name].push(a[e].value)}else{const t=getChildAttributes(e.childNodes);let o;o=t.length?t:e.textContent,n[e.tagName]?Array.isArray(n[e.tagName])?n[e.tagName]=[...n[e.tagName],o]:n[e.tagName]=[n[e.tagName],o]:n[e.tagName]=o}else{const e=getChildAttributes(t.childNodes);let o;o=e.length?e:t.textContent,n[t.tagName]=o}e.push(n)}l.content=e}else l.content=a.textContent}return function parse(e,t){return t.parser&&t.parser instanceof Function&&(e.content=t.parser.call(this,e.content)),e}(l,e)}var r={applySchema(e,t){const n=t;let r={meta:{},results:[]};return n&&n.nodeType&&(9===n.nodeType||1===n.nodeType||11===n.nodeType)&&e?(r=function parseResults(e,t,n){if(e.resultListLocator&&Array.isArray(e.resultFields)){const o=t.getElementsByTagName(e.resultListLocator),r=e.resultFields,a=[];let l,s,i,c,u;if(o.length){for(c=o.length-1;c>=0;c--){for(i={},l=o[c],u=r.length-1;u>=0;u--){s=r[u];const e=getLocationValue(s,l);i[s.key||s]=e.content,e.attributes&&(i.metaAttributes=e.attributes)}a[c]=i}n.results=a}else n.error=new Error("XML schema result nodes retrieval failure")}return n}(e,n,r),r=function parseMeta(e,t,n){if((0,o.isObject)(e)){const o=t.ownerDocument||t;for(var r in e)Object.keys(e).includes(r)&&(n.meta[r]=getLocationValue(e[r],o).content)}return n}(e.metaFields,n,r)):r.error=new Error("XML schema parse failure"),r}};t.default=r}}));
//# sourceMappingURL=xmlSchemaUtil.js.map