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/08/01 00:34:10 UTC

svn commit: r981100 - in /commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module: lib/xslt/ src/javascript/scxml/cgf/util/external_communications/ src/xslt/ir-compiler/external_communications/ src/xslt/util/ test/ test/send/

Author: jbeard
Date: Sat Jul 31 22:34:10 2010
New Revision: 981100

URL: http://svn.apache.org/viewvc?rev=981100&view=rev
Log:
Intermediate commit. Added sample code to generate send.

Added:
    commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/lib/xslt/
    commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/lib/xslt/javascript-literals.xsl   (with props)
    commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/lib/xslt/xml-to-string.xsl
      - copied, changed from r981099, commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/util/xml-to-string.xsl
    commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/javascript/scxml/cgf/util/external_communications/common.js   (with props)
Modified:
    commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/javascript/scxml/cgf/util/external_communications/jquery.js
    commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/filterParams.xsl
    commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/genMessageTemplates.xsl
    commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/sendToMessageTemplate.xsl
    commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/splitNamelist.xsl
    commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/util/xml-to-string.xsl
    commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/TestSend.xml
    commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/test_with_xsltproc.sh

Added: commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/lib/xslt/javascript-literals.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/lib/xslt/javascript-literals.xsl?rev=981100&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/lib/xslt/javascript-literals.xsl (added)
+++ commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/lib/xslt/javascript-literals.xsl Sat Jul 31 22:34:10 2010
@@ -0,0 +1,112 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+  <xsl:import href="xml-to-string.xsl"/>
+
+  <xsl:template match="/">
+    <html xml:space="preserve">
+      <head>
+        <title>Top-level elements displayed</title>
+        <script language="JavaScript">
+          <xsl:comment>
+            <xsl:apply-templates select="/*/*" mode="script"/>
+            <xsl:text>&#xA;// </xsl:text>
+          </xsl:comment>
+        </script>
+      </head>
+      <body>
+        <h2>Top-level elements, each as a stand-alone XML document</h2>
+        <form name="myForm">
+          <textarea name="xml" cols="75" rows="18"/>
+          <br/>
+          <select name="choice" onchange="on_change();">
+            <xsl:apply-templates select="/*/*"/>
+          </select>
+        </form>
+        <script language="JavaScript">
+          <xsl:comment>
+            function on_change() {
+                document.myForm.xml.value = eval('e' + document.myForm.choice.selectedIndex);
+            }
+
+            if (document.myForm.xml.value == "")
+                on_change();
+          // </xsl:comment>
+        </script>
+      </body>
+    </html>
+  </xsl:template>
+
+  <xsl:template match="/*/*">
+    <option>
+      <xsl:value-of select="position()"/>
+      <xsl:text>. </xsl:text>
+      <xsl:value-of select="name()"/>
+    </option>
+  </xsl:template>
+
+  <xsl:template match="/*/*" mode="script">
+    <xsl:text>&#xA;var e</xsl:text>
+    <xsl:value-of select="count(preceding-sibling::*)"/>
+    <xsl:text> = '</xsl:text>
+    <xsl:call-template name="escape-string">
+      <xsl:with-param name="text">
+        <xsl:call-template name="xml-to-string"/>
+      </xsl:with-param>
+    </xsl:call-template>
+    <xsl:text>';</xsl:text>
+  </xsl:template>
+
+  <xsl:template name="escape-string">
+    <xsl:param name="text"/>
+    <xsl:variable name="slashesEscaped">
+      <xsl:call-template name="replace-string">
+        <xsl:with-param name="text" select="$text"/>
+        <xsl:with-param name="replace" select="'\'"/>
+        <xsl:with-param name="with" select="'\\'"/>
+      </xsl:call-template>
+    </xsl:variable>
+    <xsl:variable name="apostrophesEscaped">
+      <xsl:call-template name="replace-string">
+        <xsl:with-param name="text" select="$slashesEscaped"/>
+        <xsl:with-param name="replace" select="&quot;'&quot;"/>
+        <xsl:with-param name="with" select="&quot;\&apos;&quot;"/>
+      </xsl:call-template>
+    </xsl:variable>
+    <xsl:variable name="newlinesEscaped">
+      <xsl:call-template name="replace-string">
+        <xsl:with-param name="text" select="$apostrophesEscaped"/>
+        <xsl:with-param name="replace" select="'&#xA;'"/>
+        <xsl:with-param name="with" select="'\n'"/>
+      </xsl:call-template>
+    </xsl:variable>
+    <xsl:call-template name="escape-dash-dash">
+      <xsl:with-param name="text" select="$newlinesEscaped"/>
+      <xsl:with-param name="replace" select="'--'"/>
+      <xsl:with-param name="with" select='"-&apos; + &apos;-"'/>
+    </xsl:call-template>
+  </xsl:template>
+
+  <xsl:template name="escape-dash-dash">
+    <xsl:param name="text"/>
+    <xsl:variable name="tempText">
+      <xsl:call-template name="replace-string">
+        <xsl:with-param name="text" select="$text"/>
+        <xsl:with-param name="replace" select="'--'"/>
+        <xsl:with-param name="with" select='"-&apos; + &apos;-"'/>
+      </xsl:call-template>
+    </xsl:variable>
+    <xsl:choose>
+      <xsl:when test="contains($tempText, '--')">
+        <xsl:call-template name="escape-dash-dash">
+          <xsl:with-param name="text" select="$tempText"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="$tempText"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file

