Author: jbeard
Date: Sat Jul 31 22:33:21 2010
New Revision: 981097

URL: http://svn.apache.org/viewvc?rev=981097&view=rev
Log:
Initial commit of code for external communications module. This code is 
untested, but should generate message templates.

Added:
    
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/javascript/scxml/cgf/util/external_communications/
    
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/javascript/scxml/cgf/util/external_communications/jquery.js
   (with props)
    
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/javascript/scxml/cgf/util/external_communications/rhino.js
   (with props)
    
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/
    
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/filterParams.xsl
   (with props)
    
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/genMessageTemplates.xsl
   (with props)
    
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/sendToMessageTemplate.xsl
   (with props)
    
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/splitNamelist.xsl
   (with props)

Added: 
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=981097&view=auto
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/javascript/scxml/cgf/util/external_communications/jquery.js
 (added)
+++ 
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:33:21 2010
@@ -0,0 +1,32 @@
+require.def("src/javascript/scxml/cgf/util/external_communications/jquery",
+["lib/js/jquery.js"],
+function(){
+       //fixme: json or xml? how do we handle the difference for get? for post?
+       return {
+               get : function(url){
+                       var toReturn;
+                       $.ajax({
+                               url:url,
+                               success: function(result) {
+                                       toReturn = result;
+                               },
+                               async:false
+                       });
+                       return toReturn;
+               },
+               post : function(url,data){
+                       var toReturn;
+                       $.ajax({
+                               type:'POST',
+                               url:url,
+                               success: function(result) {
+                                       toReturn = result;
+                               },
+                               data:data,
+                               async:false
+                       });
+                       return toReturn;
+               }
+       }
+})
+

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

Added: 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/javascript/scxml/cgf/util/external_communications/rhino.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/rhino.js?rev=981097&view=auto
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/javascript/scxml/cgf/util/external_communications/rhino.js
 (added)
+++ 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/javascript/scxml/cgf/util/external_communications/rhino.js
 Sat Jul 31 22:33:21 2010
@@ -0,0 +1,53 @@
+require.def("src/javascript/scxml/cgf/util/external_communications/rhino",
+function(){
+       //fixme: json or xml? how do we handle the difference for get? for post?
+
+       importClass(Packages.org.apache.http.NameValuePair);
+       importClass(Packages.org.apache.http.HttpResponse);
+       importClass(Packages.org.apache.http.protocol.BasicHttpContext);
+       importClass(Packages.org.apache.http.protocol.HttpContext);
+       importClass(Packages.org.apache.http.client.methods.HttpGet);
+       importClass(Packages.org.apache.http.client.methods.HttpPost);
+       
importClass(Packages.org.apache.http.client.entity.UrlEncodedFormEntity);
+       importClass(Packages.org.apache.http.util.EntityUtils);
+       importClass(Packages.org.apache.http.impl.client.DefaultHttpClient);
+       importClass(Packages.org.apache.http.message.BasicNameValuePair);
+       
+       return {
+               get : function(url){
+                       var toReturn = "";
+
+                       var httpget = new HttpGet(url);
+                       
+                       httpclient = new DefaultHttpClient();
+                       localContext = new BasicHttpContext();
+
+                       response = httpclient.execute(httpget, localContext);
+
+                       entity = response.getEntity();
+                       if (entity != null) {
+                               toReturn = String(EntityUtils.toString(entity));
+                       }
+                       
+                       return toReturn;
+               },
+               post : function(url,data){
+
+                       var httpPost = new HttpPost(url);
+                       
+                       var httpclient = new DefaultHttpClient();
+                       var localContext = new BasicHttpContext();
+                       
+                       /*
+                       List<NameValuePair> formparams = new ArrayList();
+                       formparams.add(new BasicNameValuePair("x", "200"));
+                       UrlEncodedFormEntity entity = new 
UrlEncodedFormEntity(formparams, "UTF-8");
+                       
+                       httpPost.setEntity(entity);
+                       */
+
+                       HttpResponse response = httpclient.execute(httpPost, 
localContext);
+               }
+       }
+})
+

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

Added: 
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=981097&view=auto
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/filterParams.xsl
 (added)
+++ 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/filterParams.xsl
 Sat Jul 31 22:33:21 2010
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
+       xmlns:s="http://www.w3.org/2005/07/scxml";
+       xmlns="http://www.w3.org/2005/07/scxml";
+       xmlns:c="http://commons.apache.org/scxml-js";
+       version="1.0">
+       <xsl:output method="xml"/>
+
+       <!-- identity transform -->
+       <xsl:template match="@*|node()">
+          <xsl:copy>
+             <xsl:apply-templates select="@*|node()"/>
+          </xsl:copy>
+       </xsl:template>
+
+       <xsl:template match="s:send">
+               <xsl:variable name="namelistNodes" 
select="c:namelist/c:name/text()"/>
+
+               <xsl:copy>
+                       <xsl:apply-templates select="@*"/>
+
+                       <xsl:apply-templates select="param[not(@name = 
$namelistNodes)]"/>
+
+                       <xsl:apply-templates select="node()[not(self::param)]"/>
+               </xsl:copy>
+       </xsl:template>
+
+</xsl:stylesheet>
+
+
+
+
+

