commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbe...@apache.org
Subject svn commit: r978787 - in /commons/sandbox/gsoc/2010/scxml-js/trunk: ./ demo/drag-and-drop/ demo/sandbox/ src/javascript/scxml/cgf/ src/javascript/scxml/cgf/util/ src/javascript/scxml/cgf/util/xml/ src/javascript/scxml/cgf/util/xsl/ test/
Date Sat, 24 Jul 2010 03:44:06 GMT
Author: jbeard
Date: Sat Jul 24 03:44:06 2010
New Revision: 978787

URL: http://svn.apache.org/viewvc?rev=978787&view=rev
Log:
Refactored stuff to use dependency injection.

Added:
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/browser.js
  (with props)
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/ie.js   (with
props)
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/rhino.js  
(with props)
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/browser.js
  (with props)
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/ie.js   (with
props)
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/rhino.js  
(with props)
Removed:
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/Transformer.js
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml.js
Modified:
    commons/sandbox/gsoc/2010/scxml-js/trunk/build.js
    commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drag-and-drop/drag-and-drop.xhtml
    commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drag-and-drop/drag-and-drop2.xhtml
    commons/sandbox/gsoc/2010/scxml-js/trunk/demo/sandbox/sandbox.html
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/SCXMLCompiler.js
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/main.js
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/SCXMLCompiler.js
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/testBrowserTransform.html

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/build.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/build.js?rev=978787&r1=978786&r2=978787&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/build.js (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/build.js Sat Jul 24 03:44:06 2010
@@ -21,8 +21,8 @@ require.def("build",
 		"src/javascript/scxml/cgf/util/file",	
 		"src/javascript/scxml/cgf/SCXMLCompiler",
 		"src/javascript/scxml/cgf/PerformanceAnalyzer",
-		"src/javascript/scxml/cgf/Transformer",
-		"src/javascript/scxml/cgf/util/xml",
+		"src/javascript/scxml/cgf/util/xsl/rhino",
+		"src/javascript/scxml/cgf/util/xml/rhino",
 		"test/testHelpers.js",
 		"lib/js/json2.js",
 		"lib/test-js/env.js",
@@ -316,10 +316,8 @@ require.def("build",
 
 											//recursive callback
 											step();
-										}
-									)
-								}
-							)
+										}, Transformer)
+								}, Transformer)
 						},
 						compilerCallback);
 
