Annotation of 2001/DOM-Test-Suite/ecmascript/DOMTestCase.js, revision 1.22

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.17      dom-ts-4  157: function toUpperCaseArray() {
                    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";
                    191:     this.supportedContentTypes = [ "text/html", 
                    192:         "text/xml", 
                    193:         "image/svg+xml", 
                    194:         "application/xhtml+xml",
                    195:         "text/mathml" ];
                    196: 
                    197:     this.supportsAsyncChange = false;
                    198:     this.async = true;
                    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: 
                    213: 
1.17      dom-ts-4  214: IFrameBuilder.prototype.preload = function(frame, varname, url) {
1.22    ! dom-ts-4  215:   if (url == "staff" && this.contentType == "text/html") {
        !           216:     throw "Tests using staff document are not supported by HTML processors";
1.18      dom-ts-4  217:   }
                    218:   frame.document.location.href = fileBase + url + getSuffix(this.contentType);
1.17      dom-ts-4  219:   return 0;
                    220: }
1.9       dom-ts-4  221: 
1.17      dom-ts-4  222: IFrameBuilder.prototype.load = function(frame, varname, url) {
                    223:     return frame.document;
                    224: }
1.9       dom-ts-4  225: 
1.17      dom-ts-4  226: IFrameBuilder.prototype.getImplementationAttribute = function(attr) {
1.18      dom-ts-4  227:     for (var i = 0; i < this.fixedAttributeNames.length; i++) {
                    228:         if (this.fixedAttributeNames[i] == attr) {
                    229:             return this.fixedAttributeValues[i];
1.15      dom-ts-4  230:         }
1.9       dom-ts-4  231:     }
1.18      dom-ts-4  232:     throw "Unrecognized implementation attribute: " + attr;
1.17      dom-ts-4  233: }
1.9       dom-ts-4  234: 
1.5       dom-ts-4  235: 
1.17      dom-ts-4  236: IFrameBuilder.prototype.toAutoCase = function(s) {
1.20      dom-ts-4  237:     if (this.contentType == "text/html") {
                    238:         return s.toUpperCase();
                    239:     }
                    240:     return s;
1.17      dom-ts-4  241: }
1.5       dom-ts-4  242: 
1.17      dom-ts-4  243: IFrameBuilder.prototype.toAutoCaseArray = function(s) {
1.20      dom-ts-4  244:     if (this.contentType == "text/html") {
                    245:         return toUpperCaseArray(s);
                    246:     }
                    247:     return s;
1.17      dom-ts-4  248: }
1.1       dom-ts-4  249: 
1.18      dom-ts-4  250: IFrameBuilder.prototype.setImplementationAttribute = function(attribute, value) {
                    251:     var supported = this.getImplementationAttribute(attribute);
                    252:     if (supported != value) {
                    253:         throw "IFrame loader does not support " + attribute + "=" + value;
                    254:     }
                    255: }
                    256: 
                    257: 
1.22    ! dom-ts-4  258: 
        !           259: 
1.20      dom-ts-4  260: function SVGPluginBuilder() {
                    261:     this.contentType = "image/svg+xml";
                    262:     this.supportedContentTypes = [ "image/svg+xml" ];
                    263: 
                    264:     this.supportsAsyncChange = false;
                    265:     this.async = true;
                    266:     this.fixedAttributeNames = [
                    267:         "validating",  "expandEntityReferences", "coalescing", 
                    268:         "signed", "hasNullString", "ignoringElementContentWhitespace", "namespaceAware" ];
                    269: 
                    270:     this.fixedAttributeValues = [false,  true, false, true, true , false, false ];
                    271:     this.configurableAttributeNames = [ ];
                    272:     this.configurableAttributeValues = [ ];
                    273:     this.exception = null;
                    274: }
                    275: 
                    276: SVGPluginBuilder.prototype.hasFeature = function(feature, version) {
                    277:     if (feature == "XML") {
                    278:         if (version == null || version == "1.0" || version == "2.0") {
                    279:             return true;
                    280:         }
                    281:     }
                    282: }
                    283: 
                    284: var svgloadcount = 0;
                    285: function SVGPluginBuilder_pollreadystate() {
                    286:   var newCount = 0;
                    287:   var child = document.documentElement.firstChild;
                    288:   while(child != null) {
                    289:       if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
                    290:           var grand = child.firstChild;
                    291:           while (grand != null) {
                    292:              if (grand.nodeName.toUpperCase() == 'EMBED' && grand.readystate == 4) {
                    293:                 newCount++;
                    294:              }
                    295:              grand = grand.nextSibling;
                    296:           }
                    297:           break;
                    298:       }
                    299:       child = child.nextSibling;
                    300:   }
                    301:   if (newCount > svgloadcount) {
                    302:     svgloadcount++;
                    303:     loadComplete();
                    304:     if (setUpPageStatus == 'complete') {
                    305:         return;
                    306:     }
                    307:   }
                    308:   setTimeout(SVGPluginBuilder_pollreadystate, 100);
                    309: }
                    310: 
                    311: SVGPluginBuilder.prototype.preload = function(frame, varname, url) {
                    312:   var embed = document.createElement("embed");
                    313:   embed.src = fileBase + url + getSuffix(this.contentType);
                    314:   embed.height = 100;
                    315:   embed.width = 100;
                    316:   embed.type = "image/svg+xml";
                    317:   embed.id = varname;
                    318:   var child = document.documentElement.firstChild;
                    319:   while(child != null) {
                    320:       if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
                    321:           child.appendChild(embed);
                    322:           break;
                    323:       }
                    324:       child = child.nextSibling;
                    325:   }
                    326:   //
                    327:   //   if unable to monitor ready state change then
                    328:   //     check if load is complete every in 0.1 second
                    329:   setTimeout(SVGPluginBuilder_pollreadystate , 100);
                    330:   return 0;
                    331: }
                    332: 
                    333: SVGPluginBuilder.prototype.load = function(frame, varname, url) {
                    334:   var child = document.documentElement.firstChild;
                    335:   while(child != null) {
                    336:       if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
                    337:                  var grand = child.firstChild;
                    338:                  while (grand != null) {
                    339:                        if (grand.id == varname) {
                    340:                                return grand.getSVGDocument();
                    341:                        }
                    342:                        grand = grand.nextSibling;
                    343:                  }
                    344:          }
                    345:       child = child.nextSibling;
                    346:    }
                    347:    return null;
                    348: }
                    349: 
                    350: SVGPluginBuilder.prototype.getImplementationAttribute = function(attr) {
                    351:     for (var i = 0; i < this.fixedAttributeNames.length; i++) {
                    352:         if (this.fixedAttributeNames[i] == attr) {
                    353:             return this.fixedAttributeValues[i];
                    354:         }
                    355:     }
                    356:     throw "Unrecognized implementation attribute: " + attr;
                    357: }
                    358: 
                    359: 
                    360: SVGPluginBuilder.prototype.toAutoCase = function(s) {
                    361:     return s;
                    362: }
                    363: 
                    364: SVGPluginBuilder.prototype.toAutoCaseArray = function(s) {
                    365:     return s;
                    366: }
                    367: 
                    368: SVGPluginBuilder.prototype.setImplementationAttribute = function(attribute, value) {
                    369:     var supported = this.getImplementationAttribute(attribute);
                    370:     if (supported != value) {
                    371:         throw "SVG Plugin loader does not support " + attribute + "=" + value;
                    372:     }
                    373: }
                    374: 
                    375: 
                    376: 
