typesxml
Version:
Open source XML library written in TypeScript
73 lines • 3.15 kB
JavaScript
;
/*******************************************************************************
* Copyright (c) 2023-2026 Maxprograms.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-v10.html
*
* Contributors:
* Maxprograms - initial API and implementation
*******************************************************************************/
Object.defineProperty(exports, "__esModule", { value: true });
exports.SchemaWildcardParticle = void 0;
const SchemaParticle_js_1 = require("./SchemaParticle.js");
class SchemaWildcardParticle extends SchemaParticle_js_1.SchemaParticle {
namespace;
processContents;
schemaTargetNamespace;
constructor(namespace = '##any', processContents = 'strict', minOccurs = 1, maxOccurs = 1, schemaTargetNamespace) {
super(minOccurs, maxOccurs);
this.namespace = namespace;
this.processContents = processContents;
this.schemaTargetNamespace = schemaTargetNamespace;
}
matchOnce(children, pos, nsMap, childNamespaces) {
if (pos >= children.length) {
return [];
}
if (this.namespace === '##any') {
return [pos + 1];
}
const childName = children[pos];
const colonIdx = childName.indexOf(':');
const prefix = colonIdx !== -1 ? childName.substring(0, colonIdx) : undefined;
let childNs;
if (childNamespaces !== undefined && pos < childNamespaces.length) {
childNs = childNamespaces[pos] !== '' ? childNamespaces[pos] : undefined;
}
else if (prefix !== undefined) {
childNs = nsMap ? nsMap.get(prefix) : undefined;
if (childNs === undefined) {
throw new Error('Undeclared namespace prefix "' + prefix + '" in element "' + childName + '"');
}
}
else {
const defaultNs = nsMap ? nsMap.get('') : undefined;
childNs = defaultNs !== '' ? defaultNs : undefined;
}
if (this.namespace === '##local') {
return (childNs === undefined || childNs === '') ? [pos + 1] : [];
}
if (this.namespace === '##other') {
const inTarget = this.schemaTargetNamespace !== undefined && childNs === this.schemaTargetNamespace;
return (childNs !== undefined && childNs !== '' && !inTarget) ? [pos + 1] : [];
}
const tokens = this.namespace.split(/\s+/);
for (const token of tokens) {
if (token === '##local' && (childNs === undefined || childNs === '')) {
return [pos + 1];
}
if (token === '##targetNamespace' && childNs !== undefined && childNs === this.schemaTargetNamespace) {
return [pos + 1];
}
if (token === childNs) {
return [pos + 1];
}
}
return [];
}
}
exports.SchemaWildcardParticle = SchemaWildcardParticle;
//# sourceMappingURL=SchemaWildcardParticle.js.map