@@ -858,29 +856,36 @@ require.def("build",
 							[ "src/javascript/scxml/cgf/SCXMLCompiler",
 								"xml!{modulePathToXMLTest}",
 								"{testScriptModulePath}"],
-							function(compiler,KitchenSink_executableContent,testScriptModule){
-								var compileLog = true;
-
-								compiler.compile({
-									inFiles:[KitchenSink_executableContent],
-									backend:"{backendName}",
-									beautify:true,
-									verbose:false,
-									log:compileLog,
-									ie:{isIE}
-								}, function(scArr){
-									var transformedJs = scArr[0];
 
-									console.log(transformedJs);
-
-									//eval
-									eval(transformedJs);
-
-									testScriptModule.register(StatechartExecutionContext);
-
-									dojo.require("doh.runner"); 
-									doh.run();
-								});
+							require( [window.DOMParser ?
+									"src/javascript/scxml/cgf/util/xsl/browser" :
+									"src/javascript/scxml/cgf/util/xsl/ie"],
+								function(transform){
+
+								function(compiler,KitchenSink_executableContent,testScriptModule){
+									var compileLog = true;
+
+									compiler.compile({
+										inFiles:[KitchenSink_executableContent],
+										backend:"{backendName}",
+										beautify:true,
+										verbose:false,
+										log:compileLog,
+										ie:{isIE}
+									}, function(scArr){
+										var transformedJs = scArr[0];
+
+										console.log(transformedJs);
+
+										//eval
+										eval(transformedJs);
+
+										testScriptModule.register(StatechartExecutionContext);
+
+										dojo.require("doh.runner"); 
+										doh.run();
+									},transform);
+								}
 							}
 						);
 

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drag-and-drop/drag-and-drop.xhtml
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drag-and-drop/drag-and-drop.xhtml?rev=978787&r1=978786&r2=978787&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drag-and-drop/drag-and-drop.xhtml (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drag-and-drop/drag-and-drop.xhtml Sat Jul
24 03:44:06 2010
@@ -125,55 +125,62 @@ using SCXML: 
 
 				function(compiler){
 
-					var statusDiv = document.getElementById("statusDiv");
-
-					statusDiv.textContent="Compiling SCXML elements...";
-
-					//pull SCXML nodes from DOM
-					var scxmlElements = document.getElementsByTagName("scxml");
-					for(var i = 0; i < scxmlElements.length; i++){
-						var scxml_input = scxmlElements[i];
-						var domNodeToHookUp = scxml_input.parentNode;
-
-						//prep scxml document to transform by pulling the scxml node into its own document
-						var scxmlns = "http://www.w3.org/2005/07/scxml";
-						var scxmlToTransform = document.implementation.createDocument (scxmlns , "scxml", null);
-						var newNode = scxmlToTransform.importNode(scxml_input.cloneNode(true),true);
-						scxmlToTransform.replaceChild(newNode,scxmlToTransform.documentElement);
-
-						var compiledStatechartConstructor, compiledStatechartInstance; 
-
-						compiler.compile({
-							inFiles:[scxmlToTransform],
-							//debug:true,
-							backend:"state",
-							beautify:true,
-							verbose:false,
-							log:false,
-							ie:false
-						}, function(scArr){
-							var transformedJs = scArr[0];
-
-							//eval
-							console.log(transformedJs);
-							eval(transformedJs);
-							compiledStatechartConstructor = StatechartExecutionContext;
-							compiledStatechartInstance = new compiledStatechartConstructor(); 
-
-							//initialize
-							compiledStatechartInstance.initialize();
-							
-							//pass in reference to rect
-							compiledStatechartInstance.init({rawNode:domNodeToHookUp}); 
-
-							//hook up DOM events
-							["mousedown","mouseup","mousemove"].forEach(function(eventName){
-								domNodeToHookUp.addEventListener(eventName,function(e){e.preventDefault();compiledStatechartInstance[eventName](e)},false);
-							});
-						});
-					}
-
-					statusDiv.textContent+=" Done!";
+					require( [window.DOMParser ?
+							"src/javascript/scxml/cgf/util/xsl/browser" :
+							"src/javascript/scxml/cgf/util/xsl/ie"],
+						function(transform){
+
+							var statusDiv = document.getElementById("statusDiv");
+
+							statusDiv.textContent="Compiling SCXML elements...";
+
+							//pull SCXML nodes from DOM
+							var scxmlElements = document.getElementsByTagName("scxml");
+							for(var i = 0; i < scxmlElements.length; i++){
+								var scxml_input = scxmlElements[i];
+								var domNodeToHookUp = scxml_input.parentNode;
+
+								//prep scxml document to transform by pulling the scxml node into its own document
+								var scxmlns = "http://www.w3.org/2005/07/scxml";
+								var scxmlToTransform = document.implementation.createDocument (scxmlns , "scxml",
null);
+								var newNode = scxmlToTransform.importNode(scxml_input.cloneNode(true),true);
+								scxmlToTransform.replaceChild(newNode,scxmlToTransform.documentElement);
+
+								var compiledStatechartConstructor, compiledStatechartInstance;
+
+								compiler.compile({
+									inFiles:[scxmlToTransform],
+									//debug:true,
+									backend:"state",
+									beautify:true,
+									verbose:false,
+									log:false,
+									ie:false
+								}, function(scArr){
+									var transformedJs = scArr[0];
+
+									//eval
+									console.log(transformedJs);
+									eval(transformedJs);
+									compiledStatechartConstructor = StatechartExecutionContext;
+									compiledStatechartInstance = new compiledStatechartConstructor();
+
+									//initialize
+									compiledStatechartInstance.initialize();
+
+									//pass in reference to rect
+									compiledStatechartInstance.init({rawNode:domNodeToHookUp});
+
+									//hook up DOM events
+									["mousedown","mouseup","mousemove"].forEach(function(eventName){
+										domNodeToHookUp.addEventListener(eventName,function(e){e.preventDefault();compiledStatechartInstance[eventName](e)},false);
+									});
+								},transform);
+							}
+
+							statusDiv.textContent+=" Done!";
+						}
+					)
 				}
 			);
 		]]></script>

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drag-and-drop/drag-and-drop2.xhtml
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drag-and-drop/drag-and-drop2.xhtml?rev=978787&r1=978786&r2=978787&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drag-and-drop/drag-and-drop2.xhtml (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drag-and-drop/drag-and-drop2.xhtml Sat Jul
24 03:44:06 2010
@@ -56,79 +56,88 @@ own state.
 				["src/javascript/scxml/cgf/SCXMLCompiler",
 					"xml!demo/drag-and-drop/drag-and-drop2.xml"],
 
+
 				function(compiler,scxml_input){
 
-					var SVG_NS = "http://www.w3.org/2000/svg";
+					require([ window.DOMParser ?
+							"src/javascript/scxml/cgf/util/xsl/browser" :
+							"src/javascript/scxml/cgf/util/xsl/ie"],
+						function(transform){
+
+
+							var SVG_NS = "http://www.w3.org/2000/svg";
+
+							var statusDiv = document.getElementById("statusDiv");
+							var elementButton = document.getElementById("elementButton");
+							var svgCanvas = document.getElementById("canvas");
+
+							statusDiv.textContent="Compiling SCXML...";
+
+							var compiledStatechartConstructor;
+
+							//compile statechart
+							compiler.compile({
+								inFiles:[scxml_input],
+								//debug:true,
+								backend:"state",
+								beautify:true,
+								verbose:false,
+								log:false,
+								ie:false
+							}, function(scArr){
+								var transformedJs = scArr[0];
+
+								//eval
+								console.log(transformedJs);
+								eval(transformedJs);
+								compiledStatechartConstructor = StatechartExecutionContext;
+							},transform);
+
+							statusDiv.textContent+=" Done!";
+
+							//just for fun, random color generator, courtesy of http://stackoverflow.com/questions/1484506/random-color-generator-in-javascript
+							function get_random_color() {
+								var letters = '0123456789ABCDEF'.split('');
+								var color = '#';
+								for (var i = 0; i < 6; i++ ) {
+									color += letters[Math.round(Math.random() * 15)];
+								}
+								return color;
+							}
+
+							//hook up button UI control
+							elementButton.addEventListener("click",function(e){
+
+								//do DOM stuff- create new blue circle
+								var newGNode = document.createElementNS(SVG_NS,"g");
+								var newTextNode = document.createElementNS(SVG_NS,"text");
+								var newNode = document.createElementNS(SVG_NS,"circle");
+								newNode.setAttributeNS(null,"cx",50);
+								newNode.setAttributeNS(null,"cy",50);
+								newNode.setAttributeNS(null,"r",50);
+								newNode.setAttributeNS(null,"fill",get_random_color());
+								newNode.setAttributeNS(null,"stroke","black");
+
+								newGNode.appendChild(newNode);
+								newGNode.appendChild(newTextNode);
+
+								var compiledStatechartInstance = new compiledStatechartConstructor();
+
+								//initialize
+								compiledStatechartInstance.initialize();
+
+								//pass in reference to rect
+								compiledStatechartInstance.init({rawNode:newGNode,textNode:newTextNode});
+
+								//hook up DOM events
+								["mousedown","mouseup","mousemove"].forEach(function(eventName){
+									newGNode.addEventListener(eventName,function(e){e.preventDefault();compiledStatechartInstance[eventName](e)},false);
+								});
 
-					var statusDiv = document.getElementById("statusDiv");
-					var elementButton = document.getElementById("elementButton");
-					var svgCanvas = document.getElementById("canvas");
-
-					statusDiv.textContent="Compiling SCXML...";
-
-					var compiledStatechartConstructor; 
-
-					//compile statechart
-					compiler.compile({
-						inFiles:[scxml_input],
-						//debug:true,
-						backend:"state",
-						beautify:true,
-						verbose:false,
-						log:false,
-						ie:false
-					}, function(scArr){
-						var transformedJs = scArr[0];
-
-						//eval
-						console.log(transformedJs);
-						eval(transformedJs);
-						compiledStatechartConstructor = StatechartExecutionContext;
-					});
-
-					statusDiv.textContent+=" Done!";
-
-					//just for fun, random color generator, courtesy of http://stackoverflow.com/questions/1484506/random-color-generator-in-javascript
-					function get_random_color() {
-						var letters = '0123456789ABCDEF'.split('');
-						var color = '#';
-						for (var i = 0; i < 6; i++ ) {
-							color += letters[Math.round(Math.random() * 15)];
+								svgCanvas.appendChild(newGNode);
+							},false);
 						}
-						return color;
-					}
-
-					//hook up button UI control
-					elementButton.addEventListener("click",function(e){
-
-						//do DOM stuff- create new blue circle
-						var newGNode = document.createElementNS(SVG_NS,"g"); 
-						var newTextNode = document.createElementNS(SVG_NS,"text"); 
-						var newNode = document.createElementNS(SVG_NS,"circle"); 
-						newNode.setAttributeNS(null,"cx",50);
-						newNode.setAttributeNS(null,"cy",50);
-						newNode.setAttributeNS(null,"r",50);
-						newNode.setAttributeNS(null,"fill",get_random_color());
-						newNode.setAttributeNS(null,"stroke","black");
-
-						newGNode.appendChild(newNode);
-						newGNode.appendChild(newTextNode);
-
-						var compiledStatechartInstance = new compiledStatechartConstructor(); 
-
-						//initialize
-						compiledStatechartInstance.initialize();
-						
-						//pass in reference to rect
-						compiledStatechartInstance.init({rawNode:newGNode,textNode:newTextNode}); 
-
-						//hook up DOM events
-						["mousedown","mouseup","mousemove"].forEach(function(eventName){
-							newGNode.addEventListener(eventName,function(e){e.preventDefault();compiledStatechartInstance[eventName](e)},false);
-						});
-
-						svgCanvas.appendChild(newGNode);
-					},false);
+					)
 				}
 			);
 		]]></script>

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/demo/sandbox/sandbox.html
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/demo/sandbox/sandbox.html?rev=978787&r1=978786&r2=978787&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/demo/sandbox/sandbox.html (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/demo/sandbox/sandbox.html Sat Jul 24 03:44:06
2010
@@ -85,113 +85,125 @@ that uses the SCXMLCompiler front-end. 
 
 			require(
 				{
-					"baseUrl":"/scxml-js/"
+					"baseUrl":"/"
 				},
 				[ "src/javascript/scxml/cgf/SCXMLCompiler",
-					"text!test/kitchen_sink/KitchenSink_executableContent.xml",
-					"src/javascript/scxml/cgf/util/xml"],
+					"text!test/kitchen_sink/KitchenSink_executableContent.xml" ],
 
-				function(compiler,KitchenSink_executableContent,xmlUtil){
 
-					var compiledStatechartConstructor, compiledStatechartInstance;
 
-					//some browser compatibility stuff
-					function addEventListener(el,ev,fn){
-						if (el.addEventListener){
-							el.addEventListener(ev, fn, false); 
-						} else if (el.attachEvent){
-							el.attachEvent('on' + ev, fn);
-						}
-					}
+				function(compiler,KitchenSink_executableContent){
 
-                    function setTextContent(el,str){
-                           if(typeof el.textContent == "string"){
-                               el.textContent+=str;
-                           }else if(typeof el.innerText == "string"){
-                               el.innerText+=str;
-                           }
-                    } 
-
-					function ccToString(conf){return conf.map(function(s){return s.toString()})}
-
-					//pull UI controls from DOM
-					var scxml_input = document.getElementById("scxml_input");
-					var js_output = document.getElementById("js_output");
-					var sc_console = document.getElementById("sc_console");
-					var event_name_field = document.getElementById("event_name_field");
-					var send_event_button = document.getElementById("send_event_button");
-					var compile_button = document.getElementById("compile_button");
-
-					//hook up minimal console api
-					if((typeof console == "undefined") || !console.log){
-                        /*
-						   console = {log : function(str){
-												setTextContent(sc_console, str + "\n");
-												sc_console.scrollTop = sc_console.scrollHeight; 
-											} }
-                       */ 
-						   console = {log : function(str){}}
-					} 
-
-					//set initial content of scxml_input
-					setTextContent(scxml_input, KitchenSink_executableContent);
-
-					//prepopulate stuff with stuff. 
-					addEventListener(compile_button,"click",function(e){
-
-						//TODO: provide a UI for setting these options
-						var compileLog = true;
-						var backend = "state";
-
-						//parse textArea into xml
-						var textInput = xmlUtil.parseFromString(scxml_input.textContent || scxml_input.innerText);
-
-						compiler.compile({
-							inFiles:[textInput],
-							backend:backend,
-							beautify:true,
-							verbose:false,
-							log:compileLog,
-							ie:false
-						}, function(scArr){
-							var transformedJs = scArr[0];
-
-							//eval
-							console.log(transformedJs);
-							eval(transformedJs);
-							compiledStatechartConstructor = StatechartExecutionContext;
-							compiledStatechartInstance = new compiledStatechartConstructor(); 
-
-							setTextContent(sc_console, "Initializing new statechart instance...\n");
-
-							//initialize
-							compiledStatechartInstance.initialize();
-							
-							//update DOM
-							setTextContent(js_output, transformedJs);
-
-							/*
-							sc_console.removeAttribute("disabled");
-							event_name_field.removeAttribute("disabled");
-							send_event_button.removeAttribute("disabled");
-							*/
-
-							setTextContent(sc_console, ccToString(compiledStatechartInstance.getCurrentConfiguration())
+ ">");
-							//sc_console.scrollTop = sc_console.scrollHeight; 
-						});
-					},false);
-
-					addEventListener(send_event_button,"click",function(e){
-						var eventToSend = event_name_field.value;
-
-						setTextContent(sc_console, eventToSend + "\n");
-
-						//we use synchronous API
-						compiledStatechartInstance[eventToSend](); 
-
-						setTextContent(sc_console, ccToString(compiledStatechartInstance.getCurrentConfiguration())
+ ">");
-						//sc_console.scrollTop = sc_console.scrollHeight; 
-					},false);
+					require( [window.DOMParser ?
+							"src/javascript/scxml/cgf/util/xsl/browser" :
+							"src/javascript/scxml/cgf/util/xsl/ie",
+						  window.XMLSerializer ?
+							"src/javascript/scxml/cgf/util/xml/browser" :
+							"src/javascript/scxml/cgf/util/xml/ie" ],
+						function(transform,xmlUtil){
+
+
+							var compiledStatechartConstructor, compiledStatechartInstance;
+
+							//some browser compatibility stuff
+							function addEventListener(el,ev,fn){
+								if (el.addEventListener){
+									el.addEventListener(ev, fn, false);
+								} else if (el.attachEvent){
+									el.attachEvent('on' + ev, fn);
+								}
+							}
+
+							function setTextContent(el,str){
+								if(typeof el.textContent == "string"){
+									el.textContent+=str;
+								}else if(typeof el.innerText == "string"){
+									el.innerText+=str;
+								}
+							}
+
+							function ccToString(conf){return conf.map(function(s){return s.toString()})}
+
+							//pull UI controls from DOM
+							var scxml_input = document.getElementById("scxml_input");
+							var js_output = document.getElementById("js_output");
+							var sc_console = document.getElementById("sc_console");
+							var event_name_field = document.getElementById("event_name_field");
+							var send_event_button = document.getElementById("send_event_button");
+							var compile_button = document.getElementById("compile_button");
+
+							//hook up minimal console api
+							if((typeof console == "undefined") || !console.log){
+					/*
+								   console = {log : function(str){
+														setTextContent(sc_console, str + "\n");
+														sc_console.scrollTop = sc_console.scrollHeight;
+													} }
+				       */
+								   console = {log : function(str){}}
+							}
+
+							//set initial content of scxml_input
+							setTextContent(scxml_input, KitchenSink_executableContent);
+
+							//prepopulate stuff with stuff.
+							addEventListener(compile_button,"click",function(e){
+
+								//TODO: provide a UI for setting these options
+								var compileLog = true;
+								var backend = "state";
+
+								//parse textArea into xml
+								var textInput = xmlUtil.parseFromString(scxml_input.textContent || scxml_input.innerText);
+
+								compiler.compile({
+									inFiles:[textInput],
+									backend:backend,
+									beautify:true,
+									verbose:false,
+									log:compileLog,
+									ie:false
+								}, function(scArr){
+									var transformedJs = scArr[0];
+
+									//eval
+									console.log(transformedJs);
+									eval(transformedJs);
+									compiledStatechartConstructor = StatechartExecutionContext;
+									compiledStatechartInstance = new compiledStatechartConstructor();
+
+									setTextContent(sc_console, "Initializing new statechart instance...\n");
+
+									//initialize
+									compiledStatechartInstance.initialize();
+
+									//update DOM
+									setTextContent(js_output, transformedJs);
+
+									/*
+									sc_console.removeAttribute("disabled");
+									event_name_field.removeAttribute("disabled");
+									send_event_button.removeAttribute("disabled");
+									*/
+
+									setTextContent(sc_console, ccToString(compiledStatechartInstance.getCurrentConfiguration())
+ ">");
+									//sc_console.scrollTop = sc_console.scrollHeight;
+								},transform);
+							},false);
+
+							addEventListener(send_event_button,"click",function(e){
+								var eventToSend = event_name_field.value;
+
+								setTextContent(sc_console, eventToSend + "\n");
+
+								//we use synchronous API
+								compiledStatechartInstance[eventToSend]();
+
+								setTextContent(sc_console, ccToString(compiledStatechartInstance.getCurrentConfiguration())
+ ">");
+								//sc_console.scrollTop = sc_console.scrollHeight;
+							},false);
+						}
+					)
 				}
 			);
 

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/SCXMLCompiler.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/SCXMLCompiler.js?rev=978787&r1=978786&r2=978787&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/SCXMLCompiler.js (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/SCXMLCompiler.js Sat
Jul 24 03:44:06 2010
@@ -27,14 +27,11 @@ code.  
 
 require.def("src/javascript/scxml/cgf/SCXMLCompiler",
 
-	//TODO: conditional require
 	[
-		"src/javascript/scxml/cgf/Transformer",
 		"src/javascript/scxml/cgf/util/base",
 		"lib/js/beautify"],
 	
 	function(
-		Transformer,
 		base,
 		js_beautify
 	){
@@ -50,7 +47,7 @@ require.def("src/javascript/scxml/cgf/SC
 				log
 				verbose
 		*/
-		function compile(options,callback){
+		function compile(options,callback,transform){
 			if(!options.inFiles) return false;
 
 			if(options.ie){
@@ -68,8 +65,8 @@ require.def("src/javascript/scxml/cgf/SC
 
 				var toReturn = options.inFiles.map(function(xmlFile){
 
-					var ir = Transformer(xmlFile,backend.transformations,null,"xml",options.debug);
-					var transformedJs = Transformer(ir,backend.code,options,"text",options.debug);
+					var ir = transform(xmlFile,backend.transformations,null,"xml",options.debug);
+					var transformedJs = transform(ir,backend.code,options,"text",options.debug);
 
 					//optionally beautify it
 					if(options.beautify){

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/main.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/main.js?rev=978787&r1=978786&r2=978787&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/main.js (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/main.js Sat Jul 24 03:44:06
2010
@@ -34,10 +34,11 @@ It accepts command-line arguments, and c
  */
 
 require.def("src/javascript/scxml/cgf/main",
-	["src/javascript/scxml/cgf/SCXMLCompiler",
+	[ "src/javascript/scxml/cgf/SCXMLCompiler",
 		"src/javascript/scxml/cgf/util/commandLine",
-		"src/javascript/scxml/cgf/util/xml"],
-	function(SCXMLCompiler,cmdLineUtil,xmlUtil){
+		"src/javascript/scxml/cgf/util/xml",
+		"src/javascript/scxml/cgf/util/xsl/rhino"],
+	function(SCXMLCompiler,cmdLineUtil,xmlUtil,transform){
 
 		return function(args){
 
@@ -52,7 +53,6 @@ require.def("src/javascript/scxml/cgf/ma
 				log : true,
 				verbose :  true
 			}
-debugger;
 			var parsedOptionsMap = cmdLineUtil.parseCommandLine(optionsMap,args);
 			parsedOptionsMap.inFiles = parsedOptionsMap.args.map(xmlUtil.parseFromPath);
 			delete parsedOptionsMap.args;
@@ -60,7 +60,7 @@ debugger;
 			//TODO: parse paths in inFiles into documents
 			var scArr = SCXMLCompiler.compile(parsedOptionsMap,function(scArr){
 				scArr.forEach(function(sc){print(sc)});
-			});
+			},transform);
 		}
 
 });

Added: commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/browser.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/browser.js?rev=978787&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/browser.js
(added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/browser.js
Sat Jul 24 03:44:06 2010
@@ -0,0 +1,24 @@
+require.def("src/javascript/scxml/cgf/util/xml/browser",
+function(){
+
+	return {
+		parseFromString : (function(){
+			 var parser = new DOMParser();  
+			return function(str){
+				var doc = parser.parseFromString(str,"text/xml");
+				return doc;
+			}		
+		})(),
+		serializeToString : (function(){
+			var s = new XMLSerializer();  
+			return function(d){
+				str = s.serializeToString(d);  
+				return str;
+			}
+		})(),
+		parseFromPath : function(){
+			//I think this would use DocumentBuilderFactory
+			new Error("No implementation for parseFromPath.");
+		}
+	}
+})

Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/browser.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/ie.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/ie.js?rev=978787&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/ie.js (added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/ie.js Sat Jul
24 03:44:06 2010
@@ -0,0 +1,19 @@
+require.def("src/javascript/scxml/cgf/util/xml/ie",
+function(){
+
+	return {
+		parseFromString : function(str){
+			var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
+			xmlDoc.async="false";
+			xmlDoc.loadXML(str); 
+			
+			return xmlDoc;
+		},
+		serializeToString : function(d){
+			return d.xml;
+		},
+		parseFromPath : function(){
+			new Error("No implementation for parseFromPath.")
+		}
+	}
+})

Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/ie.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/rhino.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/rhino.js?rev=978787&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/rhino.js (added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/rhino.js Sat
Jul 24 03:44:06 2010
@@ -0,0 +1,49 @@
+require.def("src/javascript/scxml/cgf/util/xml/rhino",
+function(){
+
+	return {
+		parseFromString : function(){
+			//I think this would use DocumentBuilderFactory
+			new Error("No implementation for parseFromString.");
+		},
+		serializeToString : (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.asDOMSerializer().serialize(d);
+
+				var toReturn = String(new java.lang.String(baos.toByteArray()));
+				return toReturn;
+			}
+		})(),
+		parseFromPath : (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;
+			};
+		})()
+	}
+})
+
+
+

Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xml/rhino.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/browser.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/browser.js?rev=978787&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/browser.js
(added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/browser.js
Sat Jul 24 03:44:06 2010
@@ -0,0 +1,72 @@
+require.def("src/javascript/scxml/cgf/util/xsl/browser",
+function(){
+
+	
+
+	return function(sourceDocument,transformList,params,output,debug){
+		transformList = transformList && !transformList.length	? 
+					[transformList]			:
+					transformList;
+
+		function getProcessorFromStylesheetDocument(d){
+			var processor = new XSLTProcessor();  
+			processor.importStylesheet(d); 
+			return processor;
+		}
+
+
+		function getResultTextFromDoc(d){
+			var resultText;
+			if(d &&
+				d.body &&
+				d.body.children &&
+				d.body.children[0] &&
+				d.body.children[0].textContent){
+
+				//chrome
+				resultText  = d.body.children[0].textContent
+			} else if (d &&
+				d.documentElement &&
+				d.documentElement.firstChild &&
+				d.documentElement.firstChild.textContent){
+
+				//firefox
+				resultText = d.documentElement.firstChild.textContent;
+			}else{
+				console.log("Cannot get resultText out of object " + d);
+			}
+			return resultText;
+		}
+
+		//transform to IR
+		var processors = transformList.map(getProcessorFromStylesheetDocument); 
+
+		//set parameters
+		processors.forEach(function(p){
+			for(paramName in params){
+				 var paramValue = params[paramName];
+				 if (typeof paramValue == "string") p.setParameter(null,paramName,paramValue);
+			}
+		});
+
+		var docToTransform  = sourceDocument;
+		processors.forEach(function(p){
+			if(debug) console.dirxml(docToTransform); 
+			docToTransform = p.transformToDocument(docToTransform);
+		});
+		if(debug) console.dirxml(docToTransform); 
+
+
+		var toReturn;
+		switch(output){
+			case "text":
+				toReturn = getResultTextFromDoc(docToTransform);;
+				break;
+			case "xml":
+				toReturn = docToTransform;
+				break;
+		}
+
+		return toReturn;	//string or node
+	}		
+});

Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/browser.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/ie.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/ie.js?rev=978787&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/ie.js (added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/ie.js Sat Jul
24 03:44:06 2010
@@ -0,0 +1,37 @@
+require.def("src/javascript/scxml/cgf/util/xsl/ie",
+["src/javascript/scxml/cgf/util/xml/ie"],
+function(xmlUtil){
+
+	
+
+	return 	function(sourceDocument,transformList,params,output){
+		transformList = transformList && !transformList.length	? 
+					[transformList]			:
+					transformList;
+
+		//transform to IR
+		var docToTransform = sourceDocument;
+		for(var i=0; i < transformList.length-1; i++){
+			var t = transformList[i];
+
+			var txt = docToTransform.transformNode(t); 
+			docToTransform = xmlUtil.parseFromString(txt);
+		}
+
+		var lastFilter = transformList[transformList.length-1];
+
+		var txt = docToTransform.transformNode(lastFilter ); 
+
+		var toReturn;
+		switch(output){
+			case "text":
+				toReturn = txt;
+				break;
+			case "xml":
+				toReturn = xmlUtil.parseFromString(txt);
+				break;
+		}
+
+		return toReturn;	//string or node
+	}		
+});

Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/ie.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/rhino.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/rhino.js?rev=978787&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/rhino.js (added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/rhino.js Sat
Jul 24 03:44:06 2010
@@ -0,0 +1,81 @@
+require.def("src/javascript/scxml/cgf/util/xsl/rhino",
+["src/javascript/scxml/cgf/util/xml/rhino"],
+function(xmlUtil){
+
+	return (function(){
+		var TransformerFactory = javax.xml.transform.TransformerFactory,
+			XMLReaderFactory = Packages.org.xml.sax.helpers.XMLReaderFactory,
+			ByteArrayOutputStream = java.io.ByteArrayOutputStream,
+			StreamResult = javax.xml.transform.stream.StreamResult,
+			StreamSource = javax.xml.transform.stream.StreamSource,
+			DOMSource = javax.xml.transform.dom.DOMSource,
+			SAXResult = javax.xml.transform.sax.SAXResult,
+			DOMResult = javax.xml.transform.dom.DOMResult;
+
+		//do transforms
+		var tFactory = TransformerFactory.newInstance();
+
+		function transform(xsl,xml,params,output){
+				// Use the DOM Document to define a DOMSource object.
+				var xslDomSource = new DOMSource(xsl);
+
+				// Process the stylesheet DOMSource and generate a Transformer.
+				var transformer = tFactory.newTransformer(xslDomSource);
+
+				//set parameters
+				for(paramName in params){
+					 transformer.setParameter(paramName,params[paramName]);
+				}
+
+				// Use the DOM Document to define a DOMSource object.
+				// for Rhino only, we can also accept a path rather than a Document
+				var xmlDomSource = typeof xml == "string" ? 	
+							new StreamSource(xml) :
+							new DOMSource(xml);
+
+				var toReturn;
+				switch(output){
+					case "xml":
+						// Create an empty DOMResult for the Result.
+						var domResult = new DOMResult();
+						// Perform the transformation, placing the output in the DOMResult.
+						transformer.transform(xmlDomSource, domResult);
+						toReturn = domResult.getNode();
+						break;
+
+					case "text":
+						var baos = new ByteArrayOutputStream();
+						var streamResult = new StreamResult(baos);
+						transformer.transform(xmlDomSource, streamResult);
+						toReturn = String(new java.lang.String(baos.toByteArray()));
+						break;
+				}
+
+				return toReturn;
+		}
+
+		return function(sourceDocument,transformList,params,output){
+			transformList = transformList 
+					&& !(transformList instanceof Array)	? 
+						[transformList]			:
+						transformList;
+
+			var docToTransform = sourceDocument;
+
+			for(var i=0; i < transformList.length-1; i++){	
+				var t = transformList[i];
+				docToTransform  = transform(t,docToTransform,params,"xml");
+			}
+
+			var lastTransform = transformList[transformList.length-1];
+
+			// Parse the source XML, and send the parse events to the
+			// TransformerHandler.
+			var toReturn = transform(lastTransform,docToTransform,params,output);
+
+			return toReturn;	//string or node
+		}	
+	})()		
+});
+
+

Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/util/xsl/rhino.js
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/test/SCXMLCompiler.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/SCXMLCompiler.js?rev=978787&r1=978786&r2=978787&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/SCXMLCompiler.js (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/SCXMLCompiler.js Sat Jul 24 03:44:06 2010
@@ -3,10 +3,12 @@ require.def(
 	[
 		"xml!test/kitchen_sink/KitchenSink_executableContent.xml",
 		"src/javascript/scxml/cgf/backends/js/StatePatternStatechartGenerator",
-		"/lib/js/beautify.js"],
+		"/lib/js/beautify.js",
+		"src/javascript/scxml/cgf/util/xsl/rhino"],
 	function(
 		KitchenSink,
-		StatePatternStatechartGenerator
+		StatePatternStatechartGenerator,
+		transform
 	){
 		//some compatibility stuff for IE
 		//TODO: move out into another file

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/test/testBrowserTransform.html
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/testBrowserTransform.html?rev=978787&r1=978786&r2=978787&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/testBrowserTransform.html (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/testBrowserTransform.html Sat Jul 24 03:44:06
2010
@@ -15,27 +15,36 @@
 			[ "src/javascript/scxml/cgf/SCXMLCompiler",
 				"xml!test/kitchen_sink/KitchenSink_executableContent.xml"],
 			function(compiler,KitchenSink_executableContent){
-				var compileLog = true;
-				var backend = "state";
 
-				compiler.compile({
-					inFiles:[KitchenSink_executableContent],
-					backend:backend,
-					beautify:true,
-					verbose:false,
-					log:compileLog,
-					ie:false
-				}, function(scArr){
-					var transformedJs = scArr[0];
-
-					console.log(transformedJs);
-
-					//eval
-					eval(transformedJs);
-					window.StatechartExecutionContext = StatechartExecutionContext;
-					dojo.require("doh.runner"); 
-					doh.run();
-				});
+				require([ window.DOMParser ?
+						"src/javascript/scxml/cgf/util/xsl/browser" :
+						"src/javascript/scxml/cgf/util/xsl/ie"],
+					function(transform){
+
+						var compileLog = true;
+						var backend = "state";
+
+						compiler.compile({
+							inFiles:[KitchenSink_executableContent],
+							backend:backend,
+							beautify:true,
+							verbose:false,
+							log:compileLog,
+							ie:false
+						}, function(scArr){
+							var transformedJs = scArr[0];
+
+							console.log(transformedJs);
+
+							//eval
+							eval(transformedJs);
+							window.StatechartExecutionContext = StatechartExecutionContext;
+							dojo.require("doh.runner"); 
+							doh.run();
+						},transform);
+
+					}); 
+					
 			}
 		);
 



Mime
View raw message