1.22    ! dom-ts-4  377: 
        !           378: 
1.18      dom-ts-4  379: function MSXMLBuilder(progID) {
                    380:     this.progID = progID;
                    381:     this.configurableAttributeNames = [
                    382:         "validating", "ignoringElementContentWhitespace"];
                    383:     this.configurableAttributeValues = [ false, false ];
                    384:     this.fixedAttributeNames = [ "signed", "hasNullString", 
                    385:         "expandEntityReferences", "coalescing", "namespaceAware" ];
                    386:     this.fixedAttributeValues = [ true, true, false, false, false ];
                    387: 
                    388:     this.contentType = "text/xml";
                    389:     this.supportedContentTypes = [ 
                    390:         "text/xml", 
                    391:         "image/svg+xml", 
                    392:         "application/xhtml+xml",
                    393:         "text/mathml" ];
                    394: 
                    395:     this.async = false;
                    396:     this.supportsAsyncChange = true;
                    397:     this.parser = null;
1.19      dom-ts-4  398:     this.exception = null;
1.18      dom-ts-4  399: }
                    400: 
                    401: MSXMLBuilder.prototype.createMSXML = function() {
1.19      dom-ts-4  402:     var parser = new ActiveXObject(this.progID);
1.18      dom-ts-4  403:     parser.async = this.async;
                    404:     parser.preserveWhiteSpace = !this.configurableAttributeValues[1];
                    405:     parser.validateOnParse = this.configurableAttributeValues[0];
                    406:     return parser;
                    407:   }
                    408: 
                    409: MSXMLBuilder.prototype.preload = function(frame, varname, url) {
                    410:   if (this.async) {
                    411:      this.parser = this.createMSXML();
                    412:      parser.async = true;
                    413:      parser.onreadystatechange = MSXMLBuilder_onreadystatechange;
                    414:      parser.load(fileBase + url + getSuffix(this.contentType));
                    415:      if (parser.readystate != 4) {
                    416:         return 0;
                    417:      }
                    418:   }
                    419:   return 1;
                    420: }
                    421: 
                    422: MSXMLBuilder.prototype.load = function(frame, varname, url) {
1.19      dom-ts-4  423:     var parser = this.createMSXML();
1.18      dom-ts-4  424:        if(!parser.load(fileBase + url + getSuffix(this.contentType))) {
                    425:                throw parser.parseError.reason;
                    426:        }
                    427:     //
                    428:     //   if the first child of the document is a PI representing
                    429:     //      the XML Declaration, remove it from the tree.
                    430:     //
                    431:     //   According to the DOM FAQ, this behavior is not wrong,
                    432:     //      but the tests are written assuming that it is not there.
                    433:     //
                    434:     var xmlDecl = parser.firstChild;
                    435:     if(xmlDecl != null && xmlDecl.nodeType == 7 && xmlDecl.target.toLowerCase() == "xml") {
                    436:         parser.removeChild(xmlDecl);
                    437:     }
                    438:        return parser;
                    439: }
                    440: 
                    441: MSXMLBuilder.prototype.getImplementationAttribute = function(attr) {
                    442:     var i;
                    443:     for (i = 0; i < this.fixedAttributeNames.length; i++) {
                    444:         if (this.fixedAttributeNames[i] == attr) {
                    445:             return this.fixedAttributeValues[i];
                    446:         }
                    447:     }
                    448: 
                    449:     for (i = 0; i < this.configurableAttributeNames.length; i++) {
                    450:         if (this.configurableAttributeNames[i] == attr) {
                    451:             return this.configurableAttributeValues[i];
                    452:         }
                    453:     }
                    454: 
                    455:     throw "Unrecognized implementation attribute: " + attr;
                    456: }
                    457: 
                    458: 
                    459: MSXMLBuilder.prototype.toAutoCase = function(s) {
                    460:     return s;
                    461: }
                    462: 
                    463: MSXMLBuilder.prototype.toAutoCaseArray = function(s) {
                    464:     return s;
                    465: }
                    466: 
                    467: MSXMLBuilder.prototype.setImplementationAttribute = function(attribute, value) {
                    468:     var i;
                    469:     for (i = 0; i < this.fixedAttributeNames.length; i++) {
1.19      dom-ts-4  470:         if (this.fixedAttributeNames[i] == attribute) {
1.18      dom-ts-4  471:             if (this.fixedAttributeValues[i] != value) {
                    472:                 throw "MSXML does not support " + attribute + "=" + value;
                    473:             }
                    474:             return;
                    475:         }
                    476:     }
                    477:     for (i = 0; i < this.configurableAttributeNames.length; i++) {
                    478:         if (this.configurableAttributeNames[i] == attribute) {
                    479:             this.configurableAttributeValues[i] = value;
                    480:             return;
                    481:         }
                    482:     }
                    483:     throw "Unrecognized implementation attribute: " + attr;
                    484: }
                    485:             
                    486: 
                    487: 
                    488: //
                    489: //   Only used to select tests compatible with implementation
                    490: //      not used on tests that actually test hasFeature()
                    491: //
                    492: MSXMLBuilder.prototype.hasFeature = function(feature, version) {
                    493:     //
                    494:     //   MSXML will take null, unfortunately 
                    495:     //      there is no way to get it to there from script
                    496:     //      without a type mismatch error
                    497:     if(version == null) {
                    498:                switch(feature.toUpperCase()) {
                    499:                   case "XML":
                    500:                   case "CORE":
                    501:                   return true;
                    502:                   
                    503:                   case "HTML":
                    504:                   case "ORG.W3C.DOM":
                    505:                   return false;
                    506:                }
                    507:                if(this.getDOMImplementation().hasFeature(feature,"1.0")) {
                    508:                   return true;
                    509:                }
                    510:                if(this.getDOMImplementation().hasFeature(feature,"2.0")) {
                    511:                   return true;
                    512:                }
                    513:                if(this.getDOMImplementation().hasFeature(feature,"3.0")) {
                    514:                   return true;
                    515:                }
                    516:     }
                    517:        return this.getDOMImplementation().hasFeature(feature,version);
                    518:   }
                    519: 
                    520: 
