You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XMLDTDEntity.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Generated by CoffeeScript 2.4.1
  2. (function() {
  3. var NodeType, XMLDTDEntity, XMLNode, isObject;
  4. ({isObject} = require('./Utility'));
  5. XMLNode = require('./XMLNode');
  6. NodeType = require('./NodeType');
  7. // Represents an entity declaration in the DTD
  8. module.exports = XMLDTDEntity = (function() {
  9. class XMLDTDEntity extends XMLNode {
  10. // Initializes a new instance of `XMLDTDEntity`
  11. // `parent` the parent `XMLDocType` element
  12. // `pe` whether this is a parameter entity or a general entity
  13. // defaults to `false` (general entity)
  14. // `name` the name of the entity
  15. // `value` internal entity value or an object with external entity details
  16. // `value.pubID` public identifier
  17. // `value.sysID` system identifier
  18. // `value.nData` notation declaration
  19. constructor(parent, pe, name, value) {
  20. super(parent);
  21. if (name == null) {
  22. throw new Error("Missing DTD entity name. " + this.debugInfo(name));
  23. }
  24. if (value == null) {
  25. throw new Error("Missing DTD entity value. " + this.debugInfo(name));
  26. }
  27. this.pe = !!pe;
  28. this.name = this.stringify.name(name);
  29. this.type = NodeType.EntityDeclaration;
  30. if (!isObject(value)) {
  31. this.value = this.stringify.dtdEntityValue(value);
  32. this.internal = true;
  33. } else {
  34. if (!value.pubID && !value.sysID) {
  35. throw new Error("Public and/or system identifiers are required for an external entity. " + this.debugInfo(name));
  36. }
  37. if (value.pubID && !value.sysID) {
  38. throw new Error("System identifier is required for a public external entity. " + this.debugInfo(name));
  39. }
  40. this.internal = false;
  41. if (value.pubID != null) {
  42. this.pubID = this.stringify.dtdPubID(value.pubID);
  43. }
  44. if (value.sysID != null) {
  45. this.sysID = this.stringify.dtdSysID(value.sysID);
  46. }
  47. if (value.nData != null) {
  48. this.nData = this.stringify.dtdNData(value.nData);
  49. }
  50. if (this.pe && this.nData) {
  51. throw new Error("Notation declaration is not allowed in a parameter entity. " + this.debugInfo(name));
  52. }
  53. }
  54. }
  55. // Converts the XML fragment to string
  56. // `options.pretty` pretty prints the result
  57. // `options.indent` indentation for pretty print
  58. // `options.offset` how many indentations to add to every line for pretty print
  59. // `options.newline` newline sequence for pretty print
  60. toString(options) {
  61. return this.options.writer.dtdEntity(this, this.options.writer.filterOptions(options));
  62. }
  63. };
  64. // DOM level 1
  65. Object.defineProperty(XMLDTDEntity.prototype, 'publicId', {
  66. get: function() {
  67. return this.pubID;
  68. }
  69. });
  70. Object.defineProperty(XMLDTDEntity.prototype, 'systemId', {
  71. get: function() {
  72. return this.sysID;
  73. }
  74. });
  75. Object.defineProperty(XMLDTDEntity.prototype, 'notationName', {
  76. get: function() {
  77. return this.nData || null;
  78. }
  79. });
  80. // DOM level 3
  81. Object.defineProperty(XMLDTDEntity.prototype, 'inputEncoding', {
  82. get: function() {
  83. return null;
  84. }
  85. });
  86. Object.defineProperty(XMLDTDEntity.prototype, 'xmlEncoding', {
  87. get: function() {
  88. return null;
  89. }
  90. });
  91. Object.defineProperty(XMLDTDEntity.prototype, 'xmlVersion', {
  92. get: function() {
  93. return null;
  94. }
  95. });
  96. return XMLDTDEntity;
  97. }).call(this);
  98. }).call(this);