XMLDTDAttList.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Generated by CoffeeScript 2.4.1
  2. (function() {
  3. var NodeType, XMLDTDAttList, XMLNode;
  4. XMLNode = require('./XMLNode');
  5. NodeType = require('./NodeType');
  6. // Represents an attribute list
  7. module.exports = XMLDTDAttList = class XMLDTDAttList extends XMLNode {
  8. // Initializes a new instance of `XMLDTDAttList`
  9. // `parent` the parent `XMLDocType` element
  10. // `elementName` the name of the element containing this attribute
  11. // `attributeName` attribute name
  12. // `attributeType` type of the attribute
  13. // `defaultValueType` default value type (either #REQUIRED, #IMPLIED,
  14. // #FIXED or #DEFAULT)
  15. // `defaultValue` default value of the attribute
  16. // (only used for #FIXED or #DEFAULT)
  17. constructor(parent, elementName, attributeName, attributeType, defaultValueType, defaultValue) {
  18. super(parent);
  19. if (elementName == null) {
  20. throw new Error("Missing DTD element name. " + this.debugInfo());
  21. }
  22. if (attributeName == null) {
  23. throw new Error("Missing DTD attribute name. " + this.debugInfo(elementName));
  24. }
  25. if (!attributeType) {
  26. throw new Error("Missing DTD attribute type. " + this.debugInfo(elementName));
  27. }
  28. if (!defaultValueType) {
  29. throw new Error("Missing DTD attribute default. " + this.debugInfo(elementName));
  30. }
  31. if (defaultValueType.indexOf('#') !== 0) {
  32. defaultValueType = '#' + defaultValueType;
  33. }
  34. if (!defaultValueType.match(/^(#REQUIRED|#IMPLIED|#FIXED|#DEFAULT)$/)) {
  35. throw new Error("Invalid default value type; expected: #REQUIRED, #IMPLIED, #FIXED or #DEFAULT. " + this.debugInfo(elementName));
  36. }
  37. if (defaultValue && !defaultValueType.match(/^(#FIXED|#DEFAULT)$/)) {
  38. throw new Error("Default value only applies to #FIXED or #DEFAULT. " + this.debugInfo(elementName));
  39. }
  40. this.elementName = this.stringify.name(elementName);
  41. this.type = NodeType.AttributeDeclaration;
  42. this.attributeName = this.stringify.name(attributeName);
  43. this.attributeType = this.stringify.dtdAttType(attributeType);
  44. if (defaultValue) {
  45. this.defaultValue = this.stringify.dtdAttDefault(defaultValue);
  46. }
  47. this.defaultValueType = defaultValueType;
  48. }
  49. // Converts the XML fragment to string
  50. // `options.pretty` pretty prints the result
  51. // `options.indent` indentation for pretty print
  52. // `options.offset` how many indentations to add to every line for pretty print
  53. // `options.newline` newline sequence for pretty print
  54. toString(options) {
  55. return this.options.writer.dtdAttList(this, this.options.writer.filterOptions(options));
  56. }
  57. };
  58. }).call(this);