nicholas@2224: function Specification() { nicholas@2224: // Handles the decoding of the project specification XML into a simple JavaScript Object. nicholas@2224: nicholas@2378: // attributes nicholas@2224: this.interface = null; nicholas@2303: this.projectReturn = null; nicholas@2303: this.returnURL = null; nicholas@2224: this.randomiseOrder = null; nicholas@2378: this.poolSize = null; nicholas@2378: this.loudness = null; nicholas@2378: this.sampleRate = null; nicholas@2378: this.calibration = null; nicholas@2378: this.crossFade = null; nicholas@2378: this.preSilence = null; nicholas@2378: this.postSilence = null; n@2426: this.playOne = null; nicholas@2378: nicholas@2378: // nodes nicholas@2378: this.metrics = null; nicholas@2378: this.preTest = undefined; nicholas@2378: this.postTest = undefined; nicholas@2224: this.pages = []; nicholas@2224: this.interfaces = 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@2378: for (var i=0; i 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