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