Annotation of 2001/DOM-Test-Suite/ecmascript/DOMTestCase.js, revision 1.26
1.1 dom-ts-4 1: /*
1.22 dom-ts-4 2: Copyright (c) 2001-2003 World Wide Web Consortium,
1.1 dom-ts-4 3: (Massachusetts Institute of Technology, Institut National de
4: Recherche en Informatique et en Automatique, Keio University). All
5: Rights Reserved. This program is distributed under the W3C's Software
6: Intellectual Property License. This program is distributed in the
7: hope that it will be useful, but WITHOUT ANY WARRANTY; without even
8: the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9: PURPOSE.
10: See W3C License http://www.w3.org/Consortium/Legal/ for more details.
11: */
1.3 dom-ts-4 12: function assertSize(descr, expected, actual) {
13: var actualSize;
14: actualSize = actual.length;
15: assertEquals(descr, expected, actualSize);
16: }
1.15 dom-ts-4 17:
1.9 dom-ts-4 18:
1.13 dom-ts-4 19: function assertEqualsCollection(descr, expected, actual) {
1.3 dom-ts-4 20: //
21: // if they aren't the same size, they aren't equal
1.17 dom-ts-4 22: assertEquals(descr, expected.length, actual.length);
1.3 dom-ts-4 23: //
24: // if there length is the same, then every entry in the expected list
25: // must appear once and only once in the actual list
26: var expectedLen = expected.length;
27: var expectedValue;
28: var actualLen = actual.length;
29: var i;
30: var j;
31: var matches;
32: for(i = 0; i < expectedLen; i++) {
33: matches = 0;
34: expectedValue = expected[i];
35: for(j = 0; j < actualLen; j++) {
36: if(expectedValue == actual[j]) {
37: matches++;
38: }
39: }
40: if(matches == 0) {
1.17 dom-ts-4 41: assert(descr + ": No match found for " + expectedValue,false);
1.3 dom-ts-4 42: }
43: if(matches > 1) {
1.17 dom-ts-4 44: assert(descr + ": Multiple matches found for " + expectedValue, false);
1.3 dom-ts-4 45: }
46: }
47: }
48:
49:
1.13 dom-ts-4 50: function assertEqualsList(descr, expected, actual) {
1.3 dom-ts-4 51: //
52: // if they aren't the same size, they aren't equal
1.17 dom-ts-4 53: assertEquals(descr, expected.length, actual.length);
1.3 dom-ts-4 54: //
55: var actualLen = actual.length;
56: var i;
57: for(i = 0; i < actualLen; i++) {
58: if(expected[i] != actual[i]) {
1.17 dom-ts-4 59: assertEquals(descr, expected[i], actual[i]);
1.3 dom-ts-4 60: }
61: }
62: }
63:
64: function assertInstanceOf(descr, type, obj) {
65: if(type == "Attr") {
1.17 dom-ts-4 66: assertEquals(descr,2,obj.nodeType);
1.3 dom-ts-4 67: var specd = obj.specified;
68: }
69: }
70:
71: function assertSame(descr, expected, actual) {
72: if(expected != actual) {
1.17 dom-ts-4 73: assertEquals(descr, expected.nodeType, actual.nodeType);
74: assertEquals(descr, expected.nodeValue, actual.nodeValue);
1.3 dom-ts-4 75: }
76: }
77:
1.16 dom-ts-4 78: function assertURIEquals(assertID, scheme, path, host, file, name, query, fragment, isAbsolute, actual) {
1.7 dom-ts-4 79: //
80: // URI must be non-null
1.17 dom-ts-4 81: assertNotNull(assertID, actual);
1.7 dom-ts-4 82:
83: var uri = actual;
84:
85: var lastPound = actual.lastIndexOf("#");
86: var actualFragment = "";
87: if(lastPound != -1) {
88: //
89: // substring before pound
90: //
91: uri = actual.substring(0,lastPound);
92: actualFragment = actual.substring(lastPound+1);
93: }
1.17 dom-ts-4 94: if(fragment != null) assertEquals(assertID,fragment, actualFragment);
1.7 dom-ts-4 95:
96: var lastQuestion = uri.lastIndexOf("?");
97: var actualQuery = "";
98: if(lastQuestion != -1) {
99: //
100: // substring before pound
101: //
102: uri = actual.substring(0,lastQuestion);
103: actualQuery = actual.substring(lastQuestion+1);
104: }
1.17 dom-ts-4 105: if(query != null) assertEquals(assertID, query, actualQuery);
1.7 dom-ts-4 106:
107: var firstColon = uri.indexOf(":");
108: var firstSlash = uri.indexOf("/");
109: var actualPath = uri;
110: var actualScheme = "";
111: if(firstColon != -1 && firstColon < firstSlash) {
112: actualScheme = uri.substring(0,firstColon);
113: actualPath = uri.substring(firstColon + 1);
114: }
115:
116: if(scheme != null) {
1.17 dom-ts-4 117: assertEquals(assertID, scheme, actualScheme);
1.7 dom-ts-4 118: }
119:
120: if(path != null) {
1.17 dom-ts-4 121: assertEquals(assertID, path, actualPath);
1.7 dom-ts-4 122: }
123:
124: if(host != null) {
125: var actualHost = "";
1.16 dom-ts-4 126: if(actualPath.substring(0,2) == "//") {
1.8 dom-ts-4 127: var termSlash = actualPath.substring(2).indexOf("/") + 2;
1.7 dom-ts-4 128: actualHost = actualPath.substring(0,termSlash);
129: }
1.17 dom-ts-4 130: assertEquals(assertID, host, actualHost);
1.7 dom-ts-4 131: }
132:
1.16 dom-ts-4 133: if(file != null || name != null) {
1.7 dom-ts-4 134: var actualFile = actualPath;
135: var finalSlash = actualPath.lastIndexOf("/");
136: if(finalSlash != -1) {
137: actualFile = actualPath.substring(finalSlash+1);
138: }
1.16 dom-ts-4 139: if (file != null) {
1.17 dom-ts-4 140: assertEquals(assertID, file, actualFile);
1.16 dom-ts-4 141: }
142: if (name != null) {
143: var actualName = actualFile;
144: var finalDot = actualFile.lastIndexOf(".");
145: if (finalDot != -1) {
146: actualName = actualName.substring(0, finalDot);
147: }
1.17 dom-ts-4 148: assertEquals(assertID, name, actualName);
1.16 dom-ts-4 149: }
1.7 dom-ts-4 150: }
151:
152: if(isAbsolute != null) {
1.17 dom-ts-4 153: assertEquals(assertID, isAbsolute, actualPath.substring(0,1) == "/");
1.13 dom-ts-4 154: }
155: }
156:
1.25 dom-ts-4 157: function toUpperCaseArray(expected) {
1.17 dom-ts-4 158: var upperCased = new Array(expected.length);
159: for(var i = 0; i < expected.length; i++) {
160: if (expected[i].substring(0,1) != "#") {
161: upperCased[i] = expected[i].toUpperCase();
1.15 dom-ts-4 162: } else {
1.17 dom-ts-4 163: upperCased[i] = expected[i];
1.12 dom-ts-4 164: }
1.15 dom-ts-4 165: }
1.17 dom-ts-4 166: return upperCased;
167: }
1.12 dom-ts-4 168:
1.18 dom-ts-4 169: function getSuffix(contentType) {
170: switch(contentType) {
171: case "text/html":
172: return ".html";
173:
174: case "text/xml":
175: return ".xml";
176:
177: case "application/xhtml+xml":
178: return ".xhtml";
179:
180: case "image/svg+xml":
181: return ".svg";
182:
183: case "text/mathml":
184: return ".mml";
185: }
186: return ".html";
187: }
188:
1.17 dom-ts-4 189: function IFrameBuilder() {
1.18 dom-ts-4 190: this.contentType = "text/html";
1.26 ! dom-ts-4 191: this.supportedContentTypes = [ "text/html",
! 192: "text/xml",
! 193: "image/svg+xml",
! 194: "application/xhtml+xml",
! 195: "text/mathml" ];
1.18 dom-ts-4 196:
197: this.supportsAsyncChange = false;
1.26 ! dom-ts-4 198: this.async = true;
1.18 dom-ts-4 199: this.fixedAttributeNames = [
200: "validating", "expandEntityReferences", "coalescing",
201: "signed", "hasNullString", "ignoringElementContentWhitespace", "namespaceAware" ];
202:
203: this.fixedAttributeValues = [false, true, false, true, true , false, false ];
204: this.configurableAttributeNames = [ ];
205: this.configurableAttributeValues = [ ];
1.19 dom-ts-4 206: this.exception = null;
1.17 dom-ts-4 207: }
1.12 dom-ts-4 208:
1.18 dom-ts-4 209: IFrameBuilder.prototype.hasFeature = function(feature, version) {
210: return document.implementation.hasFeature(feature, version);
211: }
212:
1.23 dom-ts-4 213: IFrameBuilder.prototype.getImplementation = function() {
214: return document.implementation;
215: }
216:
1.18 dom-ts-4 217:
1.17 dom-ts-4 218: IFrameBuilder.prototype.preload = function(frame, varname, url) {
1.26 ! dom-ts-4 219: if (this.contentType == "text/html") {
! 220: if (url == "staff" || url == "nodtdstaff") {
! 221: throw "Tests using staff or nodtdstaff are not supported by HTML processors";
! 222: }
! 223: return 1;
1.18 dom-ts-4 224: }
1.26 ! dom-ts-4 225: var iframe = document.createElement("iframe");
! 226: var srcname = url + getSuffix(this.contentType);
! 227: iframe.setAttribute("name", srcname);
! 228: iframe.setAttribute("src", fileBase + srcname);
! 229: iframe.addEventListener("load", loadComplete, false);
! 230: document.getElementsByTagName("body").item(0).appendChild(iframe);
! 231: return 0;
1.17 dom-ts-4 232: }
1.9 dom-ts-4 233:
1.17 dom-ts-4 234: IFrameBuilder.prototype.load = function(frame, varname, url) {
1.26 ! dom-ts-4 235: if (this.contentType == "text/html") {
! 236: return frame.document;
! 237: }
! 238: var name = url + getSuffix(this.contentType);
! 239: var iframes = document.getElementsByTagName("iframe");
! 240: for(var i = 0; i < iframes.length; i++) {
! 241: if (iframes.item(i).getAttribute("name") == name) {
! 242: return iframes.item(i).contentDocument;
! 243: }
! 244: }
! 245: return null;
1.17 dom-ts-4 246: }
1.9 dom-ts-4 247:
1.17 dom-ts-4 248: IFrameBuilder.prototype.getImplementationAttribute = function(attr) {
1.18 dom-ts-4 249: for (var i = 0; i < this.fixedAttributeNames.length; i++) {
250: if (this.fixedAttributeNames[i] == attr) {
251: return this.fixedAttributeValues[i];
1.15 dom-ts-4 252: }
1.9 dom-ts-4 253: }
1.18 dom-ts-4 254: throw "Unrecognized implementation attribute: " + attr;
1.17 dom-ts-4 255: }
1.9 dom-ts-4 256:
1.5 dom-ts-4 257:
1.17 dom-ts-4 258: IFrameBuilder.prototype.toAutoCase = function(s) {
1.20 dom-ts-4 259: if (this.contentType == "text/html") {
260: return s.toUpperCase();
261: }
262: return s;
1.17 dom-ts-4 263: }
1.5 dom-ts-4 264:
1.17 dom-ts-4 265: IFrameBuilder.prototype.toAutoCaseArray = function(s) {
1.20 dom-ts-4 266: if (this.contentType == "text/html") {
267: return toUpperCaseArray(s);
268: }
269: return s;
1.17 dom-ts-4 270: }
1.1 dom-ts-4 271:
1.18 dom-ts-4 272: IFrameBuilder.prototype.setImplementationAttribute = function(attribute, value) {
273: var supported = this.getImplementationAttribute(attribute);
274: if (supported != value) {
275: throw "IFrame loader does not support " + attribute + "=" + value;
276: }
277: }
278:
279:
1.22 dom-ts-4 280:
281:
1.20 dom-ts-4 282: function SVGPluginBuilder() {
283: this.contentType = "image/svg+xml";
284: this.supportedContentTypes = [ "image/svg+xml" ];
285:
286: this.supportsAsyncChange = false;
287: this.async = true;
288: this.fixedAttributeNames = [
289: "validating", "expandEntityReferences", "coalescing",
290: "signed", "hasNullString", "ignoringElementContentWhitespace", "namespaceAware" ];
291:
292: this.fixedAttributeValues = [false, true, false, true, true , false, false ];
293: this.configurableAttributeNames = [ ];
294: this.configurableAttributeValues = [ ];
295: this.exception = null;
296: }
297:
298: SVGPluginBuilder.prototype.hasFeature = function(feature, version) {
299: if (feature == "XML") {
300: if (version == null || version == "1.0" || version == "2.0") {
301: return true;
302: }
303: }
304: }
305:
1.23 dom-ts-4 306: SVGPluginBuilder.prototype.getImplementation = function() {
307: var embed = document.createElement("embed");
308: embed.src = fileBase + url + getSuffix(this.contentType);
309: embed.height = 100;
310: embed.width = 100;
311: embed.type = "image/svg+xml";
312: embed.id = varname;
313: var child = document.documentElement.firstChild;
314: while(child != null) {
315: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
316: child.appendChild(embed);
317: return child.getSVGDocument.implementation;
318: }
319: child = child.nextSibling;
320: }
321: return null;
322: }
323:
1.20 dom-ts-4 324: var svgloadcount = 0;
325: function SVGPluginBuilder_pollreadystate() {
326: var newCount = 0;
327: var child = document.documentElement.firstChild;
328: while(child != null) {
329: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
330: var grand = child.firstChild;
331: while (grand != null) {
332: if (grand.nodeName.toUpperCase() == 'EMBED' && grand.readystate == 4) {
333: newCount++;
334: }
335: grand = grand.nextSibling;
336: }
337: break;
338: }
339: child = child.nextSibling;
340: }
341: if (newCount > svgloadcount) {
342: svgloadcount++;
343: loadComplete();
344: if (setUpPageStatus == 'complete') {
345: return;
346: }
347: }
348: setTimeout(SVGPluginBuilder_pollreadystate, 100);
349: }
350:
351: SVGPluginBuilder.prototype.preload = function(frame, varname, url) {
352: var embed = document.createElement("embed");
353: embed.src = fileBase + url + getSuffix(this.contentType);
354: embed.height = 100;
355: embed.width = 100;
356: embed.type = "image/svg+xml";
357: embed.id = varname;
358: var child = document.documentElement.firstChild;
359: while(child != null) {
360: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
361: child.appendChild(embed);
362: break;
363: }
364: child = child.nextSibling;
365: }
366: //
367: // if unable to monitor ready state change then
368: // check if load is complete every in 0.1 second
369: setTimeout(SVGPluginBuilder_pollreadystate , 100);
370: return 0;
371: }
372:
373: SVGPluginBuilder.prototype.load = function(frame, varname, url) {
374: var child = document.documentElement.firstChild;
375: while(child != null) {
376: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
377: var grand = child.firstChild;
378: while (grand != null) {
379: if (grand.id == varname) {
380: return grand.getSVGDocument();
381: }
382: grand = grand.nextSibling;
383: }
384: }
385: child = child.nextSibling;
386: }
387: return null;
388: }
389:
390: SVGPluginBuilder.prototype.getImplementationAttribute = function(attr) {
391: for (var i = 0; i < this.fixedAttributeNames.length; i++) {
392: if (this.fixedAttributeNames[i] == attr) {
393: return this.fixedAttributeValues[i];
394: }
395: }
396: throw "Unrecognized implementation attribute: " + attr;
397: }
398:
399:
400: SVGPluginBuilder.prototype.toAutoCase = function(s) {
401: return s;
402: }
403:
404: SVGPluginBuilder.prototype.toAutoCaseArray = function(s) {
405: return s;
406: }
407:
408: SVGPluginBuilder.prototype.setImplementationAttribute = function(attribute, value) {
409: var supported = this.getImplementationAttribute(attribute);
410: if (supported != value) {
411: throw "SVG Plugin loader does not support " + attribute + "=" + value;
412: }
413: }
414:
415:
416:
1.22 dom-ts-4 417:
418:
1.18 dom-ts-4 419: function MSXMLBuilder(progID) {
420: this.progID = progID;
421: this.configurableAttributeNames = [
422: "validating", "ignoringElementContentWhitespace"];
423: this.configurableAttributeValues = [ false, false ];
424: this.fixedAttributeNames = [ "signed", "hasNullString",
425: "expandEntityReferences", "coalescing", "namespaceAware" ];
426: this.fixedAttributeValues = [ true, true, false, false, false ];
427:
428: this.contentType = "text/xml";
429: this.supportedContentTypes = [
430: "text/xml",
431: "image/svg+xml",
432: "application/xhtml+xml",
433: "text/mathml" ];
434:
435: this.async = false;
436: this.supportsAsyncChange = true;
437: this.parser = null;
1.19 dom-ts-4 438: this.exception = null;
1.18 dom-ts-4 439: }
440:
441: MSXMLBuilder.prototype.createMSXML = function() {
1.19 dom-ts-4 442: var parser = new ActiveXObject(this.progID);
1.18 dom-ts-4 443: parser.async = this.async;
444: parser.preserveWhiteSpace = !this.configurableAttributeValues[1];
445: parser.validateOnParse = this.configurableAttributeValues[0];
446: return parser;
447: }
448:
449: MSXMLBuilder.prototype.preload = function(frame, varname, url) {
450: if (this.async) {
451: this.parser = this.createMSXML();
452: parser.async = true;
453: parser.onreadystatechange = MSXMLBuilder_onreadystatechange;
454: parser.load(fileBase + url + getSuffix(this.contentType));
455: if (parser.readystate != 4) {
456: return 0;
457: }
458: }
459: return 1;
460: }
461:
462: MSXMLBuilder.prototype.load = function(frame, varname, url) {
1.19 dom-ts-4 463: var parser = this.createMSXML();
1.18 dom-ts-4 464: if(!parser.load(fileBase + url + getSuffix(this.contentType))) {
465: throw parser.parseError.reason;
466: }
467: //
468: // if the first child of the document is a PI representing
469: // the XML Declaration, remove it from the tree.
470: //
471: // According to the DOM FAQ, this behavior is not wrong,
472: // but the tests are written assuming that it is not there.
473: //
474: var xmlDecl = parser.firstChild;
475: if(xmlDecl != null && xmlDecl.nodeType == 7 && xmlDecl.target.toLowerCase() == "xml") {
476: parser.removeChild(xmlDecl);
477: }
478: return parser;
479: }
480:
481: MSXMLBuilder.prototype.getImplementationAttribute = function(attr) {
482: var i;
483: for (i = 0; i < this.fixedAttributeNames.length; i++) {
484: if (this.fixedAttributeNames[i] == attr) {
485: return this.fixedAttributeValues[i];
486: }
487: }
488:
489: for (i = 0; i < this.configurableAttributeNames.length; i++) {
490: if (this.configurableAttributeNames[i] == attr) {
491: return this.configurableAttributeValues[i];
492: }
493: }
494:
495: throw "Unrecognized implementation attribute: " + attr;
496: }
497:
498:
499: MSXMLBuilder.prototype.toAutoCase = function(s) {
500: return s;
501: }
502:
503: MSXMLBuilder.prototype.toAutoCaseArray = function(s) {
504: return s;
505: }
506:
507: MSXMLBuilder.prototype.setImplementationAttribute = function(attribute, value) {
508: var i;
509: for (i = 0; i < this.fixedAttributeNames.length; i++) {
1.19 dom-ts-4 510: if (this.fixedAttributeNames[i] == attribute) {
1.18 dom-ts-4 511: if (this.fixedAttributeValues[i] != value) {
512: throw "MSXML does not support " + attribute + "=" + value;
513: }
514: return;
515: }
516: }
517: for (i = 0; i < this.configurableAttributeNames.length; i++) {
518: if (this.configurableAttributeNames[i] == attribute) {
519: this.configurableAttributeValues[i] = value;
520: return;
521: }
522: }
523: throw "Unrecognized implementation attribute: " + attr;
524: }
525:
526:
1.23 dom-ts-4 527: MSXMLBuilder.prototype.getImplementation = function() {
528: var doc = this.CreateMSXML();
529: return doc.implementation;
530: }
1.18 dom-ts-4 531:
532: //
533: // Only used to select tests compatible with implementation
534: // not used on tests that actually test hasFeature()
535: //
536: MSXMLBuilder.prototype.hasFeature = function(feature, version) {
537: //
538: // MSXML will take null, unfortunately
539: // there is no way to get it to there from script
540: // without a type mismatch error
541: if(version == null) {
542: switch(feature.toUpperCase()) {
543: case "XML":
544: case "CORE":
545: return true;
546:
547: case "HTML":
548: case "ORG.W3C.DOM":
549: return false;
550: }
551: if(this.getDOMImplementation().hasFeature(feature,"1.0")) {
552: return true;
553: }
554: if(this.getDOMImplementation().hasFeature(feature,"2.0")) {
555: return true;
556: }
557: if(this.getDOMImplementation().hasFeature(feature,"3.0")) {
558: return true;
559: }
560: }
561: return this.getDOMImplementation().hasFeature(feature,version);
562: }
563:
564:
1.9 dom-ts-4 565:
1.17 dom-ts-4 566: function MozillaXMLBuilder() {
1.18 dom-ts-4 567: this.contentType = "text/xml";
568:
569: this.configurableAttributeNames = [ ];
570: this.configurableAttributeValues = [ ];
571: this.fixedAttributeNames = [ "validating", "ignoringElementContentWhitespace", "signed",
572: "hasNullString", "expandEntityReferences", "coalescing", "namespaceAware" ];
573: this.fixedAttributeValues = [ false, false, true, true, false, false, false ];
574:
575: this.contentType = "text/xml";
576: this.supportedContentTypes = [
577: "text/xml",
578: "image/svg+xml",
579: "application/xhtml+xml",
580: "text/mathml" ];
581:
582: this.async = true;
583: this.supportsAsyncChange = false;
584:
1.17 dom-ts-4 585: this.docs = new Array();
586: this.docnames = new Array();
1.19 dom-ts-4 587: this.exception = null;
1.17 dom-ts-4 588: }
1.1 dom-ts-4 589:
1.23 dom-ts-4 590: MozillaXMLBuilder.prototype.getImplementation = function() {
591: return document.implementation;
592: }
593:
594:
1.17 dom-ts-4 595: MozillaXMLBuilder.prototype.preload = function(frame, varname, url) {
596: var domimpl = document.implementation;
597: var doc = domimpl.createDocument("", "temp", null);
598: doc.addEventListener("load", loadComplete, false);
1.18 dom-ts-4 599: doc.load(fileBase + url + getSuffix(this.contentType));
1.17 dom-ts-4 600: this.docs[this.docs.length] = doc;
601: this.docnames[this.docnames.length] = varname;
602: return 0;
603: }
1.1 dom-ts-4 604:
1.17 dom-ts-4 605: MozillaXMLBuilder.prototype.load = function(frame, varname, url) {
606: for(i = 0; i < this.docnames.length; i++) {
607: if (this.docnames[i] == varname) {
608: return this.docs[i];
1.9 dom-ts-4 609: }
610: }
1.17 dom-ts-4 611: return null;
612: }
1.1 dom-ts-4 613:
1.9 dom-ts-4 614:
1.17 dom-ts-4 615: MozillaXMLBuilder.prototype.getImplementationAttribute = function(attr) {
1.22 dom-ts-4 616: for (var i = 0; i < this.fixedAttributeNames.length; i++) {
617: if (this.fixedAttributeNames[i] == attr) {
618: return this.fixedAttributeValues[i];
619: }
620: }
1.17 dom-ts-4 621: return false;
622: }
1.1 dom-ts-4 623:
624:
1.17 dom-ts-4 625: MozillaXMLBuilder.prototype.toAutoCase = function(s) {
626: return s;
627: }
1.15 dom-ts-4 628:
1.17 dom-ts-4 629: MozillaXMLBuilder.prototype.toAutoCaseArray = function(s) {
630: return s;
1.16 dom-ts-4 631: }
632:
1.22 dom-ts-4 633:
634: function DOM3LSBuilder() {
635: this.contentType = "text/xml";
636:
637: this.configurableAttributeNames = [ ];
638: this.configurableAttributeValues = [ ];
639: this.fixedAttributeNames = [ "validating", "ignoringElementContentWhitespace", "signed",
640: "hasNullString", "expandEntityReferences", "coalescing", "namespaceAware" ];
641: this.fixedAttributeValues = [ false, false, true, true, false, false, true ];
642:
643: this.contentType = "text/xml";
644: this.supportedContentTypes = [
645: "text/xml",
646: "image/svg+xml",
647: "application/xhtml+xml",
648: "text/mathml" ];
649:
650: this.async = true;
651: this.supportsAsyncChange = true;
652:
653: this.docs = new Array();
654: this.docnames = new Array();
655: this.exception = null;
656: }
657:
1.23 dom-ts-4 658: DOM3LSBuilder.prototype.getImplementation = function() {
659: return document.implementation;
660: }
661:
662:
1.22 dom-ts-4 663: DOM3LSBuilder.prototype.preload = function(frame, varname, url) {
664: if (this.async) {
665: var domimpl = document.implementation;
666: var dombuilder = domimpl.createDOMBuilder(2, null);
667: dombuilder.addEventListener("load", loadComplete, false);
668: var uri = fileBase + url + getSuffix(this.contentType);
669: var doc = dombuilder.parseURI(uri);
670: this.docs[this.docs.length] = doc;
671: this.docnames[this.docnames.length] = varname;
672: return 0;
673: }
674: return 1;
675: }
676:
677: DOM3LSBuilder.prototype.load = function(frame, varname, url) {
678: if (this.async) {
679: for(i = 0; i < this.docnames.length; i++) {
680: if (this.docnames[i] == varname) {
681: return this.docs[i];
682: }
683: }
684: return null;
685: }
686: var dombuilder = document.implementation.createDOMBuilder(1, null);
687: var uri = fileBase + url + getSuffix(this.contentType);
688: return dombuilder.parseURI(uri);
689: }
690:
691:
692: DOM3LSBuilder.prototype.getImplementationAttribute = function(attr) {
693: for (var i = 0; i < this.fixedAttributeNames.length; i++) {
694: if (this.fixedAttributeNames[i] == attr) {
695: return this.fixedAttributeValues[i];
696: }
697: }
698: }
699:
700:
701: DOM3LSBuilder.prototype.toAutoCase = function(s) {
702: return s;
703: }
704:
705: DOM3LSBuilder.prototype.toAutoCaseArray = function(s) {
706: return s;
707: }
708:
1.18 dom-ts-4 709: function createBuilder(implementation) {
710: switch(implementation) {
711: case "msxml3":
712: return new MSXMLBuilder("Msxml.DOMDocument.3.0");
713:
714: case "msxml4":
715: return new MSXMLBuilder("Msxml2.DOMDocument.4.0");
716:
717: case "mozilla":
718: return new MozillaXMLBuilder();
719:
1.20 dom-ts-4 720: case "svgplugin":
721: return new SVGPluginBuilder();
1.18 dom-ts-4 722:
723: case "dom3ls":
1.22 dom-ts-4 724: return new DOM3LSBuilder();
1.18 dom-ts-4 725: }
726: return new IFrameBuilder();
727: }
728:
729: var builder = null;
730:
731: if (top && top.jsUnitParmHash)
732: {
733: builder = createBuilder(top.jsUnitParmHash.implementation);
1.19 dom-ts-4 734: try {
735: if (top.jsUnitParmHash.asynchronous == 'true' && builder.supportAsync) {
736: builder.async = true;
737: }
738: if (top.jsUnitParmHash.expandentityreferences) {
739: if (top.jsUnitParmHash.expandEntityReferences == 'true') {
740: builder.setImplementationAttribute('expandEntityReferences', true);
741: } else {
742: builder.setImplementationAttribute('expandEntityReferences', false);
743: }
744: }
745: if (top.jsUnitParmHash.ignoringelementcontentwhitespace) {
746: if (top.jsUnitParmHash.ignoringElementContentWhitespace == 'true') {
747: builder.setImplementationAttribute('ignoringElementContentWhitespace', true);
748: } else {
749: builder.setImplementationAttribute('ignoringElementContentWhitespace', false);
750: }
751: }
752: if (top.jsUnitParmHash.validating) {
753: if (top.jsUnitParmHash.validating == 'true') {
754: builder.setImplementationAttribute('validating', true);
755: } else {
756: builder.setImplementationAttribute('validating', false);
757: }
758: }
759: if (top.jsUnitParmHash.coalescing) {
760: if (top.jsUnitParmHash.coalescing == 'true') {
761: builder.setImplementationAttribute('coalescing', true);
762: } else {
763: builder.setImplementationAttribute('coalescing', false);
764: }
765: }
766: if (top.jsUnitParmHash.namespaceaware) {
767: if (top.jsUnitParmHash.namespaceaware == 'true') {
768: builder.setImplementationAttribute('namespaceAware', true);
769: } else {
770: builder.setImplementationAttribute('namespaceAware', false);
771: }
772: }
773: var contentType = top.jsUnitParmHash.contenttype;
774: if (contentType != null) {
775: var contentTypeSet = false;
776: for (var i = 0; i < builder.supportedContentTypes.length; i++) {
777: if (builder.supportedContentTypes[i] == contentType) {
778: builder.contentType = contentType;
779: contentTypeSet = true;
780: break;
781: }
782: }
783: if (!contentTypeSet) {
784: builder.exception = "Builder does not support content type " + contentType;
785: }
786: }
787: }
788: catch(ex) {
789: builder.exception = ex;
790: }
1.18 dom-ts-4 791: } else {
792: builder = new IFrameBuilder();
793: }
1.16 dom-ts-4 794:
795:
1.17 dom-ts-4 796: function preload(frame, varname, url) {
797: return builder.preload(frame, varname, url);
1.15 dom-ts-4 798: }
799:
1.17 dom-ts-4 800: function load(frame, varname, url) {
801: return builder.load(frame, varname, url);
1.16 dom-ts-4 802: }
1.15 dom-ts-4 803:
1.17 dom-ts-4 804: function getImplementationAttribute(attr) {
805: return builder.getImplementationAttribute(attr);
1.15 dom-ts-4 806: }
1.16 dom-ts-4 807:
1.9 dom-ts-4 808:
1.17 dom-ts-4 809: function toAutoCase(s) {
810: return builder.toAutoCase(s);
811: }
1.1 dom-ts-4 812:
1.17 dom-ts-4 813: function toAutoCaseArray(s) {
814: return builder.toAutoCaseArray(s);
815: }
1.10 dom-ts-4 816:
1.18 dom-ts-4 817: function setImplementationAttribute(attribute, value) {
818: builder.setImplementationAttribute(attribute, value);
819: }
820:
1.21 dom-ts-4 821: function createXPathEvaluator(doc) {
822: try {
823: return doc.getFeature("XPath", null);
824: }
825: catch(ex) {
826: }
827: return doc;
828: }
829:
1.10 dom-ts-4 830:
1.18 dom-ts-4 831: function MSXMLBuilder_onreadystatechange() {
832: if (builder.parser.readyState == 4) {
833: loadComplete();
834: }
1.19 dom-ts-4 835: }
836:
837:
838: var fileBase = location.href;
839: if (fileBase.indexOf('?') != -1) {
840: fileBase = fileBase.substring(0, fileBase.indexOf('?'));
841: }
1.20 dom-ts-4 842: fileBase = fileBase.substring(0, fileBase.lastIndexOf('/') + 1) + "files/";
843:
1.23 dom-ts-4 844: function getImplementation() {
845: return builder.getImplementation();
846: }
1.19 dom-ts-4 847:
Webmaster