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