annotate specification.js @ 2202:61c8e13f1e2e

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