Author: jbeard Date: Sat Jun 19 05:56:35 2010 New Revision: 956186 URL: http://svn.apache.org/viewvc?rev=956186&view=rev Log: Working on creating a unified front-end that works for Rhino and all browsers. Currently works for all browsers; still working on Rhino.
Modified: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/lib/js/requirejs/require/xml.js commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/runner.js commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/SCXMLCompiler.js commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/test/testBrowserTransform.html Modified: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/lib/js/requirejs/require/xml.js URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/lib/js/requirejs/require/xml.js?rev=956186&r1=956185&r2=956186&view=diff ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/lib/js/requirejs/require/xml.js (original) +++ commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/lib/js/requirejs/require/xml.js Sat Jun 19 05:56:35 2010 @@ -63,7 +63,7 @@ return xhr; }; } - + if (!require.fetchText) { if(require.isBrowser){ require.fetchText = function (url, callback) { @@ -80,8 +80,17 @@ }; }else{ //FIXME: this is actually a rhino-specific API, so maybe we should switch on something like isRhino, rather than isBrowser + var File = java.io.File; + var DocumentBuilderFactory = javax.xml.parsers.DocumentBuilderFactory; + require.fetchText = function (url, callback) { - callback(readFile(url)); + + var file = new File(url); + var dbf = DocumentBuilderFactory.newInstance(); + var db = dbf.newDocumentBuilder(); + var doc = db.parse(file); + + callback(doc); }; } } Modified: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/runner.js URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/runner.js?rev=956186&r1=956185&r2=956186&view=diff ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/runner.js (original) +++ commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/runner.js Sat Jun 19 05:56:35 2010 @@ -75,6 +75,7 @@ if(arguments.length){ load(pathToRequireJsDir + "require.js"); load(pathToRequireJsDir + "require/rhino.js"); load(pathToRequireJsDir + "require/text.js"); + load(pathToRequireJsDir + "require/xml.js"); //bootstrap require.js require({ Modified: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/SCXMLCompiler.js URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/SCXMLCompiler.js?rev=956186&r1=956185&r2=956186&view=diff ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/SCXMLCompiler.js (original) +++ commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/SCXMLCompiler.js Sat Jun 19 05:56:35 2010 @@ -27,22 +27,18 @@ code. require.def("src/javascript/scxml/cgf/SCXMLCompiler", - ["lib/js/beautify.js"], + //TODO: conditional require + [ + "src/javascript/scxml/cgf/backends/js/StatePatternStatechartGenerator", + "src/javascript/scxml/cgf/Transformer", + "src/javascript/scxml/cgf/util/base", + "/lib/js/beautify.js"], - function(){ - - //import packages - importPackage(javax.xml.transform.dom); - importPackage(javax.xml.transform); - importPackage(javax.xml.transform.stream); - importPackage(javax.xml.transform.sax); - importPackage(Packages.org.apache.xml.serializer); - importPackage(Packages.org.xml.sax); - importPackage(Packages.org.xml.sax.helpers); - - //importPackage(Packages.org.apache.commons.io); - importClass(java.io.ByteArrayOutputStream); - importClass(java.io.StringReader); + function( + StatePatternStatechartGenerator, + Transformer, + base + ){ /* supported options: @@ -58,93 +54,14 @@ require.def("src/javascript/scxml/cgf/SC function compile(options){ if(!options.inFiles) return false; - - var baseIRFilters = ["src/xslt/ir-compiler/enumerateEvents", - "src/xslt/ir-compiler/normalizeInitialStates", - "src/xslt/ir-compiler/generateUniqueStateIds", - "src/xslt/ir-compiler/generateUniqueInitialStateIds", - "src/xslt/ir-compiler/splitTransitionTargets", - "src/xslt/ir-compiler/changeTransitionsPointingToCompoundStatesToPointToInitialStates", - "src/xslt/ir-compiler/computeLCA", - "src/xslt/ir-compiler/transformIf", - "src/xslt/ir-compiler/appendStateInformation", - "src/xslt/ir-compiler/appendBasicStateInformation"]; - - var enumeratedIRFilters = baseIRFilters.concat([ "src/xslt/ir-compiler/flattenTransitions", - "src/xslt/ir-compiler/nameTransitions", - "src/xslt/ir-compiler/numberStatesAndTransitions" ]); - - - var irFiltersXsl, codeGeneratorXsl; - - switch(options.backend){ - case "switch": - irFiltersXsl = enumeratedIRFilters; - codeGeneratorXsl = "src/xslt/backends/js/SwitchyardStatechartGenerator"; - break; - case "table": - irFiltersXsl = enumeratedIRFilters; - codeGeneratorXsl = "src/xslt/backends/js/StateTableStatechartGenerator"; - break; - case "state": - irFiltersXsl = baseIRFilters; - codeGeneratorXsl = "src/xslt/backends/js/StatePatternStatechartGenerator"; - break; - } - - var allFilters = irFiltersXsl - .concat("src/xslt/ir-compiler/appendTransitionInformation") - .concat(codeGeneratorXsl); - - //do transforms - var tFactory = TransformerFactory.newInstance(); - - //FIXME: I think require.nameToUrl is not supposed to be a public API, even though it should be... - var filterList = allFilters.map(function(modulePathToXsl){ - return tFactory.newTransformerHandler( - new StreamSource( - require.nameToUrl(modulePathToXsl,".xsl","_"))); - }); - - var reader = XMLReaderFactory.createXMLReader(); - - for(var i = 1; i < filterList.length; i++){ - var result = new SAXResult(filterList[i]); - filterList[i-1].setResult(result); - } - - var firstFilter = filterList[0]; - var lastFilter = filterList[filterList.length-1]; - var toReturn = options.inFiles.map(function(xmlFile){ if(options.ie){ options.noMap = options.noForEach = options.noIndexOf = true; } - var baos = new ByteArrayOutputStream(); - - lastFilter.setResult(new StreamResult(baos)); - - var lastFilterTransformer = lastFilter.getTransformer(); - for(optName in options){ - lastFilterTransformer.setParameter(optName,options[optName]); - } - - // Set up the transformer to process the SAX events generated by the last filter in the chain - var factory= javax.xml.parsers.SAXParserFactory.newInstance(); - factory.setNamespaceAware( true ); - var jaxpParser= factory.newSAXParser(); - var reader=jaxpParser.getXMLReader()// || XMLReaderFactory.createXMLReader(); - - reader.setContentHandler(firstFilter); - - // Parse the source XML, and send the parse events to the - // TransformerHandler. - reader.parse(xmlFile); - - //get transformed output - var transformedJs = String(new java.lang.String(baos.toByteArray())); + var ir = Transformer(xmlFile,StatePatternStatechartGenerator.transformations,null,"xml"); + var transformedJs = Transformer(ir,StatePatternStatechartGenerator.code,options,"text"); //optionally beautify it if(options.beautify){ Modified: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/test/testBrowserTransform.html URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/test/testBrowserTransform.html?rev=956186&r1=956185&r2=956186&view=diff ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/test/testBrowserTransform.html (original) +++ commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/test/testBrowserTransform.html Sat Jun 19 05:56:35 2010 @@ -24,27 +24,31 @@ { "baseUrl":"/" }, - [ "test/SCXMLCompiler"], + [ "src/javascript/scxml/cgf/SCXMLCompiler"], function(compiler){ var compileLog = true; var backend = "state"; - var transformedJs = compiler.compile({ - //inFiles:[pathToTest], - backend:backend, - beautify:true, - verbose:false, - log:compileLog, - ie:false - }); + doXHR("http://localhost:8081/test/kitchen_sink/KitchenSink_executableContent.xml", + function(KitchenSink_executableContent){ - console.log(transformedJs); + var transformedJs = compiler.compile({ + inFiles:[KitchenSink_executableContent], + backend:backend, + beautify:true, + verbose:false, + log:compileLog, + ie:false + }); - //eval - eval(transformedJs); - window.StatechartExecutionContext = StatechartExecutionContext; - dojo.require("doh.runner"); - doh.run(); + console.log(transformedJs); + + //eval + eval(transformedJs); + window.StatechartExecutionContext = StatechartExecutionContext; + dojo.require("doh.runner"); + doh.run(); + }); } );