Mercurial > hg > webaudioevaluationtool
comparison core.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 | d1c58546814c |
children |
comparison
equal
deleted
inserted
replaced
649:d1c58546814c | 650:ce3d4d6d01b8 |
---|---|
25 AudioBufferSourceNode.prototype.playbackStartTime = undefined; | 25 AudioBufferSourceNode.prototype.playbackStartTime = undefined; |
26 // Add a prototype to the bufferNode to hold the desired LINEAR gain | 26 // Add a prototype to the bufferNode to hold the desired LINEAR gain |
27 AudioBuffer.prototype.playbackGain = undefined; | 27 AudioBuffer.prototype.playbackGain = undefined; |
28 // Add a prototype to the bufferNode to hold the computed LUFS loudness | 28 // Add a prototype to the bufferNode to hold the computed LUFS loudness |
29 AudioBuffer.prototype.lufs = undefined; | 29 AudioBuffer.prototype.lufs = undefined; |
30 | |
31 // Convert relative URLs into absolutes | |
32 function escapeHTML(s) { | |
33 return s.split('&').join('&').split('<').join('<').split('"').join('"'); | |
34 } | |
35 function qualifyURL(url) { | |
36 var el= document.createElement('div'); | |
37 el.innerHTML= '<a href="'+escapeHTML(url)+'">x</a>'; | |
38 return el.firstChild.href; | |
39 } | |
30 | 40 |
31 // Firefox does not have an XMLDocument.prototype.getElementsByName | 41 // Firefox does not have an XMLDocument.prototype.getElementsByName |
32 // and there is no searchAll style command, this custom function will | 42 // and there is no searchAll style command, this custom function will |
33 // search all children recusrively for the name. Used for XSD where all | 43 // search all children recusrively for the name. Used for XSD where all |
34 // element nodes must have a name and therefore can pull the schema node | 44 // element nodes must have a name and therefore can pull the schema node |
1778 outputSequence.push(inputSequence.splice(r,1)[0]); | 1788 outputSequence.push(inputSequence.splice(r,1)[0]); |
1779 } | 1789 } |
1780 console.log(inputSequenceClone.toString()); // print original array to console | 1790 console.log(inputSequenceClone.toString()); // print original array to console |
1781 console.log(outputSequence.toString()); // print randomised array to console | 1791 console.log(outputSequence.toString()); // print randomised array to console |
1782 return holdArr; | 1792 return holdArr; |
1783 } | |
1784 | |
1785 function Specification() { | |
1786 // Handles the decoding of the project specification XML into a simple JavaScript Object. | |
1787 | |
1788 this.interface = null; | |
1789 this.projectReturn = "null"; | |
1790 this.randomiseOrder = null; | |
1791 this.testPages = null; | |
1792 this.pages = []; | |
1793 this.metrics = null; | |
1794 this.interfaces = null; | |
1795 this.loudness = null; | |
1796 this.errors = []; | |
1797 this.schema = null; | |
1798 this.exitText = "Thank you."; | |
1799 | |
1800 this.processAttribute = function(attribute,schema,schemaRoot) | |
1801 { | |
1802 // attribute is the string returned from getAttribute on the XML | |
1803 // schema is the <xs:attribute> node | |
1804 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined) | |
1805 { | |
1806 schema = schemaRoot.getAllElementsByName(schema.getAttribute('ref'))[0]; | |
1807 } | |
1808 var defaultOpt = schema.getAttribute('default'); | |
1809 if (attribute == null) { | |
1810 attribute = defaultOpt; | |
1811 } | |
1812 var dataType = schema.getAttribute('type'); | |
1813 if (typeof dataType == "string") { dataType = dataType.substr(3);} | |
1814 else {dataType = "string";} | |
1815 if (attribute == null) | |
1816 { | |
1817 return attribute; | |
1818 } | |
1819 switch(dataType) | |
1820 { | |
1821 case "boolean": | |
1822 if (attribute == 'true'){attribute = true;}else{attribute=false;} | |
1823 break; | |
1824 case "negativeInteger": | |
1825 case "positiveInteger": | |
1826 case "nonNegativeInteger": | |
1827 case "nonPositiveInteger": | |
1828 case "integer": | |
1829 case "decimal": | |
1830 case "short": | |
1831 attribute = Number(attribute); | |
1832 break; | |
1833 case "string": | |
1834 default: | |
1835 attribute = String(attribute); | |
1836 break; | |
1837 } | |
1838 return attribute; | |
1839 }; | |
1840 | |
1841 this.decode = function(projectXML) { | |
1842 this.errors = []; | |
1843 // projectXML - DOM Parsed document | |
1844 this.projectXML = projectXML.childNodes[0]; | |
1845 var setupNode = projectXML.getElementsByTagName('setup')[0]; | |
1846 var schemaSetup = this.schema.getAllElementsByName('setup')[0]; | |
1847 // First decode the attributes | |
1848 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute'); | |
1849 for (var i in attributes) | |
1850 { | |
1851 if (isNaN(Number(i)) == true){break;} | |
1852 var attributeName = attributes[i].getAttribute('name') || attributes[i].getAttribute('ref'); | |
1853 var projectAttr = setupNode.getAttribute(attributeName); | |
1854 projectAttr = this.processAttribute(projectAttr,attributes[i],this.schema); | |
1855 switch(typeof projectAttr) | |
1856 { | |
1857 case "number": | |
1858 case "boolean": | |
1859 eval('this.'+attributeName+' = '+projectAttr); | |
1860 break; | |
1861 case "string": | |
1862 eval('this.'+attributeName+' = "'+projectAttr+'"'); | |
1863 break; | |
1864 } | |
1865 | |
1866 } | |
1867 | |
1868 var exitTextNode = setupNode.getElementsByTagName('exitText'); | |
1869 if (exitTextNode.length == 1) { | |
1870 this.exitText = exitTextNode[0].textContent; | |
1871 } | |
1872 | |
1873 this.metrics = new this.metricNode(); | |
1874 | |
1875 this.metrics.decode(this,setupNode.getElementsByTagName('metric')[0]); | |
1876 | |
1877 // Now process the survey node options | |
1878 var survey = setupNode.getElementsByTagName('survey'); | |
1879 for (var i in survey) { | |
1880 if (isNaN(Number(i)) == true){break;} | |
1881 var location = survey[i].getAttribute('location'); | |
1882 if (location == 'pre' || location == 'before') | |
1883 { | |
1884 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");} | |
1885 else { | |
1886 this.preTest = new this.surveyNode(); | |
1887 this.preTest.decode(this,survey[i]); | |
1888 } | |
1889 } else if (location == 'post' || location == 'after') { | |
1890 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");} | |
1891 else { | |
1892 this.postTest = new this.surveyNode(); | |
1893 this.postTest.decode(this,survey[i]); | |
1894 } | |
1895 } | |
1896 } | |
1897 | |
1898 var interfaceNode = setupNode.getElementsByTagName('interface'); | |
1899 if (interfaceNode.length > 1) | |
1900 { | |
1901 this.errors.push("Only one <interface> node in the <setup> node allowed! Others except first ingnored!"); | |
1902 } | |
1903 this.interfaces = new this.interfaceNode(); | |
1904 if (interfaceNode.length != 0) | |
1905 { | |
1906 interfaceNode = interfaceNode[0]; | |
1907 this.interfaces.decode(this,interfaceNode,this.schema.getAllElementsByName('interface')[1]); | |
1908 } | |
1909 | |
1910 // Page tags | |
1911 var pageTags = projectXML.getElementsByTagName('page'); | |
1912 var pageSchema = this.schema.getAllElementsByName('page')[0]; | |
1913 for (var i=0; i<pageTags.length; i++) | |
1914 { | |
1915 var node = new this.page(); | |
1916 node.decode(this,pageTags[i],pageSchema); | |
1917 this.pages.push(node); | |
1918 } | |
1919 }; | |
1920 | |
1921 this.encode = function() | |
1922 { | |
1923 var RootDocument = document.implementation.createDocument(null,"waet"); | |
1924 var root = RootDocument.children[0]; | |
1925 root.setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance"); | |
1926 root.setAttribute("xsi:noNamespaceSchemaLocation","test-schema.xsd"); | |
1927 // Build setup node | |
1928 var setup = RootDocument.createElement("setup"); | |
1929 var schemaSetup = this.schema.getAllElementsByName('setup')[0]; | |
1930 // First decode the attributes | |
1931 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute'); | |
1932 for (var i=0; i<attributes.length; i++) | |
1933 { | |
1934 var name = attributes[i].getAttribute("name"); | |
1935 if (name == undefined) { | |
1936 name = attributes[i].getAttribute("ref"); | |
1937 } | |
1938 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required") | |
1939 { | |
1940 eval("setup.setAttribute('"+name+"',this."+name+")"); | |
1941 } | |
1942 } | |
1943 root.appendChild(setup); | |
1944 // Survey node | |
1945 if (this.exitText != null) { | |
1946 var exitTextNode = RootDocument.createElement('exitText'); | |
1947 exitTextNode.textContent = this.exitText; | |
1948 setup.appendChild(exitTextNode); | |
1949 } | |
1950 setup.appendChild(this.preTest.encode(RootDocument)); | |
1951 setup.appendChild(this.postTest.encode(RootDocument)); | |
1952 setup.appendChild(this.metrics.encode(RootDocument)); | |
1953 setup.appendChild(this.interfaces.encode(RootDocument)); | |
1954 for (var page of this.pages) | |
1955 { | |
1956 root.appendChild(page.encode(RootDocument)); | |
1957 } | |
1958 return RootDocument; | |
1959 }; | |
1960 | |
1961 this.surveyNode = function() { | |
1962 this.location = null; | |
1963 this.options = []; | |
1964 this.parent = null; | |
1965 this.schema = specification.schema.getAllElementsByName('survey')[0]; | |
1966 | |
1967 this.OptionNode = function() { | |
1968 this.type = undefined; | |
1969 this.schema = specification.schema.getAllElementsByName('surveyentry')[0]; | |
1970 this.id = undefined; | |
1971 this.name = undefined; | |
1972 this.mandatory = undefined; | |
1973 this.statement = undefined; | |
1974 this.boxsize = undefined; | |
1975 this.options = []; | |
1976 this.min = undefined; | |
1977 this.max = undefined; | |
1978 this.step = undefined; | |
1979 | |
1980 this.decode = function(parent,child) | |
1981 { | |
1982 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); | |
1983 for (var i in attributeMap){ | |
1984 if(isNaN(Number(i)) == true){break;} | |
1985 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); | |
1986 var projectAttr = child.getAttribute(attributeName); | |
1987 projectAttr = parent.processAttribute(projectAttr,attributeMap[i],parent.schema); | |
1988 switch(typeof projectAttr) | |
1989 { | |
1990 case "number": | |
1991 case "boolean": | |
1992 eval('this.'+attributeName+' = '+projectAttr); | |
1993 break; | |
1994 case "string": | |
1995 eval('this.'+attributeName+' = "'+projectAttr+'"'); | |
1996 break; | |
1997 } | |
1998 } | |
1999 this.statement = child.getElementsByTagName('statement')[0].textContent; | |
2000 if (this.type == "checkbox" || this.type == "radio") { | |
2001 var children = child.getElementsByTagName('option'); | |
2002 if (children.length == null) { | |
2003 console.log('Malformed' +child.nodeName+ 'entry'); | |
2004 this.statement = 'Malformed' +child.nodeName+ 'entry'; | |
2005 this.type = 'statement'; | |
2006 } else { | |
2007 this.options = []; | |
2008 for (var i in children) | |
2009 { | |
2010 if (isNaN(Number(i))==true){break;} | |
2011 this.options.push({ | |
2012 name: children[i].getAttribute('name'), | |
2013 text: children[i].textContent | |
2014 }); | |
2015 } | |
2016 } | |
2017 } | |
2018 }; | |
2019 | |
2020 this.exportXML = function(doc) | |
2021 { | |
2022 var node = doc.createElement('surveyentry'); | |
2023 node.setAttribute('type',this.type); | |
2024 var statement = doc.createElement('statement'); | |
2025 statement.textContent = this.statement; | |
2026 node.appendChild(statement); | |
2027 node.id = this.id; | |
2028 if (this.name != undefined) { node.setAttribute("name",this.name);} | |
2029 if (this.mandatory != undefined) { node.setAttribute("mandatory",this.mandatory);} | |
2030 node.id = this.id; | |
2031 if (this.name != undefined) {node.setAttribute("name",this.name);} | |
2032 switch(this.type) | |
2033 { | |
2034 case "checkbox": | |
2035 case "radio": | |
2036 for (var i=0; i<this.options.length; i++) | |
2037 { | |
2038 var option = this.options[i]; | |
2039 var optionNode = doc.createElement("option"); | |
2040 optionNode.setAttribute("name",option.name); | |
2041 optionNode.textContent = option.text; | |
2042 node.appendChild(optionNode); | |
2043 } | |
2044 case "number": | |
2045 if (this.min != undefined) {node.setAttribute("min", this.min);} | |
2046 if (this.max != undefined) {node.setAttribute("max", this.max);} | |
2047 case "question": | |
2048 if (this.boxsize != undefined) {node.setAttribute("boxsize",this.boxsize);} | |
2049 if (this.mandatory != undefined) {node.setAttribute("mandatory",this.mandatory);} | |
2050 default: | |
2051 break; | |
2052 } | |
2053 return node; | |
2054 }; | |
2055 }; | |
2056 this.decode = function(parent,xml) { | |
2057 this.parent = parent; | |
2058 this.location = xml.getAttribute('location'); | |
2059 if (this.location == 'before'){this.location = 'pre';} | |
2060 else if (this.location == 'after'){this.location = 'post';} | |
2061 for (var i in xml.children) | |
2062 { | |
2063 if(isNaN(Number(i))==true){break;} | |
2064 var node = new this.OptionNode(); | |
2065 node.decode(parent,xml.children[i]); | |
2066 this.options.push(node); | |
2067 } | |
2068 }; | |
2069 this.encode = function(doc) { | |
2070 var node = doc.createElement('survey'); | |
2071 node.setAttribute('location',this.location); | |
2072 for (var i=0; i<this.options.length; i++) | |
2073 { | |
2074 node.appendChild(this.options[i].exportXML(doc)); | |
2075 } | |
2076 return node; | |
2077 }; | |
2078 }; | |
2079 | |
2080 this.interfaceNode = function() | |
2081 { | |
2082 this.title = null; | |
2083 this.name = null; | |
2084 this.options = []; | |
2085 this.scales = []; | |
2086 this.schema = specification.schema.getAllElementsByName('interface')[1]; | |
2087 | |
2088 this.decode = function(parent,xml) { | |
2089 this.name = xml.getAttribute('name'); | |
2090 var titleNode = xml.getElementsByTagName('title'); | |
2091 if (titleNode.length == 1) | |
2092 { | |
2093 this.title = titleNode[0].textContent; | |
2094 } | |
2095 var interfaceOptionNodes = xml.getElementsByTagName('interfaceoption'); | |
2096 // Extract interfaceoption node schema | |
2097 var interfaceOptionNodeSchema = this.schema.getAllElementsByName('interfaceoption')[0]; | |
2098 var attributeMap = interfaceOptionNodeSchema.getAllElementsByTagName('xs:attribute'); | |
2099 for (var i=0; i<interfaceOptionNodes.length; i++) | |
2100 { | |
2101 var ioNode = interfaceOptionNodes[i]; | |
2102 var option = {}; | |
2103 for (var j=0; j<attributeMap.length; j++) | |
2104 { | |
2105 var attributeName = attributeMap[j].getAttribute('name') || attributeMap[j].getAttribute('ref'); | |
2106 var projectAttr = ioNode.getAttribute(attributeName); | |
2107 if(parent.processAttribute) { | |
2108 parent.processAttribute(projectAttr, attributeMap[j], parent.schema) | |
2109 } else { | |
2110 parent.parent.processAttribute(projectAttr, attributeMap[j], parent.parent.schema) | |
2111 } | |
2112 switch(typeof projectAttr) | |
2113 { | |
2114 case "number": | |
2115 case "boolean": | |
2116 eval('option.'+attributeName+' = '+projectAttr); | |
2117 break; | |
2118 case "string": | |
2119 eval('option.'+attributeName+' = "'+projectAttr+'"'); | |
2120 break; | |
2121 } | |
2122 } | |
2123 this.options.push(option); | |
2124 } | |
2125 | |
2126 // Now the scales nodes | |
2127 var scaleParent = xml.getElementsByTagName('scales'); | |
2128 if (scaleParent.length == 1) { | |
2129 scaleParent = scaleParent[0]; | |
2130 for (var i=0; i<scaleParent.children.length; i++) { | |
2131 var child = scaleParent.children[i]; | |
2132 this.scales.push({ | |
2133 text: child.textContent, | |
2134 position: Number(child.getAttribute('position')) | |
2135 }); | |
2136 } | |
2137 } | |
2138 }; | |
2139 | |
2140 this.encode = function(doc) { | |
2141 var node = doc.createElement("interface"); | |
2142 if (typeof name == "string") | |
2143 node.setAttribute("name",this.name); | |
2144 for (var option of this.options) | |
2145 { | |
2146 var child = doc.createElement("interfaceoption"); | |
2147 child.setAttribute("type",option.type); | |
2148 child.setAttribute("name",option.name); | |
2149 node.appendChild(child); | |
2150 } | |
2151 if (this.scales.length != 0) { | |
2152 var scales = doc.createElement("scales"); | |
2153 for (var scale of this.scales) | |
2154 { | |
2155 var child = doc.createElement("scalelabel"); | |
2156 child.setAttribute("position",scale.position); | |
2157 child.textContent = scale.text; | |
2158 scales.appendChild(child); | |
2159 } | |
2160 node.appendChild(scales); | |
2161 } | |
2162 return node; | |
2163 }; | |
2164 }; | |
2165 | |
2166 this.metricNode = function() { | |
2167 this.enabled = []; | |
2168 this.decode = function(parent, xml) { | |
2169 var children = xml.getElementsByTagName('metricenable'); | |
2170 for (var i in children) { | |
2171 if (isNaN(Number(i)) == true){break;} | |
2172 this.enabled.push(children[i].textContent); | |
2173 } | |
2174 } | |
2175 this.encode = function(doc) { | |
2176 var node = doc.createElement('metric'); | |
2177 for (var i in this.enabled) | |
2178 { | |
2179 if (isNaN(Number(i)) == true){break;} | |
2180 var child = doc.createElement('metricenable'); | |
2181 child.textContent = this.enabled[i]; | |
2182 node.appendChild(child); | |
2183 } | |
2184 return node; | |
2185 } | |
2186 } | |
2187 | |
2188 this.page = function() { | |
2189 this.presentedId = undefined; | |
2190 this.id = undefined; | |
2191 this.hostURL = undefined; | |
2192 this.randomiseOrder = undefined; | |
2193 this.loop = undefined; | |
2194 this.showElementComments = undefined; | |
2195 this.outsideReference = null; | |
2196 this.loudness = null; | |
2197 this.label = null; | |
2198 this.preTest = null; | |
2199 this.postTest = null; | |
2200 this.interfaces = []; | |
2201 this.commentBoxPrefix = "Comment on track"; | |
2202 this.audioElements = []; | |
2203 this.commentQuestions = []; | |
2204 this.schema = specification.schema.getAllElementsByName("page")[0]; | |
2205 this.parent = null; | |
2206 | |
2207 this.decode = function(parent,xml) | |
2208 { | |
2209 this.parent = parent; | |
2210 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); | |
2211 for (var i=0; i<attributeMap.length; i++) | |
2212 { | |
2213 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); | |
2214 var projectAttr = xml.getAttribute(attributeName); | |
2215 projectAttr = parent.processAttribute(projectAttr,attributeMap[i],parent.schema); | |
2216 switch(typeof projectAttr) | |
2217 { | |
2218 case "number": | |
2219 case "boolean": | |
2220 eval('this.'+attributeName+' = '+projectAttr); | |
2221 break; | |
2222 case "string": | |
2223 eval('this.'+attributeName+' = "'+projectAttr+'"'); | |
2224 break; | |
2225 } | |
2226 } | |
2227 | |
2228 // Get the Comment Box Prefix | |
2229 var CBP = xml.getElementsByTagName('commentboxprefix'); | |
2230 if (CBP.length != 0) { | |
2231 this.commentBoxPrefix = CBP[0].textContent; | |
2232 } | |
2233 | |
2234 // Now decode the interfaces | |
2235 var interfaceNode = xml.getElementsByTagName('interface'); | |
2236 for (var i=0; i<interfaceNode.length; i++) | |
2237 { | |
2238 var node = new parent.interfaceNode(); | |
2239 node.decode(this,interfaceNode[i],parent.schema.getAllElementsByName('interface')[1]); | |
2240 this.interfaces.push(node); | |
2241 } | |
2242 | |
2243 // Now process the survey node options | |
2244 var survey = xml.getElementsByTagName('survey'); | |
2245 var surveySchema = parent.schema.getAllElementsByName('survey')[0]; | |
2246 for (var i in survey) { | |
2247 if (isNaN(Number(i)) == true){break;} | |
2248 var location = survey[i].getAttribute('location'); | |
2249 if (location == 'pre' || location == 'before') | |
2250 { | |
2251 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");} | |
2252 else { | |
2253 this.preTest = new parent.surveyNode(); | |
2254 this.preTest.decode(parent,survey[i],surveySchema); | |
2255 } | |
2256 } else if (location == 'post' || location == 'after') { | |
2257 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");} | |
2258 else { | |
2259 this.postTest = new parent.surveyNode(); | |
2260 this.postTest.decode(parent,survey[i],surveySchema); | |
2261 } | |
2262 } | |
2263 } | |
2264 | |
2265 // Now process the audioelement tags | |
2266 var audioElements = xml.getElementsByTagName('audioelement'); | |
2267 for (var i=0; i<audioElements.length; i++) | |
2268 { | |
2269 var node = new this.audioElementNode(); | |
2270 node.decode(this,audioElements[i]); | |
2271 this.audioElements.push(node); | |
2272 } | |
2273 | |
2274 // Now decode the commentquestions | |
2275 var commentQuestions = xml.getElementsByTagName('commentquestion'); | |
2276 for (var i=0; i<commentQuestions.length; i++) | |
2277 { | |
2278 var node = new this.commentQuestionNode(); | |
2279 node.decode(parent,commentQuestions[i]); | |
2280 this.commentQuestions.push(node); | |
2281 } | |
2282 }; | |
2283 | |
2284 this.encode = function(root) | |
2285 { | |
2286 var AHNode = root.createElement("page"); | |
2287 // First decode the attributes | |
2288 var attributes = this.schema.getAllElementsByTagName('xs:attribute'); | |
2289 for (var i=0; i<attributes.length; i++) | |
2290 { | |
2291 var name = attributes[i].getAttribute("name"); | |
2292 if (name == undefined) { | |
2293 name = attributes[i].getAttribute("ref"); | |
2294 } | |
2295 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required") | |
2296 { | |
2297 eval("AHNode.setAttribute('"+name+"',this."+name+")"); | |
2298 } | |
2299 } | |
2300 if(this.loudness != null) {AHNode.setAttribute("loudness",this.loudness);} | |
2301 // <commentboxprefix> | |
2302 var commentboxprefix = root.createElement("commentboxprefix"); | |
2303 commentboxprefix.textContent = this.commentBoxPrefix; | |
2304 AHNode.appendChild(commentboxprefix); | |
2305 | |
2306 for (var i=0; i<this.interfaces.length; i++) | |
2307 { | |
2308 AHNode.appendChild(this.interfaces[i].encode(root)); | |
2309 } | |
2310 | |
2311 for (var i=0; i<this.audioElements.length; i++) { | |
2312 AHNode.appendChild(this.audioElements[i].encode(root)); | |
2313 } | |
2314 // Create <CommentQuestion> | |
2315 for (var i=0; i<this.commentQuestions.length; i++) | |
2316 { | |
2317 AHNode.appendChild(this.commentQuestions[i].encode(root)); | |
2318 } | |
2319 | |
2320 AHNode.appendChild(this.preTest.encode(root)); | |
2321 AHNode.appendChild(this.postTest.encode(root)); | |
2322 return AHNode; | |
2323 }; | |
2324 | |
2325 this.commentQuestionNode = function() { | |
2326 this.id = null; | |
2327 this.name = undefined; | |
2328 this.type = undefined; | |
2329 this.options = []; | |
2330 this.statement = undefined; | |
2331 this.schema = specification.schema.getAllElementsByName('commentquestion')[0]; | |
2332 this.decode = function(parent,xml) | |
2333 { | |
2334 this.id = xml.id; | |
2335 this.name = xml.getAttribute('name'); | |
2336 this.type = xml.getAttribute('type'); | |
2337 this.statement = xml.getElementsByTagName('statement')[0].textContent; | |
2338 var optNodes = xml.getElementsByTagName('option'); | |
2339 for (var i=0; i<optNodes.length; i++) | |
2340 { | |
2341 var optNode = optNodes[i]; | |
2342 this.options.push({ | |
2343 name: optNode.getAttribute('name'), | |
2344 text: optNode.textContent | |
2345 }); | |
2346 } | |
2347 }; | |
2348 | |
2349 this.encode = function(root) | |
2350 { | |
2351 var node = root.createElement("commentquestion"); | |
2352 node.id = this.id; | |
2353 node.setAttribute("type",this.type); | |
2354 if (this.name != undefined){node.setAttribute("name",this.name);} | |
2355 var statement = root.createElement("statement"); | |
2356 statement.textContent = this.statement; | |
2357 node.appendChild(statement); | |
2358 for (var option of this.options) | |
2359 { | |
2360 var child = root.createElement("option"); | |
2361 child.setAttribute("name",option.name); | |
2362 child.textContent = option.text; | |
2363 node.appendChild(child); | |
2364 } | |
2365 return node; | |
2366 }; | |
2367 }; | |
2368 | |
2369 this.audioElementNode = function() { | |
2370 this.url = null; | |
2371 this.id = null; | |
2372 this.name = null; | |
2373 this.parent = null; | |
2374 this.type = null; | |
2375 this.marker = null; | |
2376 this.enforce = false; | |
2377 this.gain = 0.0; | |
2378 this.schema = specification.schema.getAllElementsByName('audioelement')[0];; | |
2379 this.parent = null; | |
2380 this.decode = function(parent,xml) | |
2381 { | |
2382 this.parent = parent; | |
2383 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); | |
2384 for (var i=0; i<attributeMap.length; i++) | |
2385 { | |
2386 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); | |
2387 var projectAttr = xml.getAttribute(attributeName); | |
2388 projectAttr = parent.parent.processAttribute(projectAttr,attributeMap[i],parent.parent.schema); | |
2389 switch(typeof projectAttr) | |
2390 { | |
2391 case "number": | |
2392 case "boolean": | |
2393 eval('this.'+attributeName+' = '+projectAttr); | |
2394 break; | |
2395 case "string": | |
2396 eval('this.'+attributeName+' = "'+projectAttr+'"'); | |
2397 break; | |
2398 } | |
2399 } | |
2400 | |
2401 }; | |
2402 this.encode = function(root) | |
2403 { | |
2404 var AENode = root.createElement("audioelement"); | |
2405 var attributes = this.schema.getAllElementsByTagName('xs:attribute'); | |
2406 for (var i=0; i<attributes.length; i++) | |
2407 { | |
2408 var name = attributes[i].getAttribute("name"); | |
2409 if (name == undefined) { | |
2410 name = attributes[i].getAttribute("ref"); | |
2411 } | |
2412 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required") | |
2413 { | |
2414 eval("AENode.setAttribute('"+name+"',this."+name+")"); | |
2415 } | |
2416 } | |
2417 return AENode; | |
2418 }; | |
2419 }; | |
2420 }; | |
2421 } | 1793 } |
2422 | 1794 |
2423 function Interface(specificationObject) { | 1795 function Interface(specificationObject) { |
2424 // This handles the bindings between the interface and the audioEngineContext; | 1796 // This handles the bindings between the interface and the audioEngineContext; |
2425 this.specification = specificationObject; | 1797 this.specification = specificationObject; |
3354 this.SessionKey.generateKey(); | 2726 this.SessionKey.generateKey(); |
3355 this.document = document.implementation.createDocument(null,"waetresult"); | 2727 this.document = document.implementation.createDocument(null,"waetresult"); |
3356 this.root = this.document.childNodes[0]; | 2728 this.root = this.document.childNodes[0]; |
3357 var projectDocument = specification.projectXML; | 2729 var projectDocument = specification.projectXML; |
3358 projectDocument.setAttribute('file-name',url); | 2730 projectDocument.setAttribute('file-name',url); |
2731 projectDocument.setAttribute('url',qualifyURL(url)); | |
3359 this.root.appendChild(projectDocument); | 2732 this.root.appendChild(projectDocument); |
3360 this.root.appendChild(interfaceContext.returnDateNode()); | 2733 this.root.appendChild(interfaceContext.returnDateNode()); |
3361 this.root.appendChild(interfaceContext.returnNavigator()); | 2734 this.root.appendChild(interfaceContext.returnNavigator()); |
3362 } else { | 2735 } else { |
3363 this.document = existingStore; | 2736 this.document = existingStore; |
3514 var aeNode = this.parent.document.createElement('audioelement'); | 2887 var aeNode = this.parent.document.createElement('audioelement'); |
3515 aeNode.setAttribute('ref',element.id); | 2888 aeNode.setAttribute('ref',element.id); |
3516 if (element.name != undefined){aeNode.setAttribute('name',element.name)}; | 2889 if (element.name != undefined){aeNode.setAttribute('name',element.name)}; |
3517 aeNode.setAttribute('type',element.type); | 2890 aeNode.setAttribute('type',element.type); |
3518 aeNode.setAttribute('url', element.url); | 2891 aeNode.setAttribute('url', element.url); |
2892 aeNode.setAttribute('fqurl',qualifyURL(element.url)); | |
3519 aeNode.setAttribute('gain', element.gain); | 2893 aeNode.setAttribute('gain', element.gain); |
3520 if (element.type == 'anchor' || element.type == 'reference') | 2894 if (element.type == 'anchor' || element.type == 'reference') |
3521 { | 2895 { |
3522 if (element.marker > 0) | 2896 if (element.marker > 0) |
3523 { | 2897 { |