You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by jb...@apache.org on 2010/06/12 21:36:55 UTC

svn commit: r954074 - in /commons/sandbox/gsoc/2010/scxml-js/trunk: src/scxml/cgf/SCXMLCompiler.js test/xpathEvaluator.js

Author: jbeard
Date: Sat Jun 12 19:36:55 2010
New Revision: 954074

URL: http://svn.apache.org/viewvc?rev=954074&view=rev
Log:
Intermediate commit. Currently swapping out all the xpath for DOM.

Modified:
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/scxml/cgf/SCXMLCompiler.js
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/xpathEvaluator.js

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/src/scxml/cgf/SCXMLCompiler.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/scxml/cgf/SCXMLCompiler.js?rev=954074&r1=954073&r2=954074&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/scxml/cgf/SCXMLCompiler.js (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/scxml/cgf/SCXMLCompiler.js Sat Jun 12 19:36:55 2010
@@ -151,10 +151,71 @@ require.def("src/scxml/cgf/SCXMLCompiler
 					options.noMap = options.noForEach = options.noIndexOf = true;
 				}
 
-				var scxmlRoot = parseSCXML(readFile(xmlFile));
+
+				//var scxmlRoot = parseSCXML(readFile(xmlFile));
+
+				//FIXME: later on, change architecture to use dependency injection, 
+				//so we are just given an xml doc to manipulate
+				importPackage(Packages.org.w3c.dom);
+				importPackage(javax.xml.parsers);
+				importPackage(javax.xml.xpath);
+
+				// Set up a DOM tree to query.
+				dfactory = DocumentBuilderFactory.newInstance();
+				dfactory.setNamespaceAware(true);
+				var doc = dfactory.newDocumentBuilder().parse(xmlFile);
+
+				var scxmlNs = "http://www.w3.org/2005/07/scxml";
+	
+				var personalNamespaceContext = new javax.xml.namespace.NamespaceContext({
+				       getNamespaceURI : function(prefix)
+					{
+						//default namespace
+						if(prefix.equals("s"))
+							return scxmlNs;
+						else
+							return scxmlNs;
+					},
+					
+					getPrefix : function(namespace)
+					{
+						return null;
+					},
+
+					getPrefixes : function(namespace)
+					{
+					    return null;
+					}
+
+				});
+
+				var factory = XPathFactory.newInstance();
+				xpath = factory.newXPath();
+				xpath.setNamespaceContext(personalNamespaceContext);
+
+				var expr = xpath.compile("//s:transition");
+				var result = expr.evaluate(doc, XPathConstants.NODESET);
+
+				print(result);
+				print(result.length);
+				debugger;
+
+				function nodesetToJsArray (args){
+					var toReturn = [];
+
+					for(var i = 0; i < args.length; i++){
+						toReturn.push(args.item(i));
+					}
+
+					return toReturn;
+				}
+
+				var arr = nodesetToJsArray(result);
+				arr.forEach(function(n){print(n.getAttributeNS(null,"event"))});
 
 				//do a bit of verification and normalization transformations
 
+				/*
 				//make all names we will use for variables legal
 				scxmlRoot..transition.(@event.length() && (@event = makeLegalLValue(@event)));
 
@@ -346,7 +407,8 @@ require.def("src/scxml/cgf/SCXMLCompiler
 
 				});
 				
-				print(scxmlRoot);
+				//print(scxmlRoot);
+				//debugger;
 				//return scxmlRoot;
 
 				//do transforms
@@ -377,7 +439,7 @@ require.def("src/scxml/cgf/SCXMLCompiler
 				}
 
 				return transformedJs; 
-
+				*/
 				/*
 				var generatorConstructor;
 				switch(options.backend){

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/test/xpathEvaluator.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/xpathEvaluator.js?rev=954074&r1=954073&r2=954074&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/xpathEvaluator.js (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/xpathEvaluator.js Sat Jun 12 19:36:55 2010
@@ -38,8 +38,8 @@ function isTextNode(n) {
 
 
 var filename = arguments[0];
-//var xpath = arguments[1];
-var xpath = "//*[(self::state or self::parallel or self::final or self::initial or self::scxml or self::history) and not(.//*[(self::state or self::parallel or self::final or self::initial or self::scxml or self::history)])]"
+var xpath = arguments[1];
+//var xpath = "//*[(self::state or self::parallel or self::final or self::initial or self::scxml or self::history) and not(.//*[(self::state or self::parallel or self::final or self::initial or self::scxml or self::history)])]"
 //[]
 
 if ((filename != null) && (filename.length > 0)
@@ -54,7 +54,7 @@ if ((filename != null) && (filename.leng
 	// Set up a DOM tree to query.
 	var inputSource = new InputSource(new FileInputStream(filename));
 	dfactory = DocumentBuilderFactory.newInstance();
-	dfactory.setNamespaceAware(false);
+	dfactory.setNamespaceAware(true);
 	var doc = dfactory.newDocumentBuilder().parse(inputSource);
 	
 	// Set up an identity transformer to use as serializer.
@@ -63,7 +63,7 @@ if ((filename != null) && (filename.leng
 
 	// Use the simple XPath API to select a nodeIterator.
 	print("Querying DOM using "+xpath);
-	var nl = XPathAPI.selectNodeIterator(doc, xpath);
+	var nl = XPathAPI.selectNodeIterator(doc, xpath, doc.documentElement);
 
 	// Serialize the found nodes to System.out.
 	//print("<output>");