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