XmlDtdParamEntityRef.js 2.4 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 a parameter entity reference in a document type definition.
  22. *
  23. * A parameter entity reference is structured as follows, where `{entity}`
  24. * is the name of the entity:
  25. *
  26. * ```xml
  27. * %{entity};
  28. * ```
  29. */
  30. var XmlDtdParamEntityRef = /** @class */ (function () {
  31. function XmlDtdParamEntityRef(parent, validation, options) {
  32. this._validation = validation;
  33. this._parent = parent;
  34. this.name = options.name;
  35. }
  36. Object.defineProperty(XmlDtdParamEntityRef.prototype, "name", {
  37. /**
  38. * Gets the name of this parameter entity reference.
  39. */
  40. get: function () {
  41. return this._name;
  42. },
  43. /**
  44. * Sets the name of this parameter entity reference.
  45. */
  46. set: function (name) {
  47. if (this._validation && !(0, validate_1.validateName)(name)) {
  48. throw new Error((0, error_1.getContext)(this.up()) + ": parameter entity"
  49. + (" reference name \"" + name + "\" should not contain")
  50. + " characters not allowed in XML names");
  51. }
  52. this._name = name;
  53. },
  54. enumerable: false,
  55. configurable: true
  56. });
  57. /**
  58. * Returns an XML string representation of this parameter entity reference.
  59. */
  60. XmlDtdParamEntityRef.prototype.toString = function () {
  61. return "%" + this._name + ";";
  62. };
  63. /**
  64. * Returns the parent of this parameter entity reference.
  65. */
  66. XmlDtdParamEntityRef.prototype.up = function () {
  67. return this._parent;
  68. };
  69. return XmlDtdParamEntityRef;
  70. }());
  71. exports.default = XmlDtdParamEntityRef;