Author: jbeard Date: Sat Jun 19 19:43:00 2010 New Revision: 956274 URL: http://svn.apache.org/viewvc?rev=956274&view=rev Log: Unit tests pass with Rhino.
Added: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/util/xml.js (with props) Modified: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/build.js 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/src/javascript/scxml/cgf/main.js Modified: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/build.js URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/build.js?rev=956274&r1=956273&r2=956274&view=diff ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/build.js (original) +++ commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/build.js Sat Jun 19 19:43:00 2010 @@ -21,11 +21,12 @@ require.def("build", "src/javascript/scxml/cgf/util/file", "src/javascript/scxml/cgf/SCXMLCompiler", "src/javascript/scxml/cgf/PerformanceAnalyzer", + "src/javascript/scxml/cgf/util/xml", "test/testHelpers.js", "lib/js/json2.js", "lib/test-js/env.js", "lib/test-js/dojo-release-1.4.2-src/dojo/dojo.js"], - function(util,utilFile,SCXMLCompiler,PerformanceAnalyzer){ + function(util,utilFile,SCXMLCompiler,PerformanceAnalyzer,xmlUtil){ return function(args){ @@ -198,7 +199,7 @@ require.def("build", var sc,fpath,label,name; sc = SCXMLCompiler.compile({ - inFiles:[pathToTest], + inFiles:[pathToTest].map(xmlUtil.parseFromPath), backend:backend, beautify:true, verbose:false, @@ -228,7 +229,7 @@ require.def("build", //compile with nomap and noforeach sc = SCXMLCompiler.compile({ - inFiles:[pathToTest], + inFiles:[pathToTest].map(xmlUtil.parseFromPath), backend:backend, beautify:true, verbose:false, 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=956274&r1=956273&r2=956274&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 19:43:00 2010 @@ -80,6 +80,7 @@ }; }else{ //FIXME: this is actually a rhino-specific API, so maybe we should switch on something like isRhino, rather than isBrowser + //FIXME: use the xmlutil api var File = java.io.File; var DocumentBuilderFactory = javax.xml.parsers.DocumentBuilderFactory; var dbf = DocumentBuilderFactory.newInstance(); Modified: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/main.js URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/main.js?rev=956274&r1=956273&r2=956274&view=diff ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/main.js (original) +++ commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/main.js Sat Jun 19 19:43:00 2010 @@ -35,8 +35,9 @@ It accepts command-line arguments, and c require.def("src/javascript/scxml/cgf/main", ["src/javascript/scxml/cgf/SCXMLCompiler", - "src/javascript/scxml/cgf/util/commandLine"], - function(SCXMLCompiler,cmdLineUtil){ + "src/javascript/scxml/cgf/util/commandLine", + "src/javascript/scxml/cgf/util/xml"], + function(SCXMLCompiler,cmdLineUtil,xmlUtil){ function parseXMLFromPath(path){ var file = new java.io.File(path); @@ -62,7 +63,7 @@ require.def("src/javascript/scxml/cgf/ma } var parsedOptionsMap = cmdLineUtil.parseCommandLine(optionsMap,args); - parsedOptionsMap.inFiles = parsedOptionsMap.args.map(parseXMLFromPath); + parsedOptionsMap.inFiles = parsedOptionsMap.args.map(xmlUtil.parseFromString); delete parsedOptionsMap.args; //TODO: parse paths in inFiles into documents Added: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/util/xml.js URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/util/xml.js?rev=956274&view=auto ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/util/xml.js (added) +++ commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/util/xml.js Sat Jun 19 19:43:00 2010 @@ -0,0 +1,89 @@ +require.def("src/javascript/scxml/cgf/util/xml", +function(){ + + var serializeToString = !require.isBrowser ? + //assume Rhino + (function(){ + var ByteArrayOutputStream = java.io.ByteArrayOutputStream; + + var xmlProps = Packages.org.apache.xml.serializer.OutputPropertiesFactory + .getDefaultMethodProperties("xml"); + xmlProps.setProperty("indent", "yes"); + xmlProps.setProperty("standalone", "no"); + + var serializer = Packages.org.apache.xml.serializer.SerializerFactory.getSerializer(xmlProps); + + return function(d){ + var baos = new ByteArrayOutputStream(); + var serializer = new Packages.org.apache.xml.serialize.XMLSerializer( + baos, + new Packages.org.apache.xml.serialize.OutputFormat); + + serializer.setOutputStream(baos); + serializer.asDOMSerializer().serialize(d); + + var toReturn = String(new java.lang.String(baos.toByteArray())); + return toReturn; + } + })() : + window.XMLSerializer ? + (function(){ + var s = new XMLSerializer(); + return function(d){ + str = s.serializeToString(d); + return str; + } + })() : + function(d){ + return d.xml; + }; + + var parseFromString = !require.isBrowser ? + //assume Rhino + function(){ + //I think this would use DocumentBuilderFactory + new Error("No implementation for parseFromString."); + } : + window.DOMParser ? + (function(){ + var parser = new DOMParser(); + return function(str){ + var doc = parser.parseFromString(str); + return doc; + } + })() : + function(str){ + var xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); + xmlDoc.async="false"; + xmlDoc.loadXML(str); + + return xmlDoc; + }; + + var parseFromPath = !require.browser ? + (function(){ + var File = java.io.File; + var DocumentBuilderFactory = javax.xml.parsers.DocumentBuilderFactory; + var dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + + return function (path) { + + var file = new File(path); + var db = dbf.newDocumentBuilder(); + var doc = db.parse(file); + return doc; + }; + })() : + function(){ + new Error("No implementation for parseFromPath.") + } + + return { + parseFromString : parseFromString, + serializeToString : serializeToString, + parseFromPath : parseFromPath + } +}) + + Propchange: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/util/xml.js ------------------------------------------------------------------------------ svn:eol-style = native