1.9       dom-ts-4  521: 
1.17      dom-ts-4  522: function MozillaXMLBuilder() {
1.18      dom-ts-4  523:     this.contentType = "text/xml";
                    524: 
                    525:     this.configurableAttributeNames = [ ];
                    526:     this.configurableAttributeValues = [ ];
                    527:     this.fixedAttributeNames = [ "validating", "ignoringElementContentWhitespace", "signed", 
                    528:         "hasNullString", "expandEntityReferences", "coalescing", "namespaceAware" ];
                    529:     this.fixedAttributeValues = [ false, false, true, true, false, false, false ];
                    530: 
                    531:     this.contentType = "text/xml";
                    532:     this.supportedContentTypes = [ 
                    533:         "text/xml", 
                    534:         "image/svg+xml", 
                    535:         "application/xhtml+xml",
                    536:         "text/mathml" ];
                    537: 
                    538:     this.async = true;
                    539:     this.supportsAsyncChange = false;
                    540: 
1.17      dom-ts-4  541:     this.docs = new Array();
                    542:     this.docnames = new Array();
1.19      dom-ts-4  543:     this.exception = null;
1.17      dom-ts-4  544: }
1.1       dom-ts-4  545: 
1.17      dom-ts-4  546: MozillaXMLBuilder.prototype.preload = function(frame, varname, url) {
                    547:   var domimpl = document.implementation;
                    548:   var doc = domimpl.createDocument("", "temp", null);
                    549:   doc.addEventListener("load", loadComplete, false);
1.18      dom-ts-4  550:   doc.load(fileBase + url + getSuffix(this.contentType));
1.17      dom-ts-4  551:   this.docs[this.docs.length] = doc;
                    552:   this.docnames[this.docnames.length] = varname;
                    553:   return 0;
                    554: }
