artdaq_node_server  v1_00_09
 All Classes Namespaces Files Variables Pages
XMLStringifier.js
1 // Generated by CoffeeScript 1.9.1
2 (function() {
3  var XMLStringifier,
4  bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
5  hasProp = {}.hasOwnProperty;
6 
7  module.exports = XMLStringifier = (function() {
8  function XMLStringifier(options) {
9  this.assertLegalChar = bind(this.assertLegalChar, this);
10  var key, ref, value;
11  this.allowSurrogateChars = options != null ? options.allowSurrogateChars : void 0;
12  this.noDoubleEncoding = options != null ? options.noDoubleEncoding : void 0;
13  ref = (options != null ? options.stringify : void 0) || {};
14  for (key in ref) {
15  if (!hasProp.call(ref, key)) continue;
16  value = ref[key];
17  this[key] = value;
18  }
19  }
20 
21  XMLStringifier.prototype.eleName = function(val) {
22  val = '' + val || '';
23  return this.assertLegalChar(val);
24  };
25 
26  XMLStringifier.prototype.eleText = function(val) {
27  val = '' + val || '';
28  return this.assertLegalChar(this.elEscape(val));
29  };
30 
31  XMLStringifier.prototype.cdata = function(val) {
32  val = '' + val || '';
33  if (val.match(/]]>/)) {
34  throw new Error("Invalid CDATA text: " + val);
35  }
36  return this.assertLegalChar(val);
37  };
38 
39  XMLStringifier.prototype.comment = function(val) {
40  val = '' + val || '';
41  if (val.match(/--/)) {
42  throw new Error("Comment text cannot contain double-hypen: " + val);
43  }
44  return this.assertLegalChar(val);
45  };
46 
47  XMLStringifier.prototype.raw = function(val) {
48  return '' + val || '';
49  };
50 
51  XMLStringifier.prototype.attName = function(val) {
52  return '' + val || '';
53  };
54 
55  XMLStringifier.prototype.attValue = function(val) {
56  val = '' + val || '';
57  return this.attEscape(val);
58  };
59 
60  XMLStringifier.prototype.insTarget = function(val) {
61  return '' + val || '';
62  };
63 
64  XMLStringifier.prototype.insValue = function(val) {
65  val = '' + val || '';
66  if (val.match(/\?>/)) {
67  throw new Error("Invalid processing instruction value: " + val);
68  }
69  return val;
70  };
71 
72  XMLStringifier.prototype.xmlVersion = function(val) {
73  val = '' + val || '';
74  if (!val.match(/1\.[0-9]+/)) {
75  throw new Error("Invalid version number: " + val);
76  }
77  return val;
78  };
79 
80  XMLStringifier.prototype.xmlEncoding = function(val) {
81  val = '' + val || '';
82  if (!val.match(/^[A-Za-z](?:[A-Za-z0-9._-]|-)*$/)) {
83  throw new Error("Invalid encoding: " + val);
84  }
85  return val;
86  };
87 
88  XMLStringifier.prototype.xmlStandalone = function(val) {
89  if (val) {
90  return "yes";
91  } else {
92  return "no";
93  }
94  };
95 
96  XMLStringifier.prototype.dtdPubID = function(val) {
97  return '' + val || '';
98  };
99 
100  XMLStringifier.prototype.dtdSysID = function(val) {
101  return '' + val || '';
102  };
103 
104  XMLStringifier.prototype.dtdElementValue = function(val) {
105  return '' + val || '';
106  };
107 
108  XMLStringifier.prototype.dtdAttType = function(val) {
109  return '' + val || '';
110  };
111 
112  XMLStringifier.prototype.dtdAttDefault = function(val) {
113  if (val != null) {
114  return '' + val || '';
115  } else {
116  return val;
117  }
118  };
119 
120  XMLStringifier.prototype.dtdEntityValue = function(val) {
121  return '' + val || '';
122  };
123 
124  XMLStringifier.prototype.dtdNData = function(val) {
125  return '' + val || '';
126  };
127 
128  XMLStringifier.prototype.convertAttKey = '@';
129 
130  XMLStringifier.prototype.convertPIKey = '?';
131 
132  XMLStringifier.prototype.convertTextKey = '#text';
133 
134  XMLStringifier.prototype.convertCDataKey = '#cdata';
135 
136  XMLStringifier.prototype.convertCommentKey = '#comment';
137 
138  XMLStringifier.prototype.convertRawKey = '#raw';
139 
140  XMLStringifier.prototype.assertLegalChar = function(str) {
141  var chars, chr;
142  if (this.allowSurrogateChars) {
143  chars = /[\u0000-\u0008\u000B-\u000C\u000E-\u001F\uFFFE-\uFFFF]/;
144  } else {
145  chars = /[\u0000-\u0008\u000B-\u000C\u000E-\u001F\uD800-\uDFFF\uFFFE-\uFFFF]/;
146  }
147  chr = str.match(chars);
148  if (chr) {
149  throw new Error("Invalid character (" + chr + ") in string: " + str + " at index " + chr.index);
150  }
151  return str;
152  };
153 
154  XMLStringifier.prototype.elEscape = function(str) {
155  var ampregex;
156  ampregex = this.noDoubleEncoding ? /(?!&\S+;)&/g : /&/g;
157  return str.replace(ampregex, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\r/g, '&#xD;');
158  };
159 
160  XMLStringifier.prototype.attEscape = function(str) {
161  var ampregex;
162  ampregex = this.noDoubleEncoding ? /(?!&\S+;)&/g : /&/g;
163  return str.replace(ampregex, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
164  };
165 
166  return XMLStringifier;
167 
168  })();
169 
170 }).call(this);