annotate specification.js @ 2212:279733b3b67e

Move pythonServer-legacy.py to scripts
author Brecht De Man <b.deman@qmul.ac.uk>
date Wed, 13 Apr 2016 15:46:12 +0100
parents ed5a54029157
children 30bffc455b4d
rev   line source
nickjillings@2192 1 function Specification() {
nickjillings@2192 2 // Handles the decoding of the project specification XML into a simple JavaScript Object.
nickjillings@2192 3
nickjillings@2192 4 this.interface = null;
nickjillings@2192 5 this.projectReturn = "null";
nickjillings@2192 6 this.randomiseOrder = null;
nickjillings@2192 7 this.testPages = null;
nickjillings@2192 8 this.pages = [];
nickjillings@2192 9 this.metrics = null;
nickjillings@2192 10 this.interfaces = null;
nickjillings@2192 11 this.loudness = null;
nickjillings@2192 12 this.errors = [];
nickjillings@2192 13 this.schema = null;
nickjillings@2192 14 this.exitText = "Thank you.";
nickjillings@2192 15
nickjillings@2192 16 this.processAttribute = function(attribute,schema,schemaRoot)
nickjillings@2192 17 {
nickjillings@2192 18 // attribute is the string returned from getAttribute on the XML
nickjillings@2192 19 // schema is the <xs:attribute> node
nickjillings@2192 20 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined)
nickjillings@2192 21 {
nickjillings@2192 22 schema = schemaRoot.getAllElementsByName(schema.getAttribute('ref'))[0];
nickjillings@2192 23 }
nickjillings@2192 24 var defaultOpt = schema.getAttribute('default');
nickjillings@2192 25 if (attribute == null) {
nickjillings@2192 26 attribute = defaultOpt;
nickjillings@2192 27 }
nickjillings@2192 28 var dataType = schema.getAttribute('type');
nickjillings@2192 29 if (typeof dataType == "string") { dataType = dataType.substr(3);}
nickjillings@2192 30 else {dataType = "string";}
nickjillings@2192 31 if (attribute == null)
nickjillings@2192 32 {
nickjillings@2192 33 return attribute;
nickjillings@2192 34 }
nickjillings@2192 35 switch(dataType)
nickjillings@2192 36 {
nickjillings@2192 37 case "boolean":
nickjillings@2192 38 if (attribute == 'true'){attribute = true;}else{attribute=false;}
nickjillings@2192 39 break;
nickjillings@2192 40 case "negativeInteger":
nickjillings@2192 41 case "positiveInteger":
nickjillings@2192 42 case "nonNegativeInteger":
nickjillings@2192 43 case "nonPositiveInteger":
nickjillings@2192 44 case "integer":
nickjillings@2192 45 case "decimal":
nickjillings@2192 46 case "short":
nickjillings@2192 47 attribute = Number(attribute);
nickjillings@2192 48 break;
nickjillings@2192 49 case "string":
nickjillings@2192 50 default:
nickjillings@2192 51 attribute = String(attribute);
nickjillings@2192 52 break;
nickjillings@2192 53 }
nickjillings@2192 54 return attribute;
nickjillings@2192 55 };
nickjillings@2192 56
nickjillings@2192 57 this.decode = function(projectXML) {
nickjillings@2192 58 this.errors = [];
nickjillings@2192 59 // projectXML - DOM Parsed document
nickjillings@2192 60 this.projectXML = projectXML.childNodes[0];
nickjillings@2192 61 var setupNode = projectXML.getElementsByTagName('setup')[0];
nickjillings@2192 62 var schemaSetup = this.schema.getAllElementsByName('setup')[0];
nickjillings@2192 63 // First decode the attributes
nickjillings@2192 64 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute');
nickjillings@2192 65 for (var i in attributes)
nickjillings@2192 66 {
nickjillings@2192 67 if (isNaN(Number(i)) == true){break;}
nickjillings@2192 68 var attributeName = attributes[i].getAttribute('name') || attributes[i].getAttribute('ref');
nickjillings@2192 69 var projectAttr = setupNode.getAttribute(attributeName);
nickjillings@2192 70 projectAttr = this.processAttribute(projectAttr,attributes[i],this.schema);
nickjillings@2192 71 switch(typeof projectAttr)
nickjillings@2192 72 {
nickjillings@2192 73 case "number":
nickjillings@2192 74 case "boolean":
nickjillings@2192 75 eval('this.'+attributeName+' = '+projectAttr);
nickjillings@2192 76 break;
nickjillings@2192 77 case "string":
nickjillings@2192 78 eval('this.'+attributeName+' = "'+projectAttr+'"');
nickjillings@2192 79 break;
nickjillings@2192 80 }
nickjillings@2192 81
nickjillings@2192 82 }
nickjillings@2192 83
nickjillings@2192 84 var exitTextNode = setupNode.getElementsByTagName('exitText');
nickjillings@2192 85 if (exitTextNode.length == 1) {
nickjillings@2192 86 this.exitText = exitTextNode[0].textContent;
nickjillings@2192 87 }
nickjillings@2192 88
nickjillings@2192 89 this.metrics = new this.metricNode();
nickjillings@2192 90
nickjillings@2192 91 this.metrics.decode(this,setupNode.getElementsByTagName('metric')[0]);
nickjillings@2192 92
nickjillings@2192 93 // Now process the survey node options
nickjillings@2192 94 var survey = setupNode.getElementsByTagName('survey');
nickjillings@2192 95 for (var i in survey) {
nickjillings@2192 96 if (isNaN(Number(i)) == true){break;}
nickjillings@2192 97 var location = survey[i].getAttribute('location');
nickjillings@2192 98 if (location == 'pre' || location == 'before')
nickjillings@2192 99 {
nickjillings@2192 100 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
nickjillings@2192 101 else {
nickjillings@2192 102 this.preTest = new this.surveyNode(this);
nickjillings@2192 103 this.preTest.decode(this,survey[i]);
nickjillings@2192 104 }
nickjillings@2192 105 } else if (location == 'post' || location == 'after') {
nickjillings@2192 106 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
nickjillings@2192 107 else {
nickjillings@2192 108 this.postTest = new this.surveyNode(this);
nickjillings@2192 109 this.postTest.decode(this,survey[i]);
nickjillings@2192 110 }
nickjillings@2192 111 }
nickjillings@2192 112 }
nickjillings@2192 113
nickjillings@2192 114 var interfaceNode = setupNode.getElementsByTagName('interface');
nickjillings@2192 115 if (interfaceNode.length > 1)
nickjillings@2192 116 {
nickjillings@2192 117 this.errors.push("Only one <interface> node in the <setup> node allowed! Others except first ingnored!");
nickjillings@2192 118 }
nickjillings@2192 119 this.interfaces = new this.interfaceNode(this);
nickjillings@2192 120 if (interfaceNode.length != 0)
nickjillings@2192 121 {
nickjillings@2192 122 interfaceNode = interfaceNode[0];
nickjillings@2192 123 this.interfaces.decode(this,interfaceNode,this.schema.getAllElementsByName('interface')[1]);
nickjillings@2192 124 }
nickjillings@2192 125
nickjillings@2192 126 // Page tags
nickjillings@2192 127 var pageTags = projectXML.getElementsByTagName('page');
nickjillings@2192 128 var pageSchema = this.schema.getAllElementsByName('page')[0];
nickjillings@2192 129 for (var i=0; i<pageTags.length; i++)
nickjillings@2192 130 {
nickjillings@2192 131 var node = new this.page(this);
nickjillings@2192 132 node.decode(this,pageTags[i],pageSchema);
nickjillings@2192 133 this.pages.push(node);
nickjillings@2192 134 }
nickjillings@2192 135 };
nickjillings@2192 136
nickjillings@2192 137 this.encode = function()
nickjillings@2192 138 {
nickjillings@2192 139 var RootDocument = document.implementation.createDocument(null,"waet");
nickjillings@2192 140 var root = RootDocument.children[0];
nickjillings@2192 141 root.setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
nickjillings@2192 142 root.setAttribute("xsi:noNamespaceSchemaLocation","test-schema.xsd");
nickjillings@2192 143 // Build setup node
nickjillings@2192 144 var setup = RootDocument.createElement("setup");
nickjillings@2192 145 var schemaSetup = this.schema.getAllElementsByName('setup')[0];
nickjillings@2192 146 // First decode the attributes
nickjillings@2192 147 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute');
nickjillings@2192 148 for (var i=0; i<attributes.length; i++)
nickjillings@2192 149 {
nickjillings@2192 150 var name = attributes[i].getAttribute("name");
nickjillings@2192 151 if (name == undefined) {
nickjillings@2192 152 name = attributes[i].getAttribute("ref");
nickjillings@2192 153 }
nickjillings@2192 154 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
nickjillings@2192 155 {
nickjillings@2192 156 eval("setup.setAttribute('"+name+"',this."+name+")");
nickjillings@2192 157 }
nickjillings@2192 158 }
nickjillings@2192 159 root.appendChild(setup);
nickjillings@2192 160 // Survey node
nickjillings@2192 161 if (this.exitText != null) {
nickjillings@2192 162 var exitTextNode = RootDocument.createElement('exitText');
nickjillings@2192 163 exitTextNode.textContent = this.exitText;
nickjillings@2192 164 setup.appendChild(exitTextNode);
nickjillings@2192 165 }
nickjillings@2192 166 setup.appendChild(this.preTest.encode(RootDocument));
nickjillings@2192 167 setup.appendChild(this.postTest.encode(RootDocument));
nickjillings@2192 168 setup.appendChild(this.metrics.encode(RootDocument));
nickjillings@2192 169 setup.appendChild(this.interfaces.encode(RootDocument));
nickjillings@2192 170 for (var page of this.pages)
nickjillings@2192 171 {
nickjillings@2192 172 root.appendChild(page.encode(RootDocument));
nickjillings@2192 173 }
nickjillings@2192 174 return RootDocument;
nickjillings@2192 175 };
nickjillings@2192 176
nickjillings@2192 177 this.surveyNode = function(specification) {
nickjillings@2192 178 this.location = null;
nickjillings@2192 179 this.options = [];
nickjillings@2192 180 this.parent = null;
nickjillings@2192 181 this.schema = specification.schema.getAllElementsByName('survey')[0];
nickjillings@2192 182 this.specification = specification;
nickjillings@2192 183
nickjillings@2192 184 this.OptionNode = function(specification) {
nickjillings@2192 185 this.type = undefined;
nickjillings@2192 186 this.schema = specification.schema.getAllElementsByName('surveyentry')[0];
nickjillings@2192 187 this.id = undefined;
nickjillings@2192 188 this.name = undefined;
nickjillings@2192 189 this.mandatory = undefined;
nickjillings@2192 190 this.statement = undefined;
nickjillings@2192 191 this.boxsize = undefined;
nickjillings@2192 192 this.options = [];
nickjillings@2192 193 this.min = undefined;
nickjillings@2192 194 this.max = undefined;
nickjillings@2192 195 this.step = undefined;
nickjillings@2192 196
nickjillings@2192 197 this.decode = function(parent,child)
nickjillings@2192 198 {
nickjillings@2192 199 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
nickjillings@2192 200 for (var i in attributeMap){
nickjillings@2192 201 if(isNaN(Number(i)) == true){break;}
nickjillings@2192 202 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
nickjillings@2192 203 var projectAttr = child.getAttribute(attributeName);
nickjillings@2192 204 projectAttr = parent.processAttribute(projectAttr,attributeMap[i],parent.schema);
nickjillings@2192 205 switch(typeof projectAttr)
nickjillings@2192 206 {
nickjillings@2192 207 case "number":
nickjillings@2192 208 case "boolean":
nickjillings@2192 209 eval('this.'+attributeName+' = '+projectAttr);
nickjillings@2192 210 break;
nickjillings@2192 211 case "string":
nickjillings@2192 212 eval('this.'+attributeName+' = "'+projectAttr+'"');
nickjillings@2192 213 break;
nickjillings@2192 214 }
nickjillings@2192 215 }
nickjillings@2192 216 this.statement = child.getElementsByTagName('statement')[0].textContent;
nickjillings@2192 217 if (this.type == "checkbox" || this.type == "radio") {
nickjillings@2192 218 var children = child.getElementsByTagName('option');
nickjillings@2192 219 if (children.length == null) {
nickjillings@2192 220 console.log('Malformed' +child.nodeName+ 'entry');
nickjillings@2192 221 this.statement = 'Malformed' +child.nodeName+ 'entry';
nickjillings@2192 222 this.type = 'statement';
nickjillings@2192 223 } else {
nickjillings@2192 224 this.options = [];
nickjillings@2192 225 for (var i in children)
nickjillings@2192 226 {
nickjillings@2192 227 if (isNaN(Number(i))==true){break;}
nickjillings@2192 228 this.options.push({
nickjillings@2192 229 name: children[i].getAttribute('name'),
nickjillings@2192 230 text: children[i].textContent
nickjillings@2192 231 });
nickjillings@2192 232 }
nickjillings@2192 233 }
nickjillings@2192 234 }
nickjillings@2192 235 };
nickjillings@2192 236
nickjillings@2192 237 this.exportXML = function(doc)
nickjillings@2192 238 {
nickjillings@2192 239 var node = doc.createElement('surveyentry');
nickjillings@2192 240 node.setAttribute('type',this.type);
nickjillings@2192 241 var statement = doc.createElement('statement');
nickjillings@2192 242 statement.textContent = this.statement;
nickjillings@2192 243 node.appendChild(statement);
nickjillings@2192 244 node.id = this.id;
nickjillings@2192 245 if (this.name != undefined) { node.setAttribute("name",this.name);}
nickjillings@2192 246 if (this.mandatory != undefined) { node.setAttribute("mandatory",this.mandatory);}
nickjillings@2192 247 node.id = this.id;
nickjillings@2192 248 if (this.name != undefined) {node.setAttribute("name",this.name);}
nickjillings@2192 249 switch(this.type)
nickjillings@2192 250 {
nickjillings@2192 251 case "checkbox":
nickjillings@2192 252 case "radio":
nickjillings@2192 253 for (var i=0; i<this.options.length; i++)
nickjillings@2192 254 {
nickjillings@2192 255 var option = this.options[i];
nickjillings@2192 256 var optionNode = doc.createElement("option");
nickjillings@2192 257 optionNode.setAttribute("name",option.name);
nickjillings@2192 258 optionNode.textContent = option.text;
nickjillings@2192 259 node.appendChild(optionNode);
nickjillings@2192 260 }
nickjillings@2192 261 case "number":
nickjillings@2192 262 if (this.min != undefined) {node.setAttribute("min", this.min);}
nickjillings@2192 263 if (this.max != undefined) {node.setAttribute("max", this.max);}
nickjillings@2192 264 case "question":
nickjillings@2192 265 if (this.boxsize != undefined) {node.setAttribute("boxsize",this.boxsize);}
nickjillings@2192 266 if (this.mandatory != undefined) {node.setAttribute("mandatory",this.mandatory);}
nickjillings@2192 267 default:
nickjillings@2192 268 break;
nickjillings@2192 269 }
nickjillings@2192 270 return node;
nickjillings@2192 271 };
nickjillings@2192 272 };
nickjillings@2192 273 this.decode = function(parent,xml) {
nickjillings@2192 274 this.parent = parent;
nickjillings@2192 275 this.location = xml.getAttribute('location');
nickjillings@2192 276 if (this.location == 'before'){this.location = 'pre';}
nickjillings@2192 277 else if (this.location == 'after'){this.location = 'post';}
nickjillings@2192 278 for (var i in xml.children)
nickjillings@2192 279 {
nickjillings@2192 280 if(isNaN(Number(i))==true){break;}
nickjillings@2192 281 var node = new this.OptionNode(this.specification);
nickjillings@2192 282 node.decode(parent,xml.children[i]);
nickjillings@2192 283 this.options.push(node);
nickjillings@2192 284 }
nickjillings@2192 285 };
nickjillings@2192 286 this.encode = function(doc) {
nickjillings@2192 287 var node = doc.createElement('survey');
nickjillings@2192 288 node.setAttribute('location',this.location);
nickjillings@2192 289 for (var i=0; i<this.options.length; i++)
nickjillings@2192 290 {
nickjillings@2192 291 node.appendChild(this.options[i].exportXML(doc));
nickjillings@2192 292 }
nickjillings@2192 293 return node;
nickjillings@2192 294 };
nickjillings@2192 295 };
nickjillings@2192 296
nickjillings@2192 297 this.interfaceNode = function(specification)
nickjillings@2192 298 {
nickjillings@2192 299 this.title = null;
nickjillings@2192 300 this.name = null;
nickjillings@2192 301 this.options = [];
nickjillings@2192 302 this.scales = [];
nickjillings@2192 303 this.schema = specification.schema.getAllElementsByName('interface')[1];
nickjillings@2192 304
nickjillings@2192 305 this.decode = function(parent,xml) {
nickjillings@2192 306 this.name = xml.getAttribute('name');
nickjillings@2192 307 var titleNode = xml.getElementsByTagName('title');
nickjillings@2192 308 if (titleNode.length == 1)
nickjillings@2192 309 {
nickjillings@2192 310 this.title = titleNode[0].textContent;
nickjillings@2192 311 }
nickjillings@2192 312 var interfaceOptionNodes = xml.getElementsByTagName('interfaceoption');
nickjillings@2192 313 // Extract interfaceoption node schema
nickjillings@2192 314 var interfaceOptionNodeSchema = this.schema.getAllElementsByName('interfaceoption')[0];
nickjillings@2192 315 var attributeMap = interfaceOptionNodeSchema.getAllElementsByTagName('xs:attribute');
nickjillings@2192 316 for (var i=0; i<interfaceOptionNodes.length; i++)
nickjillings@2192 317 {
nickjillings@2192 318 var ioNode = interfaceOptionNodes[i];
nickjillings@2192 319 var option = {};
nickjillings@2192 320 for (var j=0; j<attributeMap.length; j++)
nickjillings@2192 321 {
nickjillings@2192 322 var attributeName = attributeMap[j].getAttribute('name') || attributeMap[j].getAttribute('ref');
nickjillings@2192 323 var projectAttr = ioNode.getAttribute(attributeName);
nickjillings@2192 324 if(parent.processAttribute) {
nickjillings@2192 325 parent.processAttribute(projectAttr, attributeMap[j], parent.schema)
nickjillings@2192 326 } else {
nickjillings@2192 327 parent.parent.processAttribute(projectAttr, attributeMap[j], parent.parent.schema)
nickjillings@2192 328 }
nickjillings@2192 329 switch(typeof projectAttr)
nickjillings@2192 330 {
nickjillings@2192 331 case "number":
nickjillings@2192 332 case "boolean":
nickjillings@2192 333 eval('option.'+attributeName+' = '+projectAttr);
nickjillings@2192 334 break;
nickjillings@2192 335 case "string":
nickjillings@2192 336 eval('option.'+attributeName+' = "'+projectAttr+'"');
nickjillings@2192 337 break;
nickjillings@2192 338 }
nickjillings@2192 339 }
nickjillings@2192 340 this.options.push(option);
nickjillings@2192 341 }
nickjillings@2192 342
nickjillings@2192 343 // Now the scales nodes
nickjillings@2192 344 var scaleParent = xml.getElementsByTagName('scales');
nickjillings@2192 345 if (scaleParent.length == 1) {
nickjillings@2192 346 scaleParent = scaleParent[0];
nickjillings@2192 347 for (var i=0; i<scaleParent.children.length; i++) {
nickjillings@2192 348 var child = scaleParent.children[i];
nickjillings@2192 349 this.scales.push({
nickjillings@2192 350 text: child.textContent,
nickjillings@2192 351 position: Number(child.getAttribute('position'))
nickjillings@2192 352 });
nickjillings@2192 353 }
nickjillings@2192 354 }
nickjillings@2192 355 };
nickjillings@2192 356
nickjillings@2192 357 this.encode = function(doc) {
nickjillings@2192 358 var node = doc.createElement("interface");
nickjillings@2192 359 if (typeof name == "string")
nickjillings@2192 360 node.setAttribute("name",this.name);
nickjillings@2192 361 for (var option of this.options)
nickjillings@2192 362 {
nickjillings@2192 363 var child = doc.createElement("interfaceoption");
nickjillings@2192 364 child.setAttribute("type",option.type);
nickjillings@2192 365 child.setAttribute("name",option.name);
nickjillings@2192 366 node.appendChild(child);
nickjillings@2192 367 }
nickjillings@2192 368 if (this.scales.length != 0) {
nickjillings@2192 369 var scales = doc.createElement("scales");
nickjillings@2192 370 for (var scale of this.scales)
nickjillings@2192 371 {
nickjillings@2192 372 var child = doc.createElement("scalelabel");
nickjillings@2192 373 child.setAttribute("position",scale.position);
nickjillings@2192 374 child.textContent = scale.text;
nickjillings@2192 375 scales.appendChild(child);
nickjillings@2192 376 }
nickjillings@2192 377 node.appendChild(scales);
nickjillings@2192 378 }
nickjillings@2192 379 return node;
nickjillings@2192 380 };
nickjillings@2192 381 };
nickjillings@2192 382
nickjillings@2192 383 this.metricNode = function() {
nickjillings@2192 384 this.enabled = [];
nickjillings@2192 385 this.decode = function(parent, xml) {
nickjillings@2192 386 var children = xml.getElementsByTagName('metricenable');
nickjillings@2192 387 for (var i in children) {
nickjillings@2192 388 if (isNaN(Number(i)) == true){break;}
nickjillings@2192 389 this.enabled.push(children[i].textContent);
nickjillings@2192 390 }
nickjillings@2192 391 }
nickjillings@2192 392 this.encode = function(doc) {
nickjillings@2192 393 var node = doc.createElement('metric');
nickjillings@2192 394 for (var i in this.enabled)
nickjillings@2192 395 {
nickjillings@2192 396 if (isNaN(Number(i)) == true){break;}
nickjillings@2192 397 var child = doc.createElement('metricenable');
nickjillings@2192 398 child.textContent = this.enabled[i];
nickjillings@2192 399 node.appendChild(child);
nickjillings@2192 400 }
nickjillings@2192 401 return node;
nickjillings@2192 402 }
nickjillings@2192 403 }
nickjillings@2192 404
nickjillings@2192 405 this.page = function(specification) {
nickjillings@2192 406 this.presentedId = undefined;
nickjillings@2192 407 this.id = undefined;
nickjillings@2192 408 this.hostURL = undefined;
nickjillings@2192 409 this.randomiseOrder = undefined;
nickjillings@2192 410 this.loop = undefined;
nickjillings@2192 411 this.showElementComments = undefined;
nickjillings@2192 412 this.outsideReference = null;
nickjillings@2192 413 this.loudness = null;
nickjillings@2192 414 this.label = null;
nickjillings@2192 415 this.preTest = null;
nickjillings@2192 416 this.postTest = null;
nickjillings@2192 417 this.interfaces = [];
nickjillings@2192 418 this.commentBoxPrefix = "Comment on track";
nickjillings@2192 419 this.audioElements = [];
nickjillings@2192 420 this.commentQuestions = [];
nickjillings@2192 421 this.schema = specification.schema.getAllElementsByName("page")[0];
nickjillings@2192 422 this.specification = specification;
nickjillings@2192 423 this.parent = null;
nickjillings@2192 424
nickjillings@2192 425 this.decode = function(parent,xml)
nickjillings@2192 426 {
nickjillings@2192 427 this.parent = parent;
nickjillings@2192 428 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
nickjillings@2192 429 for (var i=0; i<attributeMap.length; i++)
nickjillings@2192 430 {
nickjillings@2192 431 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
nickjillings@2192 432 var projectAttr = xml.getAttribute(attributeName);
nickjillings@2192 433 projectAttr = parent.processAttribute(projectAttr,attributeMap[i],parent.schema);
nickjillings@2192 434 switch(typeof projectAttr)
nickjillings@2192 435 {
nickjillings@2192 436 case "number":
nickjillings@2192 437 case "boolean":
nickjillings@2192 438 eval('this.'+attributeName+' = '+projectAttr);
nickjillings@2192 439 break;
nickjillings@2192 440 case "string":
nickjillings@2192 441 eval('this.'+attributeName+' = "'+projectAttr+'"');
nickjillings@2192 442 break;
nickjillings@2192 443 }
nickjillings@2192 444 }
nickjillings@2192 445
nickjillings@2192 446 // Get the Comment Box Prefix
nickjillings@2192 447 var CBP = xml.getElementsByTagName('commentboxprefix');
nickjillings@2192 448 if (CBP.length != 0) {
nickjillings@2192 449 this.commentBoxPrefix = CBP[0].textContent;
nickjillings@2192 450 }
nickjillings@2192 451
nickjillings@2192 452 // Now decode the interfaces
nickjillings@2192 453 var interfaceNode = xml.getElementsByTagName('interface');
nickjillings@2192 454 for (var i=0; i<interfaceNode.length; i++)
nickjillings@2192 455 {
nickjillings@2192 456 var node = new parent.interfaceNode(this.specification);
nickjillings@2192 457 node.decode(this,interfaceNode[i],parent.schema.getAllElementsByName('interface')[1]);
nickjillings@2192 458 this.interfaces.push(node);
nickjillings@2192 459 }
nickjillings@2192 460
nickjillings@2192 461 // Now process the survey node options
nickjillings@2192 462 var survey = xml.getElementsByTagName('survey');
nickjillings@2192 463 var surveySchema = parent.schema.getAllElementsByName('survey')[0];
nickjillings@2192 464 for (var i in survey) {
nickjillings@2192 465 if (isNaN(Number(i)) == true){break;}
nickjillings@2192 466 var location = survey[i].getAttribute('location');
nickjillings@2192 467 if (location == 'pre' || location == 'before')
nickjillings@2192 468 {
nickjillings@2192 469 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
nickjillings@2192 470 else {
nickjillings@2192 471 this.preTest = new parent.surveyNode(this.specification);
nickjillings@2192 472 this.preTest.decode(parent,survey[i],surveySchema);
nickjillings@2192 473 }
nickjillings@2192 474 } else if (location == 'post' || location == 'after') {
nickjillings@2192 475 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
nickjillings@2192 476 else {
nickjillings@2192 477 this.postTest = new parent.surveyNode(this.specification);
nickjillings@2192 478 this.postTest.decode(parent,survey[i],surveySchema);
nickjillings@2192 479 }
nickjillings@2192 480 }
nickjillings@2192 481 }
nickjillings@2192 482
nickjillings@2192 483 // Now process the audioelement tags
nickjillings@2192 484 var audioElements = xml.getElementsByTagName('audioelement');
nickjillings@2192 485 for (var i=0; i<audioElements.length; i++)
nickjillings@2192 486 {
nickjillings@2192 487 var node = new this.audioElementNode(this.specification);
nickjillings@2192 488 node.decode(this,audioElements[i]);
nickjillings@2192 489 this.audioElements.push(node);
nickjillings@2192 490 }
nickjillings@2192 491
nickjillings@2192 492 // Now decode the commentquestions
nickjillings@2192 493 var commentQuestions = xml.getElementsByTagName('commentquestion');
nickjillings@2192 494 for (var i=0; i<commentQuestions.length; i++)
nickjillings@2192 495 {
nickjillings@2192 496 var node = new this.commentQuestionNode(this.specification);
nickjillings@2192 497 node.decode(parent,commentQuestions[i]);
nickjillings@2192 498 this.commentQuestions.push(node);
nickjillings@2192 499 }
nickjillings@2192 500 };
nickjillings@2192 501
nickjillings@2192 502 this.encode = function(root)
nickjillings@2192 503 {
nickjillings@2192 504 var AHNode = root.createElement("page");
nickjillings@2192 505 // First decode the attributes
nickjillings@2192 506 var attributes = this.schema.getAllElementsByTagName('xs:attribute');
nickjillings@2192 507 for (var i=0; i<attributes.length; i++)
nickjillings@2192 508 {
nickjillings@2192 509 var name = attributes[i].getAttribute("name");
nickjillings@2192 510 if (name == undefined) {
nickjillings@2192 511 name = attributes[i].getAttribute("ref");
nickjillings@2192 512 }
nickjillings@2192 513 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
nickjillings@2192 514 {
nickjillings@2192 515 eval("AHNode.setAttribute('"+name+"',this."+name+")");
nickjillings@2192 516 }
nickjillings@2192 517 }
nickjillings@2192 518 if(this.loudness != null) {AHNode.setAttribute("loudness",this.loudness);}
nickjillings@2192 519 // <commentboxprefix>
nickjillings@2192 520 var commentboxprefix = root.createElement("commentboxprefix");
nickjillings@2192 521 commentboxprefix.textContent = this.commentBoxPrefix;
nickjillings@2192 522 AHNode.appendChild(commentboxprefix);
nickjillings@2192 523
nickjillings@2192 524 for (var i=0; i<this.interfaces.length; i++)
nickjillings@2192 525 {
nickjillings@2192 526 AHNode.appendChild(this.interfaces[i].encode(root));
nickjillings@2192 527 }
nickjillings@2192 528
nickjillings@2192 529 for (var i=0; i<this.audioElements.length; i++) {
nickjillings@2192 530 AHNode.appendChild(this.audioElements[i].encode(root));
nickjillings@2192 531 }
nickjillings@2192 532 // Create <CommentQuestion>
nickjillings@2192 533 for (var i=0; i<this.commentQuestions.length; i++)
nickjillings@2192 534 {
nickjillings@2192 535 AHNode.appendChild(this.commentQuestions[i].encode(root));
nickjillings@2192 536 }
nickjillings@2192 537
nickjillings@2192 538 AHNode.appendChild(this.preTest.encode(root));
nickjillings@2192 539 AHNode.appendChild(this.postTest.encode(root));
nickjillings@2192 540 return AHNode;
nickjillings@2192 541 };
nickjillings@2192 542
nickjillings@2192 543 this.commentQuestionNode = function(specification) {
nickjillings@2192 544 this.id = null;
nickjillings@2192 545 this.name = undefined;
nickjillings@2192 546 this.type = undefined;
nickjillings@2192 547 this.options = [];
nickjillings@2192 548 this.statement = undefined;
nickjillings@2192 549 this.schema = specification.schema.getAllElementsByName('commentquestion')[0];
nickjillings@2192 550 this.decode = function(parent,xml)
nickjillings@2192 551 {
nickjillings@2192 552 this.id = xml.id;
nickjillings@2192 553 this.name = xml.getAttribute('name');
nickjillings@2192 554 this.type = xml.getAttribute('type');
nickjillings@2192 555 this.statement = xml.getElementsByTagName('statement')[0].textContent;
nickjillings@2192 556 var optNodes = xml.getElementsByTagName('option');
nickjillings@2192 557 for (var i=0; i<optNodes.length; i++)
nickjillings@2192 558 {
nickjillings@2192 559 var optNode = optNodes[i];
nickjillings@2192 560 this.options.push({
nickjillings@2192 561 name: optNode.getAttribute('name'),
nickjillings@2192 562 text: optNode.textContent
nickjillings@2192 563 });
nickjillings@2192 564 }
nickjillings@2192 565 };
nickjillings@2192 566
nickjillings@2192 567 this.encode = function(root)
nickjillings@2192 568 {
nickjillings@2192 569 var node = root.createElement("commentquestion");
nickjillings@2192 570 node.id = this.id;
nickjillings@2192 571 node.setAttribute("type",this.type);
nickjillings@2192 572 if (this.name != undefined){node.setAttribute("name",this.name);}
nickjillings@2192 573 var statement = root.createElement("statement");
nickjillings@2192 574 statement.textContent = this.statement;
nickjillings@2192 575 node.appendChild(statement);
nickjillings@2192 576 for (var option of this.options)
nickjillings@2192 577 {
nickjillings@2192 578 var child = root.createElement("option");
nickjillings@2192 579 child.setAttribute("name",option.name);
nickjillings@2192 580 child.textContent = option.text;
nickjillings@2192 581 node.appendChild(child);
nickjillings@2192 582 }
nickjillings@2192 583 return node;
nickjillings@2192 584 };
nickjillings@2192 585 };
nickjillings@2192 586
nickjillings@2192 587 this.audioElementNode = function(specification) {
nickjillings@2192 588 this.url = null;
nickjillings@2192 589 this.id = null;
nickjillings@2192 590 this.name = null;
nickjillings@2192 591 this.parent = null;
nickjillings@2192 592 this.type = null;
nickjillings@2192 593 this.marker = null;
nickjillings@2192 594 this.enforce = false;
nickjillings@2192 595 this.gain = 0.0;
nickjillings@2192 596 this.schema = specification.schema.getAllElementsByName('audioelement')[0];;
nickjillings@2192 597 this.parent = null;
nickjillings@2192 598 this.decode = function(parent,xml)
nickjillings@2192 599 {
nickjillings@2192 600 this.parent = parent;
nickjillings@2192 601 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
nickjillings@2192 602 for (var i=0; i<attributeMap.length; i++)
nickjillings@2192 603 {
nickjillings@2192 604 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
nickjillings@2192 605 var projectAttr = xml.getAttribute(attributeName);
nickjillings@2192 606 projectAttr = parent.parent.processAttribute(projectAttr,attributeMap[i],parent.parent.schema);
nickjillings@2192 607 switch(typeof projectAttr)
nickjillings@2192 608 {
nickjillings@2192 609 case "number":
nickjillings@2192 610 case "boolean":
nickjillings@2192 611 eval('this.'+attributeName+' = '+projectAttr);
nickjillings@2192 612 break;
nickjillings@2192 613 case "string":
nickjillings@2192 614 eval('this.'+attributeName+' = "'+projectAttr+'"');
nickjillings@2192 615 break;
nickjillings@2192 616 }
nickjillings@2192 617 }
nickjillings@2192 618
nickjillings@2192 619 };
nickjillings@2192 620 this.encode = function(root)
nickjillings@2192 621 {
nickjillings@2192 622 var AENode = root.createElement("audioelement");
nickjillings@2192 623 var attributes = this.schema.getAllElementsByTagName('xs:attribute');
nickjillings@2192 624 for (var i=0; i<attributes.length; i++)
nickjillings@2192 625 {
nickjillings@2192 626 var name = attributes[i].getAttribute("name");
nickjillings@2192 627 if (name == undefined) {
nickjillings@2192 628 name = attributes[i].getAttribute("ref");
nickjillings@2192 629 }
nickjillings@2192 630 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
nickjillings@2192 631 {
nickjillings@2192 632 eval("AENode.setAttribute('"+name+"',this."+name+")");
nickjillings@2192 633 }
nickjillings@2192 634 }
nickjillings@2192 635 return AENode;
nickjillings@2192 636 };
nickjillings@2192 637 };
nickjillings@2192 638 };
nickjillings@2192 639 }