XMLDocument.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. // Generated by CoffeeScript 2.4.1
  2. (function() {
  3. var NodeType, XMLDOMConfiguration, XMLDOMImplementation, XMLDocument, XMLNode, XMLStringWriter, XMLStringifier, isPlainObject;
  4. ({isPlainObject} = require('./Utility'));
  5. XMLDOMImplementation = require('./XMLDOMImplementation');
  6. XMLDOMConfiguration = require('./XMLDOMConfiguration');
  7. XMLNode = require('./XMLNode');
  8. NodeType = require('./NodeType');
  9. XMLStringifier = require('./XMLStringifier');
  10. XMLStringWriter = require('./XMLStringWriter');
  11. // Represents an XML builder
  12. module.exports = XMLDocument = (function() {
  13. class XMLDocument extends XMLNode {
  14. // Initializes a new instance of `XMLDocument`
  15. // `options.keepNullNodes` whether nodes with null values will be kept
  16. // or ignored: true or false
  17. // `options.keepNullAttributes` whether attributes with null values will be
  18. // kept or ignored: true or false
  19. // `options.ignoreDecorators` whether decorator strings will be ignored when
  20. // converting JS objects: true or false
  21. // `options.separateArrayItems` whether array items are created as separate
  22. // nodes when passed as an object value: true or false
  23. // `options.noDoubleEncoding` whether existing html entities are encoded:
  24. // true or false
  25. // `options.stringify` a set of functions to use for converting values to
  26. // strings
  27. // `options.writer` the default XML writer to use for converting nodes to
  28. // string. If the default writer is not set, the built-in XMLStringWriter
  29. // will be used instead.
  30. constructor(options) {
  31. super(null);
  32. this.name = "#document";
  33. this.type = NodeType.Document;
  34. this.documentURI = null;
  35. this.domConfig = new XMLDOMConfiguration();
  36. options || (options = {});
  37. if (!options.writer) {
  38. options.writer = new XMLStringWriter();
  39. }
  40. this.options = options;
  41. this.stringify = new XMLStringifier(options);
  42. }
  43. // Ends the document and passes it to the given XML writer
  44. // `writer` is either an XML writer or a plain object to pass to the
  45. // constructor of the default XML writer. The default writer is assigned when
  46. // creating the XML document. Following flags are recognized by the
  47. // built-in XMLStringWriter:
  48. // `writer.pretty` pretty prints the result
  49. // `writer.indent` indentation for pretty print
  50. // `writer.offset` how many indentations to add to every line for pretty print
  51. // `writer.newline` newline sequence for pretty print
  52. end(writer) {
  53. var writerOptions;
  54. writerOptions = {};
  55. if (!writer) {
  56. writer = this.options.writer;
  57. } else if (isPlainObject(writer)) {
  58. writerOptions = writer;
  59. writer = this.options.writer;
  60. }
  61. return writer.document(this, writer.filterOptions(writerOptions));
  62. }
  63. // Converts the XML document to string
  64. // `options.pretty` pretty prints the result
  65. // `options.indent` indentation for pretty print
  66. // `options.offset` how many indentations to add to every line for pretty print
  67. // `options.newline` newline sequence for pretty print
  68. toString(options) {
  69. return this.options.writer.document(this, this.options.writer.filterOptions(options));
  70. }
  71. // DOM level 1 functions to be implemented later
  72. createElement(tagName) {
  73. throw new Error("This DOM method is not implemented." + this.debugInfo());
  74. }
  75. createDocumentFragment() {
  76. throw new Error("This DOM method is not implemented." + this.debugInfo());
  77. }
  78. createTextNode(data) {
  79. throw new Error("This DOM method is not implemented." + this.debugInfo());
  80. }
  81. createComment(data) {
  82. throw new Error("This DOM method is not implemented." + this.debugInfo());
  83. }
  84. createCDATASection(data) {
  85. throw new Error("This DOM method is not implemented." + this.debugInfo());
  86. }
  87. createProcessingInstruction(target, data) {
  88. throw new Error("This DOM method is not implemented." + this.debugInfo());
  89. }
  90. createAttribute(name) {
  91. throw new Error("This DOM method is not implemented." + this.debugInfo());
  92. }
  93. createEntityReference(name) {
  94. throw new Error("This DOM method is not implemented." + this.debugInfo());
  95. }
  96. getElementsByTagName(tagname) {
  97. throw new Error("This DOM method is not implemented." + this.debugInfo());
  98. }
  99. // DOM level 2 functions to be implemented later
  100. importNode(importedNode, deep) {
  101. throw new Error("This DOM method is not implemented." + this.debugInfo());
  102. }
  103. createElementNS(namespaceURI, qualifiedName) {
  104. throw new Error("This DOM method is not implemented." + this.debugInfo());
  105. }
  106. createAttributeNS(namespaceURI, qualifiedName) {
  107. throw new Error("This DOM method is not implemented." + this.debugInfo());
  108. }
  109. getElementsByTagNameNS(namespaceURI, localName) {
  110. throw new Error("This DOM method is not implemented." + this.debugInfo());
  111. }
  112. getElementById(elementId) {
  113. throw new Error("This DOM method is not implemented." + this.debugInfo());
  114. }
  115. // DOM level 3 functions to be implemented later
  116. adoptNode(source) {
  117. throw new Error("This DOM method is not implemented." + this.debugInfo());
  118. }
  119. normalizeDocument() {
  120. throw new Error("This DOM method is not implemented." + this.debugInfo());
  121. }
  122. renameNode(node, namespaceURI, qualifiedName) {
  123. throw new Error("This DOM method is not implemented." + this.debugInfo());
  124. }
  125. // DOM level 4 functions to be implemented later
  126. getElementsByClassName(classNames) {
  127. throw new Error("This DOM method is not implemented." + this.debugInfo());
  128. }
  129. createEvent(eventInterface) {
  130. throw new Error("This DOM method is not implemented." + this.debugInfo());
  131. }
  132. createRange() {
  133. throw new Error("This DOM method is not implemented." + this.debugInfo());
  134. }
  135. createNodeIterator(root, whatToShow, filter) {
  136. throw new Error("This DOM method is not implemented." + this.debugInfo());
  137. }
  138. createTreeWalker(root, whatToShow, filter) {
  139. throw new Error("This DOM method is not implemented." + this.debugInfo());
  140. }
  141. };
  142. // DOM level 1
  143. Object.defineProperty(XMLDocument.prototype, 'implementation', {
  144. value: new XMLDOMImplementation()
  145. });
  146. Object.defineProperty(XMLDocument.prototype, 'doctype', {
  147. get: function() {
  148. var child, i, len, ref;
  149. ref = this.children;
  150. for (i = 0, len = ref.length; i < len; i++) {
  151. child = ref[i];
  152. if (child.type === NodeType.DocType) {
  153. return child;
  154. }
  155. }
  156. return null;
  157. }
  158. });
  159. Object.defineProperty(XMLDocument.prototype, 'documentElement', {
  160. get: function() {
  161. return this.rootObject || null;
  162. }
  163. });
  164. // DOM level 3
  165. Object.defineProperty(XMLDocument.prototype, 'inputEncoding', {
  166. get: function() {
  167. return null;
  168. }
  169. });
  170. Object.defineProperty(XMLDocument.prototype, 'strictErrorChecking', {
  171. get: function() {
  172. return false;
  173. }
  174. });
  175. Object.defineProperty(XMLDocument.prototype, 'xmlEncoding', {
  176. get: function() {
  177. if (this.children.length !== 0 && this.children[0].type === NodeType.Declaration) {
  178. return this.children[0].encoding;
  179. } else {
  180. return null;
  181. }
  182. }
  183. });
  184. Object.defineProperty(XMLDocument.prototype, 'xmlStandalone', {
  185. get: function() {
  186. if (this.children.length !== 0 && this.children[0].type === NodeType.Declaration) {
  187. return this.children[0].standalone === 'yes';
  188. } else {
  189. return false;
  190. }
  191. }
  192. });
  193. Object.defineProperty(XMLDocument.prototype, 'xmlVersion', {
  194. get: function() {
  195. if (this.children.length !== 0 && this.children[0].type === NodeType.Declaration) {
  196. return this.children[0].version;
  197. } else {
  198. return "1.0";
  199. }
  200. }
  201. });
  202. // DOM level 4
  203. Object.defineProperty(XMLDocument.prototype, 'URL', {
  204. get: function() {
  205. return this.documentURI;
  206. }
  207. });
  208. Object.defineProperty(XMLDocument.prototype, 'origin', {
  209. get: function() {
  210. return null;
  211. }
  212. });
  213. Object.defineProperty(XMLDocument.prototype, 'compatMode', {
  214. get: function() {
  215. return null;
  216. }
  217. });
  218. Object.defineProperty(XMLDocument.prototype, 'characterSet', {
  219. get: function() {
  220. return null;
  221. }
  222. });
  223. Object.defineProperty(XMLDocument.prototype, 'contentType', {
  224. get: function() {
  225. return null;
  226. }
  227. });
  228. return XMLDocument;
  229. }).call(this);
  230. }).call(this);