1.1       dom-ts-4  555: 
1.17      dom-ts-4  556: MozillaXMLBuilder.prototype.load = function(frame, varname, url) {
                    557:     for(i = 0; i < this.docnames.length; i++) {
                    558:         if (this.docnames[i] == varname) {
                    559:             return this.docs[i];
1.9       dom-ts-4  560:         }
                    561:     }
1.17      dom-ts-4  562:     return null;
                    563: }
1.1       dom-ts-4  564: 
1.9       dom-ts-4  565: 
1.17      dom-ts-4  566: MozillaXMLBuilder.prototype.getImplementationAttribute = function(attr) {
1.22    ! dom-ts-4  567:     for (var i = 0; i < this.fixedAttributeNames.length; i++) {
        !           568:         if (this.fixedAttributeNames[i] == attr) {
        !           569:             return this.fixedAttributeValues[i];
        !           570:         }
        !           571:     }
1.17      dom-ts-4  572:     return false;
                    573: }
1.1       dom-ts-4  574: 
                    575: 
1.17      dom-ts-4  576: MozillaXMLBuilder.prototype.toAutoCase = function(s) {
                    577:     return s;
                    578: }
1.15      dom-ts-4  579: 
1.17      dom-ts-4  580: MozillaXMLBuilder.prototype.toAutoCaseArray = function(s) {
                    581:     return s;
1.16      dom-ts-4  582: }
                    583: 
