annotate specification.js @ 650:ce3d4d6d01b8 Dev_main

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