Propchange: commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/lib/xslt/javascript-literals.xsl
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/lib/xslt/xml-to-string.xsl (from r981099, commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/util/xml-to-string.xsl)
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/lib/xslt/xml-to-string.xsl?p2=commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/lib/xslt/xml-to-string.xsl&p1=commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/util/xml-to-string.xsl&r1=981099&r2=981100&rev=981100&view=diff
==============================================================================
    (empty)

Added: commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/javascript/scxml/cgf/util/external_communications/common.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/javascript/scxml/cgf/util/external_communications/common.js?rev=981100&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/javascript/scxml/cgf/util/external_communications/common.js (added)
+++ commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/javascript/scxml/cgf/util/external_communications/common.js Sat Jul 31 22:34:10 2010
@@ -0,0 +1,27 @@
+require.def("src/javascript/scxml/cgf/util/external_communications/common",
+{
+	genProperties : function ($names) {
+		var toReturn = [], value, name;
+
+		for (name in $names) {
+			if ($names.hasOwnProperty(name)) {
+				value = $names[name];
+				toReturn.push('<scxml:property name="', name, '">', value, '</scxml:property>');
+			}
+		}
+		return toReturn.join('');
+	},
+
+	scxmlMessageTemplate : function (data) {
+		//TODO: hints
+		return [
+			'<scxml:message xmlns:scxml="http://www.w3.org/2005/07/scxml" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2005/07/scxml scxml-message.xsd" source="" sourcetype="scxml"',
+			'sourcetype="scxml" ',
+			'sendid="', data.$sendid, '" ',
+			'type="', data.$type, '" ',
+			'name="', data.$event, '" ',
+			'target="', data.$target, '">',
+			'<scxml:payload>', data.$content || this.genProperties(data.$names), '</scxml:payload></scxml:message>'
+		].join('');
+	}
+});

