XmlDtdEntity.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. "use strict";
  2. /**
  3. * Copyright (C) 2016-2019 Michael Kourlas
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. Object.defineProperty(exports, "__esModule", { value: true });
  18. var error_1 = require("../error");
  19. var validate_1 = require("../validate");
  20. /**
  21. * Represents an entity declaration in a document type definition.
  22. *
  23. * An entity declaration is structured as follows, where `{text}` is the
  24. * text of the declaration:
  25. *
  26. * ```xml
  27. * <!ENTITY {text}>
  28. * ```
  29. */
  30. var XmlDtdEntity = /** @class */ (function () {
  31. function XmlDtdEntity(parent, validation, options) {
  32. this._validation = validation;
  33. this._parent = parent;
  34. this.charData = options.charData;
  35. }
  36. Object.defineProperty(XmlDtdEntity.prototype, "charData", {
  37. /**
  38. * Gets the text of this entity declaration.
  39. */
  40. get: function () {
  41. return this._charData;
  42. },
  43. /**
  44. * Sets the text of this entity declaration.
  45. */
  46. set: function (charData) {
  47. if (this._validation && !(0, validate_1.validateChar)(charData)) {
  48. throw new Error((0, error_1.getContext)(this.up()) + ": entity declaration"
  49. + (" \"" + charData + "\" should not contain characters")
  50. + " not allowed in XML");
  51. }
  52. this._charData = charData;
  53. },
  54. enumerable: false,
  55. configurable: true
  56. });
  57. /**
  58. * Returns an XML string representation of this entity declaration.
  59. */
  60. XmlDtdEntity.prototype.toString = function () {
  61. return "<!ENTITY " + this._charData + ">";
  62. };
  63. /**
  64. * Returns the parent of this entity declaration.
  65. */
  66. XmlDtdEntity.prototype.up = function () {
  67. return this._parent;
  68. };
  69. return XmlDtdEntity;
  70. }());
  71. exports.default = XmlDtdEntity;