1.22    ! dom-ts-4  584: 
        !           585: function DOM3LSBuilder() {
        !           586:     this.contentType = "text/xml";
        !           587: 
        !           588:     this.configurableAttributeNames = [ ];
        !           589:     this.configurableAttributeValues = [ ];
        !           590:     this.fixedAttributeNames = [ "validating", "ignoringElementContentWhitespace", "signed", 
        !           591:         "hasNullString", "expandEntityReferences", "coalescing", "namespaceAware" ];
        !           592:     this.fixedAttributeValues = [ false, false, true, true, false, false, true ];
        !           593: 
        !           594:     this.contentType = "text/xml";
        !           595:     this.supportedContentTypes = [ 
        !           596:         "text/xml", 
        !           597:         "image/svg+xml", 
        !           598:         "application/xhtml+xml",
        !           599:         "text/mathml" ];
        !           600: 
        !           601:     this.async = true;
        !           602:     this.supportsAsyncChange = true;
        !           603: 
        !           604:     this.docs = new Array();
        !           605:     this.docnames = new Array();
        !           606:     this.exception = null;
        !           607: }
        !           608: 
        !           609: DOM3LSBuilder.prototype.preload = function(frame, varname, url) {
        !           610:   if (this.async) {
        !           611:       var domimpl = document.implementation;
        !           612:       var dombuilder = domimpl.createDOMBuilder(2, null);
        !           613:       dombuilder.addEventListener("load", loadComplete, false);
        !           614:       var uri = fileBase + url + getSuffix(this.contentType);
        !           615:       var doc = dombuilder.parseURI(uri);
        !           616:       this.docs[this.docs.length] = doc;
        !           617:       this.docnames[this.docnames.length] = varname;
        !           618:       return 0;
        !           619:    }
        !           620:    return 1;
        !           621: }
        !           622: 
        !           623: DOM3LSBuilder.prototype.load = function(frame, varname, url) {
        !           624:     if (this.async) {
        !           625:         for(i = 0; i < this.docnames.length; i++) {
        !           626:             if (this.docnames[i] == varname) {
        !           627:                 return this.docs[i];
        !           628:             }
        !           629:         }
        !           630:         return null;
        !           631:     }
        !           632:     var dombuilder = document.implementation.createDOMBuilder(1, null);
        !           633:     var uri = fileBase + url + getSuffix(this.contentType);
        !           634:     return dombuilder.parseURI(uri);
        !           635: }
        !           636: 
        !           637: 
        !           638: DOM3LSBuilder.prototype.getImplementationAttribute = function(attr) {
        !           639:     for (var i = 0; i < this.fixedAttributeNames.length; i++) {
        !           640:         if (this.fixedAttributeNames[i] == attr) {
        !           641:             return this.fixedAttributeValues[i];
        !           642:         }
        !           643:     }
        !           644: }
        !           645: 
        !           646: 
        !           647: DOM3LSBuilder.prototype.toAutoCase = function(s) {
        !           648:     return s;
        !           649: }
        !           650: 
        !           651: DOM3LSBuilder.prototype.toAutoCaseArray = function(s) {
        !           652:     return s;
        !           653: }
        !           654: 
