UNPKG

typesxml

Version:

Open source XML library written in TypeScript

166 lines 4.32 kB
"use strict"; /******************************************************************************* * Copyright (c) 2023-2026 Maxprograms. * * This program and the accompanying materials * are made available under the terms of the Eclipse 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.JsonEventStreamWriter = void 0; class JsonEventStreamWriter { writer; arrayStarted; firstEvent; closed; catalog; grammar; constructor(writer) { this.writer = writer; this.arrayStarted = false; this.firstEvent = true; this.closed = false; } initialize() { this.arrayStarted = false; this.firstEvent = true; this.closed = false; } setCatalog(catalog) { this.catalog = catalog; } setGrammar(grammar) { this.grammar = grammar; } getGrammar() { return this.grammar; } getCurrentText() { return ''; } startDocument() { this.writeEvent({ type: "startDocument" }); } endDocument() { this.writeEvent({ type: "endDocument" }); this.closeArray(); } xmlDeclaration(version, encoding, standalone) { this.writeEvent({ type: "xmlDeclaration", version: version, encoding: encoding, standalone: standalone }); } startElement(name, atts) { const attributes = new Array(); for (let index = 0; index < atts.length; index++) { const attribute = atts[index]; const descriptor = { name: attribute.getName(), value: attribute.getValue() }; attributes.push(descriptor); } this.writeEvent({ type: "startElement", name: name, attributes: attributes }); } endElement(name) { this.writeEvent({ type: "endElement", name: name }); } internalSubset(declaration) { this.writeEvent({ type: "internalSubset", declaration: declaration }); } characters(ch) { this.writeEvent({ type: "characters", value: ch }); } ignorableWhitespace(ch) { this.writeEvent({ type: "ignorableWhitespace", value: ch }); } comment(ch) { this.writeEvent({ type: "comment", value: ch }); } processingInstruction(target, data) { this.writeEvent({ type: "processingInstruction", target: target, data: data }); } startCDATA() { this.writeEvent({ type: "startCDATA" }); } endCDATA() { this.writeEvent({ type: "endCDATA" }); } startDTD(name, publicId, systemId) { this.writeEvent({ type: "startDTD", name: name, publicId: publicId, systemId: systemId }); } endDTD() { this.writeEvent({ type: "endDTD" }); } skippedEntity(name) { this.writeEvent({ type: "skippedEntity", name: name }); } writeEvent(event) { this.ensureArrayStarted(); if (!this.firstEvent) { this.writer.write(","); } const payload = JSON.stringify(event); this.writer.write(payload); this.firstEvent = false; } closeArray() { if (this.closed) { return; } if (!this.arrayStarted) { this.writer.write("[]"); this.closed = true; return; } this.writer.write("]"); this.closed = true; } ensureArrayStarted() { if (this.arrayStarted) { return; } this.writer.write("["); this.arrayStarted = true; } } exports.JsonEventStreamWriter = JsonEventStreamWriter; //# sourceMappingURL=JsonEventStreamWriter.js.map