artdaq_node_server  v1_00_08
 All Classes Namespaces Files Variables Pages
XMLElement.js
1 // Generated by CoffeeScript 1.10.0
2 (function() {
3  var XMLAttribute, XMLElement, XMLNode, isFunction, isObject, ref,
4  extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
5  hasProp = {}.hasOwnProperty;
6 
7  ref = require('./Utility'), isObject = ref.isObject, isFunction = ref.isFunction;
8 
9  XMLNode = require('./XMLNode');
10 
11  XMLAttribute = require('./XMLAttribute');
12 
13  module.exports = XMLElement = (function(superClass) {
14  extend(XMLElement, superClass);
15 
16  function XMLElement(parent, name, attributes) {
17  XMLElement.__super__.constructor.call(this, parent);
18  if (name == null) {
19  throw new Error("Missing element name");
20  }
21  this.name = this.stringify.eleName(name);
22  this.attributes = {};
23  if (attributes != null) {
24  this.attribute(attributes);
25  }
26  if (parent.isDocument) {
27  this.isRoot = true;
28  this.documentObject = parent;
29  parent.rootObject = this;
30  }
31  }
32 
33  XMLElement.prototype.clone = function() {
34  var att, attName, clonedSelf, ref1;
35  clonedSelf = Object.create(this);
36  if (clonedSelf.isRoot) {
37  clonedSelf.documentObject = null;
38  }
39  clonedSelf.attributes = {};
40  ref1 = this.attributes;
41  for (attName in ref1) {
42  if (!hasProp.call(ref1, attName)) continue;
43  att = ref1[attName];
44  clonedSelf.attributes[attName] = att.clone();
45  }
46  clonedSelf.children = [];
47  this.children.forEach(function(child) {
48  var clonedChild;
49  clonedChild = child.clone();
50  clonedChild.parent = clonedSelf;
51  return clonedSelf.children.push(clonedChild);
52  });
53  return clonedSelf;
54  };
55 
56  XMLElement.prototype.attribute = function(name, value) {
57  var attName, attValue;
58  if (name != null) {
59  name = name.valueOf();
60  }
61  if (isObject(name)) {
62  for (attName in name) {
63  if (!hasProp.call(name, attName)) continue;
64  attValue = name[attName];
65  this.attribute(attName, attValue);
66  }
67  } else {
68  if (isFunction(value)) {
69  value = value.apply();
70  }
71  if (!this.options.skipNullAttributes || (value != null)) {
72  this.attributes[name] = new XMLAttribute(this, name, value);
73  }
74  }
75  return this;
76  };
77 
78  XMLElement.prototype.removeAttribute = function(name) {
79  var attName, i, len;
80  if (name == null) {
81  throw new Error("Missing attribute name");
82  }
83  name = name.valueOf();
84  if (Array.isArray(name)) {
85  for (i = 0, len = name.length; i < len; i++) {
86  attName = name[i];
87  delete this.attributes[attName];
88  }
89  } else {
90  delete this.attributes[name];
91  }
92  return this;
93  };
94 
95  XMLElement.prototype.toString = function(options) {
96  return this.options.writer.set(options).element(this);
97  };
98 
99  XMLElement.prototype.att = function(name, value) {
100  return this.attribute(name, value);
101  };
102 
103  XMLElement.prototype.a = function(name, value) {
104  return this.attribute(name, value);
105  };
106 
107  return XMLElement;
108 
109  })(XMLNode);
110 
111 }).call(this);