XmlEntityRef.js 2.2 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 reference.
  22. *
  23. * An entity reference is structured as follows, where `{name}` is the name of
  24. * the entity to be referenced:
  25. *
  26. * ```xml
  27. * &{entity};
  28. * ```
  29. */
  30. var XmlEntityRef = /** @class */ (function () {
  31. function XmlEntityRef(parent, validation, options) {
  32. this._validation = validation;
  33. this._parent = parent;
  34. this.name = options.name;
  35. }
  36. Object.defineProperty(XmlEntityRef.prototype, "name", {
  37. /**
  38. * Gets the name of this entity reference.
  39. */
  40. get: function () {
  41. return this._name;
  42. },
  43. /**
  44. * Sets the name of this 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()) + ": entity reference name"
  49. + (" \"" + name + "\" should not contain characters not")
  50. + " 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 entity reference.
  59. */
  60. XmlEntityRef.prototype.toString = function () {
  61. return "&" + this._name + ";";
  62. };
  63. /**
  64. * Returns the parent of this entity reference.
  65. */
  66. XmlEntityRef.prototype.up = function () {
  67. return this._parent;
  68. };
  69. return XmlEntityRef;
  70. }());
  71. exports.default = XmlEntityRef;