6 function DOMException (c) { this.code = c }
7 DOMException.INDEX_SIZE_ERR = 1;
8 DOMException.DOMSTRING_SIZE_ERR = 2;
9 DOMException.HIERARCHY_REQUEST_ERR = 3;
10 DOMException.WRONG_DOCUMENT_ERR = 4;
11 DOMException.INVALID_CHARACTER_ERR = 5;
12 DOMException.NO_DATA_ALLOWED_ERR = 6;
13 DOMException.NO_MODIFICATION_ALLOWED_ERR = 7;
14 DOMException.NOT_FOUND_ERR = 8;
15 DOMException.NOT_SUPPORTED_ERR = 9;
16 DOMException.INUSE_ATTRIBUTE_ERR = 10;
17 DOMException.INVALID_STATE_ERR = 11;
18 DOMException.SYNTAX_ERR = 12;
19 DOMException.INVALID_MODIFICATION_ERR = 13;
20 DOMException.NAMESPACE_ERR = 14;
21 DOMException.INVALID_ACCESS_ERR = 15;
23 function DOMImplementation () {
25 this._features['CORE'] = {};
26 this._features['CORE']['any'] = true;
27 this._features['CORE']['1.0'] = true;
28 this._features['CORE']['2.0'] = true;
29 this._features['XML'] = {};
30 this._features['XML']['any'] = true;
31 this._features['XML']['1.0'] = true;
32 this._features['XML']['2.0'] = true;
35 DOMImplementation.method('hasFeature', function (f, v) {
37 if (this._features[f] && this._features[f][v])
38 return this._features[f][v];
41 DOMImplementation.method('createDocumentType', function (n, p, s) {
44 DOMImplementation.method('createDocument', function (ns,qn,dt) {
45 var d = new Document(dt);
46 d.documentElement = d.createElement(qn);
47 d.appendChild(d.documentElement);
49 d.documentElement.namespaceURI = ns;
51 installDOM3XPathSupport(d,new XPathParser());
57 DOMImplementation.parseString = function (xml) {
58 __XMLDOC['id' + __XMLDOCid] = {};
60 _OILS_FUNC_xml_parse_string(xml, '__XMLDOC.id' + __XMLDOCid);
62 alert("Sorry, no string parsing support");
64 var x = __XMLDOC['id' + __XMLDOCid];
71 function NodeList () {
73 //log_stdout(' -- NodeList constructor');
76 NodeList.method('item', function (idx) {
79 NodeList.method('push', function (node) {
80 var idx = this.length;
89 // NamedNodeMap interface
90 function NamedNodeMap () {
94 //log_stdout(' -- NamedNodeMap constructor');
97 NamedNodeMap.method('item', function (idx) {
98 return this.getNamedItem(idx);
101 NamedNodeMap.method('removeNamedItemNS', function (ns, name) {
102 var x = this._ns_nodes[ns][name];
103 for (var i in this._nodes) {
104 if (this._nodes[i] === x) {
105 this._nodes[i] = null;
108 this._ns_nodes[ns][name] = null;
112 NamedNodeMap.method('removeNamedItem', function (name) {
113 var x = this._nodes[name];
114 for (var i in this._nodes) {
115 if (this._nodes[i] === x) {
116 this._nodes[i] = null;
122 NamedNodeMap.method('getNamedItem', function (name) {
123 return this._nodes[name];
126 NamedNodeMap.method('getNamedItemNS', function (ns,name) {
127 return this._ns_nodes[ns][name];
130 NamedNodeMap.method('setNamedItem', function (node) {
131 if (node.nodeName == 'length') return null;
132 this[node.nodeName] = node.value;
133 this[this.length] = node.value;
134 this._nodes[node.nodeName] = node;
135 this._nodes[this.length] = node;
139 NamedNodeMap.method('setNamedItemNS', function (node) {
140 if (node.nodeName == 'length') return null;
141 this[this.length] = node.value;
142 if (!this._ns_nodes[node.namespaceURI]) this._ns_nodes[node.namespaceURI] = {};
143 this._ns_nodes[node.namespaceURI][node.nodeName] = node;
144 this._nodes[this.length] = node;
149 function Node (name) {
150 this.nodeName = name;
151 this.nodeValue = null;
152 this.nodeType = null;
153 this.parentNode = null;
154 this.childNodes = new NodeList();
155 this.firstChild = null;
156 this.lastChild = null;
157 this.previousSibling = null;
158 this.nextSibling = null;
159 this.attributes = new NamedNodeMap();
160 this.ownerDocument = null;
161 this.namespaceURI = null;
164 var p = name.indexOf(':');
166 this.prefix = name.substring(0,p);
167 this.localName = name.substring(p + 1);
169 this.localName = name;
173 //log_stdout(' -- Node constructor');
175 Node.ELEMENT_NODE = 1;
176 Node.ATTRIBUTE_NODE = 2;
178 Node.CDATA_SECTION_NODE = 4;
179 Node.ENTITY_REFERENCE_NODE = 5;
180 Node.ENTITY_NODE = 6;
181 Node.PROCESSING_INSTRUCTION_NODE = 7;
182 Node.COMMENT_NODE = 8;
183 Node.DOCUMENT_NODE = 9;
184 Node.DOCUMENT_TYPE_NODE = 10;
185 Node.DOCUMENT_FRAGMENT_NODE = 11;
186 Node.NOTATION_NODE = 12;
187 Node.NAMESPACE_DECL = 18;
189 Node.method('_childIndex', function (node) {
190 for (var i = 0; i < this.childNodes.length; i++)
191 if (this.childNodes[i] === node) return i;
193 Node.method('insertBefore', function (node, target) {
195 if (node.nodeType == Node.DOCUMENT_FRAGMENT_NODE) {
196 for (var i = 0; i < node.childNodes.length; i++)
197 this.insertBefore(node.childNodes.item(i));
201 node.parentNode = this;
202 node.ownerDocument = this.ownerDocument;
203 var i = this._childIndex(target);
205 for (var j = this.childNodes.length; j > i; j--)
206 this.childNodes[j] = this.childNodes[j - 1];
208 this.childNodes[i] = node;
211 this.firstChild = node;
213 this.childNodes[i - 1].nextSibling = node;
214 node.previousSibling = this.childNodes[i + 1];
217 this.childNodes[i + 1].previousSibling = node;
218 node.nextSibling = this.childNodes[i + 1];
220 node._index = this.ownerDocument._nodes.length;
221 this.ownerDocument._nodes[this.ownerDocument._nodes.length] = node;
223 this.childNodes.length++;
227 Node.method('removeChild', function (node) {
228 node.parentNode = this;
229 node.ownerDocument = this.ownerDocument;
230 var i = this._childIndex(node);
232 if (node === this.firstChild) {
233 this.firstChild = node.nextSibling;
235 node.previousSibling.nextSibling = node.nextSibling;
236 for (var j = i; j < this.childNodes.length; j++)
237 this.childNodes[j - 1] = this.childNodes[j];
240 if (node === this.lastChild) {
241 this.lastChild = node.previousSibling;
243 node.nextSibling.previousSibling = node.previousSibling;
246 this.ownerDocument._nodes[node._index] = null;
248 this.childNodes.length--;
252 Node.method('appendChild', function (node) {
254 if (node.nodeType == Node.DOCUMENT_FRAGMENT_NODE) {
255 for (var i = 0; i < node.childNodes.length; i++)
256 this.appendChild(node.childNodes.item(i));
260 node.parentNode = this;
261 this.childNodes.push( node );
262 this.lastChild = node;
263 if (this.childNodes.length == 1) {
264 this.firstChild = node;
266 this.lastChild.previousSibling = this.childNodes[this.childNodes.length - 2]
267 this.lastChild.previousSibling.nextSibling = this.lastChild;
273 Node.method('hasChildNodes', function () {
274 if (this.childNodes.length) return true;
278 Node.method('hasAttributes', function () {
279 if (this.attributes.length) return true;
283 Node.method('cloneNode', function (deep) {
284 //log_stdout(this.constructor);
285 var newNode = new this.constructor( this.nodeName );
286 newNode.ownerDocument = this.ownerDocument;
287 newNode.namespaceURI = this.namespaceURI;
288 newNode.prefix = this.prefix;
291 for (var i = 0; i < this.childNodes.length; i++)
292 newNode.appendChild( this.childNodes.item(i).cloneNode(deep) );
295 for (var i = 0; i < this.attributes.length; i++)
296 newNode.attributes.setNamedItem( this.attributes.item(i) );
301 function DocumentType (n,p,s) {
302 this.uber('constructor');
303 this.constructor = DocumentType;
304 this.nodeType = Node.DOCUMENT_TYPE_NODE;
306 this.entities = new NamedNodeMap();
307 this.notations = new NamedNodeMap();
310 this.internalSubset = null;
312 DocumentType.inherits(Node);
314 function Notation (p, s) {
315 this.uber('constructor');
316 this.constructor = Notation;
317 this.nodeType = Node.NOTATION_NODE;
321 Notation.inherits(Node);
323 function ProcessingInstruction (target, data) {
324 this.uber('constructor');
325 this.constructor = ProcessingInstruction;
326 this.nodeType = Node.PROCESSING_INSTRUCTION_NODE;
327 this.target = target;
330 ProcessingInstruction.inherits(Node);
332 function Entity (p, s, n) {
333 this.uber('constructor');
334 this.constructor = Entity;
335 this.nodeType = Node.ENTITY_NODE;
338 this.notationName = n;
340 Entity.inherits(Node);
342 function EntityReference () {
343 this.uber('constructor');
344 this.constructor = EntityReference;
345 this.nodeType = Node.ENTITY_REFERENCE_NODE;
347 EntityReference.inherits(Node);
349 // Document interface
350 function Document (dt) {
351 this.uber('constructor');
352 this.constructor = Document;
353 this.nodeType = Node.DOCUMENT_NODE;
355 this.documentElement = null;
356 this.implementation = new DOMImplementation();
358 //log_stdout(' -- Document constructor');
361 Document.inherits(Node);
362 Document.method('createAttribute', function (tagName) {
363 var node = new Attr(tagName);
364 node.ownerDocument = this;
368 Document.method('createAttributeNS', function (ns,tagName) {
369 var node = this.createAttribute(tagName);
370 node.namespaceURI = ns;
374 Document.method('createElement', function (tagName) {
375 var node = new Element(tagName);
376 node.ownerDocument = this;
377 node._index = this._nodes.length;
378 this._nodes[this._nodes.length] = node;
382 Document.method('createElementNS', function (ns,tagName) {
383 var node = this.createElement(tagName);
384 node.namespaceURI = ns;
388 Document.method('importNode', function (node, deep) {
389 var tmp = node.clone(deep);
390 tmp.ownerDocument = this;
391 var newNode = tmp.cloneNode(deep);
395 Document.method('createDocumentFragment', function () {
397 x.nodeType = Node.DOCUMENT_FRAGMENT_NODE;
398 x.ownerDocument = this;
401 Document.method('createTextNode', function (content) {
402 var node = new Text(content);
403 node.ownerDocument = this;
407 Document.method('createComment', function (content) {
408 var node = new Comment(content);
409 node.ownerDocument = this;
413 Document.method('createCDATASection', function (content) {
414 var node = new CDATASection(content);
415 node.ownerDocument = this;
419 Document.method('getElementById', function (id) {
420 for (var i in this._nodes) {
421 //log_stdout(' id = ' + this._nodes[i].attributes.id);
422 if (this._nodes[i] && this._nodes[i].attributes.id == id)
423 return this._nodes[i];
428 Document.method('getElementsByTagName', function (tname) {
429 var list = new NodeList();
430 this.documentElement.getElementsByTagName(tname, list);
434 Document.method('getElementsByTagNameNS', function (ns, tname) {
435 var list = new NodeList();
436 this.documentElement.getElementsByTagNameNS(ns, tname, list);
441 function Attr ( name, value ) {
442 this.uber('constructor',name);
443 this.constructor = Attr;
444 this.nodeType = Node.ATTRIBUTE_NODE;
446 this.value = this.nodeValue = value;
447 this.specified = (this.value ? true : false);
448 this.ownerElement = null;
449 //log_stdout(' -- Attr constructor');
455 function Element ( name ) {
456 this.uber('constructor',name);
457 this.constructor = Element;
458 this.nodeType = Node.ELEMENT_NODE;
460 //log_stdout(' -- Element constructor')
462 Element.inherits(Node);
464 Element.method('getAttribute', function (aname) {
465 var x = this.attributes.getNamedItem(aname);
466 if (x) return x.value;
470 Element.method('setAttribute', function (aname,aval) {
471 var attr = new Attr(aname, aval);
472 attr.ownerElement = this;
473 return this.attributes.setNamedItem(attr);
476 Element.method('removeAttribute', function (aname) {
477 this.attributes.removeNamedItem(aname);
481 Element.method('getAttributeNode', function (aname) {
482 return this.attributes.getNamedItem(aname);
485 Element.method('setAttributeNode', function (attr) {
486 attr.ownerElement = this;
487 attr.namespaceURI = (attr.namespaceURI ? attr.namespaceURI : this.namespaceURI);
488 return this.attributes.setNamedItem(attr);
491 Element.method('removeAttributeNode', function (attr) {
492 if (attr.namespaceURI) {
493 return this.attributes.removeNamedItemNS(attr.namespaceURI, attr.name);
495 return this.attributes.removeNamedItem(attr.name);
499 Element.method('getAttributeNS', function (ns,aname) {
500 var x = this.attributes.getNamedItemNS(ns,aname);
501 if (x) return x.value;
505 Element.method('setAttributeNS', function (ns,aname,aval) {
506 var attr = new Attr(aname, aval);
507 attr.ownerElement = this;
508 attr.namespaceURI = ns;
509 return this.attributes.setNamedItem(ns,attr);
512 Element.method('removeAttributeNS', function (ns,aname) {
513 this.attributes.removeNamedItemNS(ns,aname);
517 Element.method('getAttributeNodeNS', function (ns, aname) {
518 return this.attributes.getNamedItemNS(ns,aname);
521 Element.method('setAttributeNodeNS', function (attr) {
522 attr.ownerElement = this;
523 attr.namespaceURI = (attr.namespaceURI ? attr.namespaceURI : this.namespaceURI);
524 return this.attributes.setNamedItemNS(attr);
527 Element.method('hasAttribute', function (name) {
528 return ( this.getAttribute(name) ? true : false );
531 Element.method('hasAttributeNS', function (ns, name) {
532 return ( this.getAttributeNS(ns, name) ? true : false );
535 Element.method('getElementsByTagName', function (tname, list) {
536 if (!list) list = new NodeList();
537 if (this.tagName == tname) list.push(this);
538 //log_stdout(' -- ' + this.tagName + ' :: ' + this.childNodes.length);
539 for (var i = 0; i < this.childNodes.length; i++) {
540 if (this.childNodes.item(i).nodeType == 1)
541 this.childNodes.item(i).getElementsByTagName(tname, list);
546 Element.method('getElementsByTagNameNS', function (ns, tname, list) {
547 if (!list) list = new NodeList();
548 if (this.localName == tname && this.namespaceURI == ns) list.push(this);
549 //log_stdout(' -- {' + this.namespaceURI + '}:' + this.localName + ' :: ' + this.childNodes.length);
550 for (var i = 0; i < this.childNodes.length; i++) {
551 if (this.childNodes.item(i).nodeType == 1)
552 this.childNodes.item(i).getElementsByTagNameNS(ns, tname, list);
558 // CharacterData interface
559 function CharacterData ( name, content ) {
560 this.uber('constructor', name);
561 this.constructor = CharacterData;
562 this.setData(content);
563 //log_stdout(' -- CharacterData constructor');
564 //log_stdout(' -- CharacterData length == ' + this.length + ' :: ' + this.data);
566 CharacterData.inherits(Node);
568 CharacterData.method('setData', function (content) {
569 this.data = this.nodeValue = content;
571 this.length = this.data.length;
573 CharacterData.method('substringData', function (offset,count) {
574 this.data.substring(offset,count);
576 CharacterData.method('appendData', function (txt) {
577 this.data = this.nodeValue = this.data + txt;
578 this.length = this.data.length;
580 CharacterData.method('insertData', function (offset,txt) {
581 var b = this.data.substring(0,offset);
582 var a = this.data.substring(offset);
583 this.data = this.nodeValue = b + txt + a;
584 this.length = this.data.length;
586 CharacterData.method('deleteData', function (offset,count) {
587 var b = this.data.substring(0,offset);
588 var a = this.data.substring(offset + count);
589 this.data = this.nodeValue = b + a;
590 this.length = this.data.length;
592 CharacterData.method('replaceData', function (offset,count,txt) {
593 var b = this.data.substring(0,offset);
594 var a = this.data.substring(offset + count);
595 this.data = this.nodeValue = b + txt + a;
596 this.length = this.data.length;
602 function Text ( content ) {
603 this.superclass.constructor.call(this, '#text', content);
604 this.constructor = Text;
605 this.nodeType = Node.TEXT_NODE;
606 //log_stdout(' -- Text constructor :: ' + this.data);
608 Text.inherits(CharacterData);
611 // CDATASection interface
612 function CDATASection ( content ) {
613 this.uber('constructor', '#cdata', content);
614 this.constructor = CDATASection;
615 this.nodeType = Node.COMMENT_NODE;
616 //log_stdout(' -- Comment constructor');
618 CDATASection.inherits(Text);
621 function Comment ( content ) {
622 this.uber('constructor', '#comment', content);
623 this.constructor = Comment;
624 this.nodeType = Node.COMMENT_NODE;
625 //log_stdout(' -- Comment constructor');
627 Comment.inherits(Text);
631 //////////////////////// XPath stuff /////////////////////////
633 function XPathNamespaceResolver (data) {
636 XPathNamespaceResolver.inherits(NamespaceResolver);
638 XPathNamespaceResolver.method('lookupNamespaceURI', function (prefix) {
639 return this.data[prefix];
641 XPathNamespaceResolver.method('setNamespaceURI', function (prefix, uri) {
642 this.data[prefix] = uri;