1.18      dom-ts-4  655: function createBuilder(implementation) {
                    656:   switch(implementation) {
                    657:     case "msxml3":
                    658:     return new MSXMLBuilder("Msxml.DOMDocument.3.0");
                    659:     
                    660:     case "msxml4":
                    661:     return new MSXMLBuilder("Msxml2.DOMDocument.4.0");
                    662: 
                    663:     case "mozilla":
                    664:     return new MozillaXMLBuilder();
                    665: 
1.20      dom-ts-4  666:     case "svgplugin":
                    667:     return new SVGPluginBuilder();
1.18      dom-ts-4  668: 
                    669:     case "dom3ls":
1.22    ! dom-ts-4  670:     return new DOM3LSBuilder();
1.18      dom-ts-4  671:   }
                    672:   return new IFrameBuilder();
                    673: }
                    674: 
                    675: var builder = null;
                    676: 
                    677: if (top && top.jsUnitParmHash)
                    678: {
                    679:     builder = createBuilder(top.jsUnitParmHash.implementation);
1.19      dom-ts-4  680:     try {
                    681:         if (top.jsUnitParmHash.asynchronous == 'true' && builder.supportAsync) {
                    682:             builder.async = true;
                    683:         }
                    684:         if (top.jsUnitParmHash.expandentityreferences) {
                    685:             if (top.jsUnitParmHash.expandEntityReferences == 'true') {
                    686:                 builder.setImplementationAttribute('expandEntityReferences', true);
                    687:             } else {
                    688:                 builder.setImplementationAttribute('expandEntityReferences', false);
                    689:             }
                    690:         }
                    691:         if (top.jsUnitParmHash.ignoringelementcontentwhitespace) {
                    692:             if (top.jsUnitParmHash.ignoringElementContentWhitespace == 'true') {
                    693:                 builder.setImplementationAttribute('ignoringElementContentWhitespace', true);
                    694:             } else {
                    695:                 builder.setImplementationAttribute('ignoringElementContentWhitespace', false);
                    696:             }
                    697:         }
                    698:         if (top.jsUnitParmHash.validating) {
                    699:             if (top.jsUnitParmHash.validating == 'true') {
                    700:                 builder.setImplementationAttribute('validating', true);
                    701:             } else {
                    702:                 builder.setImplementationAttribute('validating', false);
                    703:             }
                    704:         }
                    705:         if (top.jsUnitParmHash.coalescing) {
                    706:             if (top.jsUnitParmHash.coalescing == 'true') {
                    707:                 builder.setImplementationAttribute('coalescing', true);
                    708:             } else {
                    709:                 builder.setImplementationAttribute('coalescing', false);
                    710:             }
                    711:         }
                    712:         if (top.jsUnitParmHash.namespaceaware) {
                    713:             if (top.jsUnitParmHash.namespaceaware == 'true') {
                    714:                 builder.setImplementationAttribute('namespaceAware', true);
                    715:             } else {
                    716:                 builder.setImplementationAttribute('namespaceAware', false);
                    717:             }
                    718:         }
                    719:         var contentType = top.jsUnitParmHash.contenttype;
                    720:         if (contentType != null) {
                    721:             var contentTypeSet = false;
                    722:             for (var i = 0; i < builder.supportedContentTypes.length; i++) {
                    723:                 if (builder.supportedContentTypes[i] == contentType) {
                    724:                     builder.contentType = contentType;
                    725:                     contentTypeSet = true;
                    726:                     break;
                    727:                 }
                    728:             }
                    729:             if (!contentTypeSet) {
                    730:                 builder.exception = "Builder does not support content type " + contentType;
                    731:             }
                    732:         }
                    733:     }
                    734:     catch(ex) {
                    735:         builder.exception = ex;
                    736:     }
1.18      dom-ts-4  737: } else {
                    738:     builder = new IFrameBuilder();
                    739: }
1.16      dom-ts-4  740: 
                    741: 
1.17      dom-ts-4  742: function preload(frame, varname, url) {
                    743:   return builder.preload(frame, varname, url);
1.15      dom-ts-4  744: }
                    745: 
1.17      dom-ts-4  746: function load(frame, varname, url) {
                    747:     return builder.load(frame, varname, url);
1.16      dom-ts-4  748: }
1.15      dom-ts-4  749: 
1.17      dom-ts-4  750: function getImplementationAttribute(attr) {
                    751:     return builder.getImplementationAttribute(attr);
1.15      dom-ts-4  752: }
1.16      dom-ts-4  753: 
1.9       dom-ts-4  754: 
1.17      dom-ts-4  755: function toAutoCase(s) {
                    756:     return builder.toAutoCase(s);
                    757: }
1.1       dom-ts-4  758: 
1.17      dom-ts-4  759: function toAutoCaseArray(s) {
                    760:     return builder.toAutoCaseArray(s);
                    761: }
1.10      dom-ts-4  762: 
1.18      dom-ts-4  763: function setImplementationAttribute(attribute, value) {
                    764:     builder.setImplementationAttribute(attribute, value);
                    765: }
                    766: 
1.21      dom-ts-4  767: function createXPathEvaluator(doc) {
                    768:     try {
                    769:         return doc.getFeature("XPath", null);
                    770:     }
                    771:     catch(ex) {
                    772:     }
                    773:     return doc;
                    774: }
                    775: 
1.10      dom-ts-4  776: 
1.18      dom-ts-4  777: function MSXMLBuilder_onreadystatechange() {
                    778:     if (builder.parser.readyState == 4) {
                    779:         loadComplete();
                    780:     }
1.19      dom-ts-4  781: }
                    782: 
                    783: 
                    784: var fileBase = location.href;
                    785: if (fileBase.indexOf('?') != -1) {
                    786:    fileBase = fileBase.substring(0, fileBase.indexOf('?'));
                    787: }
1.20      dom-ts-4  788: fileBase = fileBase.substring(0, fileBase.lastIndexOf('/') + 1) + "files/";
                    789: 
                    790: 
1.19      dom-ts-4  791: 

Webmaster