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