Propchange: commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/javascript/scxml/cgf/util/external_communications/common.js
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/javascript/scxml/cgf/util/external_communications/jquery.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/javascript/scxml/cgf/util/external_communications/jquery.js?rev=981100&r1=981099&r2=981100&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/javascript/scxml/cgf/util/external_communications/jquery.js (original)
+++ commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/javascript/scxml/cgf/util/external_communications/jquery.js Sat Jul 31 22:34:10 2010
@@ -1,7 +1,8 @@
 require.def("src/javascript/scxml/cgf/util/external_communications/jquery",
-["lib/js/jquery.js"],
-function(){
+["src/javascript/scxml/cgf/util/external_communications/common","lib/js/jquery.js"],
+function(common){
 	//fixme: json or xml? how do we handle the difference for get? for post?
+
 	return {
 		get : function(url){
 			var toReturn;
@@ -14,7 +15,20 @@ function(){
 			});
 			return toReturn;
 		},
-		post : function(url,data){
+		post : function(url,messagedata,contentdata){
+			var postDataString = null;
+			if(typeof contentdata == "string"){
+				//assume content
+				messagedata.$content = contentdata;
+			}else if(typeof contentdata == "object"){
+				//assume we are given an object hash
+				messagedata.$names = contentdata;
+			}			
+			postDataString = common.scxmlMessageTemplate(data);
+
+			jQuery.post(url,{_content:postDataString});
+
+			/*
 			var toReturn;
 			$.ajax({
 				type:'POST',
@@ -22,10 +36,13 @@ function(){
 				success: function(result) {
 					toReturn = result;
 				},
-				data:data,
+				data:{
+					_content : postDataString 
+				},
 				async:false
 			});
 			return toReturn;
+			*/
 		}
 	}
 })

Modified: commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/filterParams.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/filterParams.xsl?rev=981100&r1=981099&r2=981100&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/filterParams.xsl (original)
+++ commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/filterParams.xsl Sat Jul 31 22:34:10 2010
@@ -14,14 +14,22 @@
 	</xsl:template>
 
 	<xsl:template match="s:send">
-		<xsl:variable name="namelistNodes" select="c:namelist/c:name/text()"/>
+		<xsl:variable name="namelistNodes" select="c:namelist/c:name"/>
+		<xsl:variable name="filteredParams" select="s:param[not(@name = $namelistNodes/text())]"/>
+
+		<!--
+		<xsl:message>
+			namelistNodes : <xsl:value-of select="count($namelistNodes)"/>
+			filteredParams : <xsl:value-of select="count($filteredParams)"/>
+		</xsl:message>
+		-->
 
 		<xsl:copy>
 			<xsl:apply-templates select="@*"/>
 
-			<xsl:apply-templates select="param[not(@name = $namelistNodes)]"/>
+			<xsl:apply-templates select="$filteredParams"/>
 
-			<xsl:apply-templates select="node()[not(self::param)]"/>
+			<xsl:apply-templates select="node()[not(self::s:param)]"/>
 		</xsl:copy>
 	</xsl:template>
 

Modified: commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/genMessageTemplates.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/genMessageTemplates.xsl?rev=981100&r1=981099&r2=981100&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/genMessageTemplates.xsl (original)
+++ commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/genMessageTemplates.xsl Sat Jul 31 22:34:10 2010
@@ -22,9 +22,21 @@
 	xmlns:c="http://commons.apache.org/scxml-js"
 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	version="1.0">
+
+	<xsl:import href="../../util/xml-to-string.xsl"/>
+
   	<xsl:output method="text"/>
 
-	<xsl:template match="send">
+	<!--
+	<xsl:template match="/">
+		<TestElement>
+			<xsl:apply-templates mode="escape"/>
+		</TestElement>
+	</xsl:template>
+	-->
+
+	<!--
+	<xsl:template match="s:send">
 		<xsl:text>send(</xsl:text>
 			<xsl:apply-templates select="c:messageTemplate"/>,
 			<xsl:text>&apos;</xsl:text><xsl:value-of select="@target"/><xsl:text>&apos;</xsl:text>
@@ -32,13 +44,13 @@
 	</xsl:template>
 		
 	<xsl:template match="c:messageTemplate">
-		<xsl:text>return &apos;</xsl:text><xsl:apply-templates select="*"/> <xsl:text>&apos;</xsl:text>
+		<xsl:text>return &apos;</xsl:text><xsl:apply-templates mode="escape"/> <xsl:text>&apos;</xsl:text>
 	</xsl:template>
 
 	<xsl:template match="c:name">
 		<xsl:text>&apos; + </xsl:text>
 			<xsl:value-of select="@name"/>
-		<xsl:text> + apos;</xsl:text>
+		<xsl:text> + &apos;</xsl:text>
 	</xsl:template>
 
 	<xsl:template match="c:param">
@@ -47,51 +59,168 @@
 			<xsl:if test="@expr">
 				|| <xsl:value-of select="@expr"/>
 			</xsl:if>
-		<xsl:text> + apos;</xsl:text>
+		<xsl:text> + &apos;</xsl:text>
 	</xsl:template>
-	
-	<!-- from: http://stackoverflow.com/questions/1162352/converting-xml-to-escaped-text-in-xslt -->
-	<xsl:template match="*" mode="escape">
-		<!-- Begin opening tag -->
-		<xsl:text>&lt;</xsl:text>
-		<xsl:value-of select="name()"/>
-		
-		<!-- Namespaces -->
-		<xsl:for-each select="namespace::*">
-			<xsl:text> xmlns</xsl:text>
-			<xsl:if test="name() != ''">
-				<xsl:text>:</xsl:text>
-				<xsl:value-of select="name()"/>
-			</xsl:if>
-			<xsl:text>='</xsl:text>
-			<xsl:call-template name="escape-xml">
-					<xsl:with-param name="text" select="."/>
-			</xsl:call-template>
-			<xsl:text>'</xsl:text>
-		</xsl:for-each>
-		
-		<!-- Attributes -->
-		<xsl:for-each select="@*">
-			<xsl:text> </xsl:text>
-			<xsl:value-of select="name()"/>
-			<xsl:text>='</xsl:text>
-			<xsl:call-template name="escape-xml">
-					<xsl:with-param name="text" select="."/>
-			</xsl:call-template>
-			<xsl:text>'</xsl:text>
-		</xsl:for-each>
-		
-		<!-- End opening tag -->
-		<xsl:text>&gt;</xsl:text>
-		
-		<!-- Content (child elements, text nodes, and PIs) -->
-		<xsl:apply-templates select="node()" mode="escape" />
-		
-		<!-- Closing tag -->
-		<xsl:text>&lt;/</xsl:text>
-		<xsl:value-of select="name()"/>
-		<xsl:text>&gt;</xsl:text>
+	-->
+
+	<xsl:template match="/">
+		<xsl:apply-templates select="//s:send"/>
 	</xsl:template>
-		
-		
+
+	<xsl:template match="s:send">
+		<!-- TODO: switch based on whether send is internal.
+			the code so far is only for external -->
+
+		<xsl:variable name="eventParamValue">
+			<xsl:choose>
+				<xsl:when test="@event">
+					&quot;<xsl:value-of select="@event"/>&quot;
+				</xsl:when>
+				<xsl:when test="@eventexpr">
+					<xsl:value-of select="@eventexpr"/>
+				</xsl:when>
+				<xsl:otherwise>
+					<!-- TODO: move into constant variable -->
+					"external.event"
+				</xsl:otherwise>
+			</xsl:choose>
+		</xsl:variable>
+
+
+		<xsl:variable name="targetParamValue">
+			<xsl:choose>
+				<xsl:when test="@target">
+					&quot;<xsl:value-of select="@target"/>&quot;
+				</xsl:when>
+				<xsl:when test="@targetexpr">
+					<xsl:value-of select="@targetexpr"/>
+				</xsl:when>
+				<xsl:otherwise>
+					<xsl:message terminate="yes">
+						You must specify a @target or @targetexpr on a send element.
+					</xsl:message>
+				</xsl:otherwise>
+			</xsl:choose>
+		</xsl:variable>
+
+
+		<xsl:variable name="typeParamValue">
+			<xsl:choose>
+				<xsl:when test="@type">
+					&quot;<xsl:value-of select="@type"/>&quot;
+				</xsl:when>
+				<xsl:when test="@typeexpr">
+					<xsl:value-of select="@typeexpr"/>
+				</xsl:when>
+				<xsl:otherwise>
+					"scxml"
+				</xsl:otherwise>
+			</xsl:choose>
+		</xsl:variable>
+
+
+		<xsl:variable name="idParamValue">
+			<xsl:choose>
+				<xsl:when test="@id">
+					&quot;<xsl:value-of select="@id"/>&quot;
+				</xsl:when>
+				<xsl:when test="@idlocation">
+					<xsl:value-of select="@idlocation"/>
+				</xsl:when>
+				<xsl:otherwise>
+					<!-- empty node-set? empty string?-->
+					""
+				</xsl:otherwise>
+			</xsl:choose>
+		</xsl:variable>
+
+
+		<xsl:variable name="delayParamValue">
+			<xsl:choose>
+				<xsl:when test="@delay">
+					&quot;<xsl:value-of select="@delay"/>&quot;
+				</xsl:when>
+				<xsl:when test="@delayexpr">
+					<xsl:value-of select="@delayexpr"/>
+				</xsl:when>
+				<xsl:otherwise>
+					<!-- empty node-set? empty string?-->
+					""
+				</xsl:otherwise>
+			</xsl:choose>
+		</xsl:variable>
+
+		<xsl:variable name="hintsParamValue">
+			<xsl:choose>
+				<xsl:when test="@hints">
+					&quot;<xsl:value-of select="@hints"/>&quot;
+				</xsl:when>
+				<xsl:when test="@hintsexpr">
+					<xsl:value-of select="@hintsexpr"/>
+				</xsl:when>
+				<xsl:otherwise>
+					<!-- empty node-set? empty string?-->
+					""
+				</xsl:otherwise>
+			</xsl:choose>
+		</xsl:variable>
+
+		<xsl:variable name="payload">
+			<xsl:choose>
+				<xsl:when test="s:content">
+					<!-- serialize to js-safe string -->
+					'<xsl:apply-templates select="s:content"/>'
+				</xsl:when>
+				<xsl:otherwise>
+					{
+					<xsl:for-each select="c:namelist/c:name | s:param">
+						<xsl:variable name="name">
+							<xsl:choose>
+								<xsl:when test="@name">
+									<xsl:value-of select="@name"/>
+								</xsl:when>
+								<xsl:otherwise>
+									<xsl:value-of select="."/>
+								</xsl:otherwise>
+							</xsl:choose>
+						</xsl:variable>
+						<xsl:value-of select="$name" /> : <xsl:value-of select="$name" />
+						<xsl:if test="@expr">
+							|| <xsl:value-of select="@expr"/>
+						</xsl:if>
+						<xsl:if test="not(position() = last())">
+						,
+						</xsl:if>
+					</xsl:for-each>
+					}
+				</xsl:otherwise>
+			</xsl:choose>
+		</xsl:variable>
+
+		<xsl:text>send(</xsl:text>
+			<xsl:value-of select="$targetParamValue"/>,
+			{
+				$event : <xsl:value-of select="$eventParamValue"/>,
+				$target : <xsl:value-of select="$targetParamValue"/>,
+				$type : <xsl:value-of select="$typeParamValue"/>,
+				$sendid : <xsl:value-of select="$idParamValue"/>,
+				$delay : <xsl:value-of select="$delayParamValue"/>,
+				$hints : <xsl:value-of select="$hintsParamValue"/>
+
+			},
+			<xsl:value-of select="$payload"/>
+		<xsl:text>)</xsl:text>
+		<xsl:text>&#xA;&#xA;</xsl:text>
+	</xsl:template>
+
+	<xsl:template match="s:content">
+		<xsl:call-template name="escape-js-string">
+			<xsl:with-param name="text">
+				<xsl:for-each select="node()">
+					<xsl:call-template name="xml-to-string"/>
+				</xsl:for-each>
+			</xsl:with-param>
+		</xsl:call-template>
+	</xsl:template>
+
 </xsl:stylesheet>

Modified: commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/sendToMessageTemplate.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/sendToMessageTemplate.xsl?rev=981100&r1=981099&r2=981100&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/sendToMessageTemplate.xsl (original)
+++ commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/sendToMessageTemplate.xsl Sat Jul 31 22:34:10 2010
@@ -40,72 +40,52 @@
 			<xsl:apply-templates select="@*"/>
 
 
-			<!-- TODO: idlocation -->
+			<!-- TODO: id or idlocation -->
 			<!-- TODO: hints --> 
 			<c:messageTemplate>
 				<message 
 					xsi:schemaLocation="http://www.w3.org/2005/07/scxml scxml-message.xsd"
 					sourcetype="scxml"
 					sendid="{@id}">
-					<payload>
-						<!-- these properties may be static or dynamic -->
-						<xsl:choose>
-							<xsl:when test="@type">
-								<xsl:attribute name="type">
-									<xsl:value-of select="@type"/>
-								</xsl:attribute>
-							</xsl:when>
-							<xsl:otherwise>
-								<!-- accept it as a parameter --> 
-								<c:param name="type"/>
-							</xsl:otherwise>
-						</xsl:choose>
-
-						<xsl:choose>
-							<xsl:when test="@event">
-								<xsl:attribute name="name">
-									<xsl:value-of select="@event"/>
-								</xsl:attribute>
-							</xsl:when>
-							<xsl:otherwise>
-								<!-- accept it as a parameter --> 
-								<c:param name="event"/>
-							</xsl:otherwise>
-						</xsl:choose>
-
-						<xsl:choose>
-							<xsl:when test="@target">
-								<xsl:attribute name="target">
-									<xsl:value-of select="@target"/>
-								</xsl:attribute>
-							</xsl:when>
-							<xsl:otherwise>
-								<!-- accept it as a parameter --> 
-								<c:param name="target"/>
-							</xsl:otherwise>
-						</xsl:choose>
-
-						<!-- grab all of the things that might be properties -->
-						<xsl:choose>
-							<xsl:when test="content">
-								<xsl:apply-templates select="content"/>
-							</xsl:when>
-							<xsl:otherwise>
-								<xsl:for-each select="c:namelist/c:name">
-									<property name="{.}">
-										<c:param name="{.}"/>
-									</property>
-								</xsl:for-each> 
-								<xsl:for-each select="param/@name">
-									<property name="{.}">
-										<c:name name="{.}"/>
-									</property>
-								</xsl:for-each> 
-
-
-							</xsl:otherwise>
-						</xsl:choose>
-					</payload>
+
+					<!-- these properties may be static or dynamic -->
+					
+					<xsl:if test="@type">
+						<xsl:attribute name="type">
+							<xsl:value-of select="@type"/>
+						</xsl:attribute>
+					</xsl:if>
+
+					<xsl:if test="@event">
+						<xsl:attribute name="name">
+							<xsl:value-of select="@event"/>
+						</xsl:attribute>
+					</xsl:if>
+
+					<xsl:if test="@target">
+						<xsl:attribute name="target">
+							<xsl:value-of select="@target"/>
+						</xsl:attribute>
+					</xsl:if>
+
+					<xsl:if test="s:content or c:namelist/c:name or s:param">
+						<payload>
+							<!-- grab all of the things that might be properties -->
+							<xsl:choose>
+								<xsl:when test="s:content">
+									<xsl:apply-templates select="s:content"/>
+								</xsl:when>
+								<xsl:otherwise>
+									<xsl:for-each select="c:namelist/c:name">
+										<property name="{.}"><c:param name="{.}"/></property>
+									</xsl:for-each> 
+									<xsl:for-each select="s:param/@name">
+										<property name="{.}"><c:name name="{.}"/></property>
+									</xsl:for-each> 
+								</xsl:otherwise>
+							</xsl:choose>
+						</payload>
+					</xsl:if>
 				</message>
 			</c:messageTemplate>
 

Modified: commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/splitNamelist.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/splitNamelist.xsl?rev=981100&r1=981099&r2=981100&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/splitNamelist.xsl (original)
+++ commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/splitNamelist.xsl Sat Jul 31 22:34:10 2010
@@ -33,13 +33,16 @@
 
 	
 	<xsl:template match="s:send">
+		<xsl:variable name="normalizedNamelist" select="normalize-space(@namelist)"/>
 		<xsl:copy>
 			<xsl:apply-templates select="@*|node()"/>
-			<c:namelist>
-				<xsl:call-template name="namelistAttributeToNodeList">
-					<xsl:with-param name="list" select="@namelist"/>
-				</xsl:call-template>	
-			</c:namelist>
+			<xsl:if test="$normalizedNamelist">
+				<c:namelist>
+					<xsl:call-template name="namelistAttributeToNodeList">
+						<xsl:with-param name="list" select="$normalizedNamelist"/>
+					</xsl:call-template>	
+				</c:namelist>
+			</xsl:if>
 		</xsl:copy>
 	</xsl:template>
 

Modified: commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/util/xml-to-string.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/util/xml-to-string.xsl?rev=981100&r1=981099&r2=981100&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/util/xml-to-string.xsl (original)
+++ commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/util/xml-to-string.xsl Sat Jul 31 22:34:10 2010
@@ -314,4 +314,55 @@ Recent changes:
     </xsl:choose>
   </xsl:template>
 
+  <xsl:template name="escape-js-string">
+    <xsl:param name="text"/>
+    <xsl:variable name="slashesEscaped">
+      <xsl:call-template name="replace-string">
+        <xsl:with-param name="text" select="$text"/>
+        <xsl:with-param name="replace" select="'\'"/>
+        <xsl:with-param name="with" select="'\\'"/>
+      </xsl:call-template>
+    </xsl:variable>
+    <xsl:variable name="apostrophesEscaped">
+      <xsl:call-template name="replace-string">
+        <xsl:with-param name="text" select="$slashesEscaped"/>
+        <xsl:with-param name="replace" select="&quot;'&quot;"/>
+        <xsl:with-param name="with" select="&quot;\&apos;&quot;"/>
+      </xsl:call-template>
+    </xsl:variable>
+    <xsl:variable name="newlinesEscaped">
+      <xsl:call-template name="replace-string">
+        <xsl:with-param name="text" select="$apostrophesEscaped"/>
+        <xsl:with-param name="replace" select="'&#xA;'"/>
+        <xsl:with-param name="with" select="'\n'"/>
+      </xsl:call-template>
+    </xsl:variable>
+    <xsl:call-template name="escape-dash-dash">
+      <xsl:with-param name="text" select="$newlinesEscaped"/>
+      <xsl:with-param name="replace" select="'--'"/>
+      <xsl:with-param name="with" select='"-&apos; + &apos;-"'/>
+    </xsl:call-template>
+  </xsl:template>
+
+  <xsl:template name="escape-dash-dash">
+    <xsl:param name="text"/>
+    <xsl:variable name="tempText">
+      <xsl:call-template name="replace-string">
+        <xsl:with-param name="text" select="$text"/>
+        <xsl:with-param name="replace" select="'--'"/>
+        <xsl:with-param name="with" select='"-&apos; + &apos;-"'/>
+      </xsl:call-template>
+    </xsl:variable>
+    <xsl:choose>
+      <xsl:when test="contains($tempText, '--')">
+        <xsl:call-template name="escape-dash-dash">
+          <xsl:with-param name="text" select="$tempText"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="$tempText"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
 </xsl:stylesheet>

Modified: commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/TestSend.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/TestSend.xml?rev=981100&r1=981099&r2=981100&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/TestSend.xml (original)
+++ commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/TestSend.xml Sat Jul 31 22:34:10 2010
@@ -21,7 +21,7 @@
 	profile="ecmascript">
 
 	<initial>
-		<transition target="a1"/>
+		<transition target="a"/>
 	</initial>
 
 	<datamodel>
@@ -32,19 +32,19 @@
 
 	<!-- given event foo.bar, foo should be selected, and we should end in state b1-->
 	<state id="a">
-		<transition id="b2" event="t1">
+		<transition target="b" event="t1">
 			<send target="http://www.google.com"/>
 		</transition>
 	</state>
 
 	<state id="b">
-		<transition id="c" event="t2">
+		<transition target="c" event="t2">
 			<send target="http://www.google.com" namelist="foo bar"/>
 		</transition>
 	</state>
 
 	<state id="c">
-		<transition id="d" event="t3">
+		<transition target="d" event="t3">
 			<!-- namelist foo should take priority over param foo,
 				default expression in bar should be ignored, as it's already defined in the data model,
 				and bat is not defined, so should here use the value 'default3' --> 
@@ -57,7 +57,7 @@
 	</state>
 	
 	<state id="d">
-		<transition id="e" event="t4">
+		<transition target="e" event="t4">
 			<!-- try with JSON data -->
 			<send target="http://www.google.com">
 				<content><![CDATA[
@@ -72,7 +72,7 @@
 	</state>
 
 	<state id="e">
-		<transition id="f" event="t5">
+		<transition target="f" event="t5">
 			<!-- try it with some arbirary XML content, here a bit of XSL -->
 			<send target="http://www.google.com">
 				<content>

Modified: commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/test_with_xsltproc.sh
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/test_with_xsltproc.sh?rev=981100&r1=981099&r2=981100&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/test_with_xsltproc.sh (original)
+++ commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/test_with_xsltproc.sh Sat Jul 31 22:34:10 2010
@@ -1,6 +1,7 @@
 #!/bin/sh
 #cat prefix_events/TestPrefixEvents.xml | \
-cat simple2.xml | \
+cat send/TestSend.xml | \
+#cat kitchen_sink/KitchenSink.xml | \
 xsltproc ../src/xslt/ir-compiler/normalizeInitialStates.xsl - | \
 xsltproc ../src/xslt/ir-compiler/generateUniqueStateIds.xsl - | \
 xsltproc ../src/xslt/ir-compiler/generateUniqueInitialStateIds.xsl - | \
@@ -20,10 +21,16 @@ xsltproc ../src/xslt/ir-compiler/addEven
 xsltproc ../src/xslt/ir-compiler/expandStarEvent.xsl - | \
 #
 xsltproc ../src/xslt/ir-compiler/numberStatesAndTransitions.xsl - | \
+#
+xsltproc ../src/xslt/ir-compiler/external_communications/splitNamelist.xsl - | \
+xsltproc ../src/xslt/ir-compiler/external_communications/filterParams.xsl - | \
+#xsltproc ../src/xslt/ir-compiler/external_communications/sendToMessageTemplate.xsl - | \
 xmlindent > tmp_IR.xml;
+#cat > tmp_IR.xml;
 
+xsltproc ../src/xslt/ir-compiler/external_communications/genMessageTemplates.xsl tmp_IR.xml > out.js
 #uncomment to compile IR to js
-xsltproc ../build/StateTableStatechartGenerator_combined.xsl tmp_IR.xml > out.js
+#xsltproc ../build/StateTableStatechartGenerator_combined.xsl tmp_IR.xml > out.js
 
 #uncomment to prettify js. need to have beautify.js, beautify-cl.js and beautify-html.js in this directory
 #java -cp ../lib/java/js.jar org.mozilla.javascript.tools.shell.Main -debug beautify-cl.js -i 4 out.js > out_pretty.js