123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- "use strict";
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var error_1 = require("../error");
- var escape_1 = require("../escape");
- var options_1 = require("../options");
- var validate_1 = require("../validate");
- var XmlAttributeText_1 = __importDefault(require("./XmlAttributeText"));
- var XmlCharRef_1 = __importDefault(require("./XmlCharRef"));
- var XmlEntityRef_1 = __importDefault(require("./XmlEntityRef"));
- var XmlAttribute = (function () {
- function XmlAttribute(parent, validation, options) {
- this._validation = validation;
- if (!(0, validate_1.isUndefined)(options.replaceInvalidCharsInName)) {
- this._replaceInvalidCharsInName = options.replaceInvalidCharsInName;
- }
- else {
- this._replaceInvalidCharsInName = false;
- }
- this._children = [];
- this._parent = parent;
- this.name = options.name;
- }
- Object.defineProperty(XmlAttribute.prototype, "name", {
-
- get: function () {
- return this._name;
- },
-
- set: function (name) {
- if (this._replaceInvalidCharsInName) {
- name = (0, validate_1.fixName)(name);
- if (name.length === 0) {
- throw new Error((0, error_1.getContext)(this.up()) + ": attribute name"
- + " should not be empty");
- }
- }
- else if (this._validation && !(0, validate_1.validateName)(name)) {
- if (name.length === 0) {
- throw new Error((0, error_1.getContext)(this.up()) + ": attribute name"
- + " should not be empty");
- }
- else {
- throw new Error((0, error_1.getContext)(this.up()) + ": attribute name"
- + (" \"" + name + "\" should not contain characters not")
- + " allowed in XML names");
- }
- }
- this._name = name;
- },
- enumerable: false,
- configurable: true
- });
-
- XmlAttribute.prototype.charRef = function (options) {
- var charRef = new XmlCharRef_1.default(this, this._validation, options);
- this._children.push(charRef);
- return charRef;
- };
-
- XmlAttribute.prototype.entityRef = function (options) {
- var charRef = new XmlEntityRef_1.default(this, this._validation, options);
- this._children.push(charRef);
- return charRef;
- };
-
- XmlAttribute.prototype.text = function (options) {
- var textNode = new XmlAttributeText_1.default(this, this._validation, options);
- this._children.push(textNode);
- return textNode;
- };
-
- XmlAttribute.prototype.toString = function (options) {
- if (options === void 0) { options = {}; }
- var optionsObj = new options_1.StringOptions(options);
- var quote = optionsObj.doubleQuotes ? "\"" : "'";
- var str = this._name + "=" + quote;
- for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
- var child = _a[_i];
- if (optionsObj.doubleQuotes) {
- str += (0, escape_1.escapeDoubleQuotes)(child.toString());
- }
- else {
- str += (0, escape_1.escapeSingleQuotes)(child.toString());
- }
- }
- str += quote;
- return str;
- };
-
- XmlAttribute.prototype.up = function () {
- return this._parent;
- };
- return XmlAttribute;
- }());
- exports.default = XmlAttribute;
|