Propchange: 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/filterParams.xsl
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
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=981097&view=auto
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/genMessageTemplates.xsl
 (added)
+++ 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/genMessageTemplates.xsl
 Sat Jul 31 22:33:21 2010
@@ -0,0 +1,85 @@
+<?xml version="1.0"?>
+
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
+       xmlns:s="http://www.w3.org/2005/07/scxml";
+       xmlns="http://www.w3.org/2005/07/scxml";
+       xmlns:c="http://commons.apache.org/scxml-js";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       version="1.0">
+    <xsl:output method="xml"/>
+    
+    <xsl:template match="c:messageTemplate">
+        <xsl:text>function(</xsl:text>
+        <xsl:for-each select=".//c:param">
+            <xsl:value-of select="@name"/>
+            <xsl:if test="not(position() = last())">
+                <xsl:text>,</xsl:text>
+            </xsl:if>
+        </xsl:for-each>
+        <xsl:text>){</xsl:text>
+        <xsl:text>return &apos;</xsl:text><xsl:apply-templates 
select="node()"/>
+        <xsl:text>&apos;</xsl:text>
+        <xsl:text>}</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>
+    
+    
+</xsl:stylesheet>

Propchange: 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/genMessageTemplates.xsl
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
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=981097&view=auto
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/sendToMessageTemplate.xsl
 (added)
+++ 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/sendToMessageTemplate.xsl
 Sat Jul 31 22:33:21 2010
@@ -0,0 +1,108 @@
+<?xml version="1.0"?>
+
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
+       xmlns:s="http://www.w3.org/2005/07/scxml";
+       xmlns="http://www.w3.org/2005/07/scxml";
+       xmlns:c="http://commons.apache.org/scxml-js";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       version="1.0">
+       <xsl:output method="xml"/>
+
+       <!-- identity transform -->
+       <xsl:template match="@*|node()">
+               <xsl:copy>
+                       <xsl:apply-templates select="@*|node()"/>
+               </xsl:copy>
+       </xsl:template>
+
+       <xsl:template match="s:send">
+               <!-- where do we put xml messages templates? how do we map them 
to send? --> 
+               <!-- process namelist attribute,
+                       process params,
+                       content --> 
+               <xsl:copy>
+                       <xsl:apply-templates select="@*"/>
+
+
+                       <!-- TODO: 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 | param/@name">
+                                                                       
<property name="{.}">
+                                                                               
<c:param name="{.}"/>
+                                                                       
</property>
+                                                               </xsl:for-each>
+                                                       </xsl:otherwise>
+                                               </xsl:choose>
+                                       </payload>
+                               </message>
+                       </c:messageTemplate>
+
+                       <xsl:apply-templates select="node()"/>
+               </xsl:copy>
+       </xsl:template>
+</xsl:stylesheet>

Propchange: 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/sendToMessageTemplate.xsl
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
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=981097&view=auto
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/splitNamelist.xsl
 (added)
+++ 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/splitNamelist.xsl
 Sat Jul 31 22:33:21 2010
@@ -0,0 +1,50 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
+       xmlns:s="http://www.w3.org/2005/07/scxml";
+       xmlns="http://www.w3.org/2005/07/scxml";
+       xmlns:c="http://commons.apache.org/scxml-js";
+       version="1.0">
+       <xsl:output method="xml"/>
+
+       <!-- identity transform -->
+       <xsl:template match="@*|node()">
+          <xsl:copy>
+             <xsl:apply-templates select="@*|node()"/>
+          </xsl:copy>
+       </xsl:template>
+
+       <!-- recursive template -->
+       <xsl:template name="namelistAttributeToNodeList">
+           <xsl:param name="list" /> 
+           <xsl:variable name="newlist" select="concat(normalize-space($list), 
' ')" /> 
+           <xsl:variable name="first" select="substring-before($newlist, ' ')" 
/> 
+           <xsl:variable name="remaining" select="substring-after($newlist, ' 
')" /> 
+
+           <c:name>
+               <xsl:value-of select="$first" /> 
+           </c:name>
+
+           <xsl:if test="$remaining">
+               <xsl:call-template name="namelistAttributeToNodeList">
+                       <xsl:with-param name="list" select="$remaining" /> 
+               </xsl:call-template>
+           </xsl:if>
+       </xsl:template>
+
+       
+       <xsl:template match="s:send">
+               <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:copy>
+       </xsl:template>
+
+</xsl:stylesheet>
+
+
+
+

Propchange: 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/splitNamelist.xsl
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to