nickjillings@1925: function Specification() { nickjillings@1925: // Handles the decoding of the project specification XML into a simple JavaScript Object. nickjillings@1925: nickjillings@1925: this.interface = null; nickjillings@1925: this.projectReturn = "null"; nickjillings@1925: this.randomiseOrder = null; nickjillings@1925: this.testPages = null; nickjillings@1925: this.pages = []; nickjillings@1925: this.metrics = null; nickjillings@1925: this.interfaces = null; nickjillings@1925: this.loudness = null; nickjillings@1925: this.errors = []; nickjillings@1925: this.schema = null; nickjillings@1925: this.exitText = "Thank you."; nickjillings@1925: nickjillings@1925: this.processAttribute = function(attribute,schema,schemaRoot) nickjillings@1925: { nickjillings@1925: // attribute is the string returned from getAttribute on the XML nickjillings@1925: // schema is the node nickjillings@1925: if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined) nickjillings@1925: { nickjillings@1925: schema = schemaRoot.getAllElementsByName(schema.getAttribute('ref'))[0]; nickjillings@1925: } nickjillings@1925: var defaultOpt = schema.getAttribute('default'); nickjillings@1925: if (attribute == null) { nickjillings@1925: attribute = defaultOpt; nickjillings@1925: } nickjillings@1925: var dataType = schema.getAttribute('type'); nickjillings@1925: if (typeof dataType == "string") { dataType = dataType.substr(3);} nickjillings@1925: else {dataType = "string";} nickjillings@1925: if (attribute == null) nickjillings@1925: { nickjillings@1925: return attribute; nickjillings@1925: } nickjillings@1925: switch(dataType) nickjillings@1925: { nickjillings@1925: case "boolean": nickjillings@1925: if (attribute == 'true'){attribute = true;}else{attribute=false;} nickjillings@1925: break; nickjillings@1925: case "negativeInteger": nickjillings@1925: case "positiveInteger": nickjillings@1925: case "nonNegativeInteger": nickjillings@1925: case "nonPositiveInteger": nickjillings@1925: case "integer": nickjillings@1925: case "decimal": nickjillings@1925: case "short": nickjillings@1925: attribute = Number(attribute); nickjillings@1925: break; nickjillings@1925: case "string": nickjillings@1925: default: nickjillings@1925: attribute = String(attribute); nickjillings@1925: break; nickjillings@1925: } nickjillings@1925: return attribute; nickjillings@1925: }; nickjillings@1925: nickjillings@1925: this.decode = function(projectXML) { nickjillings@1925: this.errors = []; nickjillings@1925: // projectXML - DOM Parsed document nickjillings@1925: this.projectXML = projectXML.childNodes[0]; nickjillings@1925: var setupNode = projectXML.getElementsByTagName('setup')[0]; nickjillings@1925: var schemaSetup = this.schema.getAllElementsByName('setup')[0]; nickjillings@1925: // First decode the attributes nickjillings@1925: var attributes = schemaSetup.getAllElementsByTagName('xs:attribute'); nickjillings@1925: for (var i in attributes) nickjillings@1925: { nickjillings@1925: if (isNaN(Number(i)) == true){break;} nickjillings@1925: var attributeName = attributes[i].getAttribute('name') || attributes[i].getAttribute('ref'); nickjillings@1925: var projectAttr = setupNode.getAttribute(attributeName); nickjillings@1925: projectAttr = this.processAttribute(projectAttr,attributes[i],this.schema); nickjillings@1925: switch(typeof projectAttr) nickjillings@1925: { nickjillings@1925: case "number": nickjillings@1925: case "boolean": nickjillings@1925: eval('this.'+attributeName+' = '+projectAttr); nickjillings@1925: break; nickjillings@1925: case "string": nickjillings@1925: eval('this.'+attributeName+' = "'+projectAttr+'"'); nickjillings@1925: break; nickjillings@1925: } nickjillings@1925: nickjillings@1925: } nickjillings@1925: nickjillings@1925: var exitTextNode = setupNode.getElementsByTagName('exitText'); nickjillings@1925: if (exitTextNode.length == 1) { nickjillings@1925: this.exitText = exitTextNode[0].textContent; nickjillings@1925: } nickjillings@1925: nickjillings@1925: this.metrics = new this.metricNode(); nickjillings@1925: nickjillings@1925: this.metrics.decode(this,setupNode.getElementsByTagName('metric')[0]); nickjillings@1925: nickjillings@1925: // Now process the survey node options nickjillings@1925: var survey = setupNode.getElementsByTagName('survey'); nickjillings@1925: for (var i in survey) { nickjillings@1925: if (isNaN(Number(i)) == true){break;} nickjillings@1925: var location = survey[i].getAttribute('location'); nickjillings@1925: if (location == 'pre' || location == 'before') nickjillings@1925: { nickjillings@1925: if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");} nickjillings@1925: else { nickjillings@1925: this.preTest = new this.surveyNode(this); nickjillings@1925: this.preTest.decode(this,survey[i]); nickjillings@1925: } nickjillings@1925: } else if (location == 'post' || location == 'after') { nickjillings@1925: if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");} nickjillings@1925: else { nickjillings@1925: this.postTest = new this.surveyNode(this); nickjillings@1925: this.postTest.decode(this,survey[i]); nickjillings@1925: } nickjillings@1925: } nickjillings@1925: } nickjillings@1925: nickjillings@1925: var interfaceNode = setupNode.getElementsByTagName('interface'); nickjillings@1925: if (interfaceNode.length > 1) nickjillings@1925: { nickjillings@1925: this.errors.push("Only one node in the node allowed! Others except first ingnored!"); nickjillings@1925: } nickjillings@1925: this.interfaces = new this.interfaceNode(this); nickjillings@1925: if (interfaceNode.length != 0) nickjillings@1925: { nickjillings@1925: interfaceNode = interfaceNode[0]; nickjillings@1925: this.interfaces.decode(this,interfaceNode,this.schema.getAllElementsByName('interface')[1]); nickjillings@1925: } nickjillings@1925: nickjillings@1925: // Page tags nickjillings@1925: var pageTags = projectXML.getElementsByTagName('page'); nickjillings@1925: var pageSchema = this.schema.getAllElementsByName('page')[0]; nickjillings@1925: for (var i=0; i nickjillings@1925: var commentboxprefix = root.createElement("commentboxprefix"); nickjillings@1925: commentboxprefix.textContent = this.commentBoxPrefix; nickjillings@1925: AHNode.appendChild(commentboxprefix); nickjillings@1925: nickjillings@1925: for (var i=0; i nickjillings@1925: for (var i=0; i