artdaq_node_server  v1_00_09
 All Classes Namespaces Files Variables Pages
XMLBuilder.js
1 // Generated by CoffeeScript 1.9.1
2 (function() {
3  var XMLBuilder, XMLDeclaration, XMLDocType, XMLElement, XMLStringifier;
4 
5  XMLStringifier = require('./XMLStringifier');
6 
7  XMLDeclaration = require('./XMLDeclaration');
8 
9  XMLDocType = require('./XMLDocType');
10 
11  XMLElement = require('./XMLElement');
12 
13  module.exports = XMLBuilder = (function() {
14  function XMLBuilder(name, options) {
15  var root, temp;
16  if (name == null) {
17  throw new Error("Root element needs a name");
18  }
19  if (options == null) {
20  options = {};
21  }
22  this.options = options;
23  this.stringify = new XMLStringifier(options);
24  temp = new XMLElement(this, 'doc');
25  root = temp.element(name);
26  root.isRoot = true;
27  root.documentObject = this;
28  this.rootObject = root;
29  if (!options.headless) {
30  root.declaration(options);
31  if ((options.pubID != null) || (options.sysID != null)) {
32  root.doctype(options);
33  }
34  }
35  }
36 
37  XMLBuilder.prototype.root = function() {
38  return this.rootObject;
39  };
40 
41  XMLBuilder.prototype.end = function(options) {
42  return this.toString(options);
43  };
44 
45  XMLBuilder.prototype.toString = function(options) {
46  var indent, newline, offset, pretty, r, ref, ref1, ref2;
47  pretty = (options != null ? options.pretty : void 0) || false;
48  indent = (ref = options != null ? options.indent : void 0) != null ? ref : ' ';
49  offset = (ref1 = options != null ? options.offset : void 0) != null ? ref1 : 0;
50  newline = (ref2 = options != null ? options.newline : void 0) != null ? ref2 : '\n';
51  r = '';
52  if (this.xmldec != null) {
53  r += this.xmldec.toString(options);
54  }
55  if (this.doctype != null) {
56  r += this.doctype.toString(options);
57  }
58  r += this.rootObject.toString(options);
59  if (pretty && r.slice(-newline.length) === newline) {
60  r = r.slice(0, -newline.length);
61  }
62  return r;
63  };
64 
65  return XMLBuilder;
66 
67  })();
68 
69 }).call(this);