artdaq_node_server  v1_00_08
 All Classes Namespaces Files Variables Pages
XMLDTDEntity.js
1 // Generated by CoffeeScript 1.9.1
2 (function() {
3  var XMLDTDEntity, create, isObject;
4 
5  create = require('lodash/create');
6 
7  isObject = require('lodash/isObject');
8 
9  module.exports = XMLDTDEntity = (function() {
10  function XMLDTDEntity(parent, pe, name, value) {
11  this.stringify = parent.stringify;
12  if (name == null) {
13  throw new Error("Missing entity name");
14  }
15  if (value == null) {
16  throw new Error("Missing entity value");
17  }
18  this.pe = !!pe;
19  this.name = this.stringify.eleName(name);
20  if (!isObject(value)) {
21  this.value = this.stringify.dtdEntityValue(value);
22  } else {
23  if (!value.pubID && !value.sysID) {
24  throw new Error("Public and/or system identifiers are required for an external entity");
25  }
26  if (value.pubID && !value.sysID) {
27  throw new Error("System identifier is required for a public external entity");
28  }
29  if (value.pubID != null) {
30  this.pubID = this.stringify.dtdPubID(value.pubID);
31  }
32  if (value.sysID != null) {
33  this.sysID = this.stringify.dtdSysID(value.sysID);
34  }
35  if (value.nData != null) {
36  this.nData = this.stringify.dtdNData(value.nData);
37  }
38  if (this.pe && this.nData) {
39  throw new Error("Notation declaration is not allowed in a parameter entity");
40  }
41  }
42  }
43 
44  XMLDTDEntity.prototype.toString = function(options, level) {
45  var indent, newline, offset, pretty, r, ref, ref1, ref2, space;
46  pretty = (options != null ? options.pretty : void 0) || false;
47  indent = (ref = options != null ? options.indent : void 0) != null ? ref : ' ';
48  offset = (ref1 = options != null ? options.offset : void 0) != null ? ref1 : 0;
49  newline = (ref2 = options != null ? options.newline : void 0) != null ? ref2 : '\n';
50  level || (level = 0);
51  space = new Array(level + offset + 1).join(indent);
52  r = '';
53  if (pretty) {
54  r += space;
55  }
56  r += '<!ENTITY';
57  if (this.pe) {
58  r += ' %';
59  }
60  r += ' ' + this.name;
61  if (this.value) {
62  r += ' "' + this.value + '"';
63  } else {
64  if (this.pubID && this.sysID) {
65  r += ' PUBLIC "' + this.pubID + '" "' + this.sysID + '"';
66  } else if (this.sysID) {
67  r += ' SYSTEM "' + this.sysID + '"';
68  }
69  if (this.nData) {
70  r += ' NDATA ' + this.nData;
71  }
72  }
73  r += '>';
74  if (pretty) {
75  r += newline;
76  }
77  return r;
78  };
79 
80  return XMLDTDEntity;
81 
82  })();
83 
84 }).call(this);