shindig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddum...@apache.org
Subject svn commit: r1351753 - in /shindig/trunk: content/samplecontainer/examples/ content/samplecontainer/examples/embeddedexperiences/ features/ features/src/main/javascript/features/actions/ features/src/main/javascript/features/open-views.ee/ features/src...
Date Tue, 19 Jun 2012 15:52:51 GMT
Author: ddumont
Date: Tue Jun 19 15:52:50 2012
New Revision: 1351753

URL: http://svn.apache.org/viewvc?rev=1351753&view=rev
Log:
SHINDIG-1798 - Best effort support for open-views.ee getting a string dataModel

Added:
    shindig/trunk/content/samplecontainer/examples/OpenViews-OpenEE.xml   (with props)
    shindig/trunk/features/src/test/javascript/features/json-xmltojson/
    shindig/trunk/features/src/test/javascript/features/json-xmltojson/jsonxmltojson-test.js
  (with props)
Modified:
    shindig/trunk/content/samplecontainer/examples/embeddedexperiences/PhotoList.xml
    shindig/trunk/features/pom.xml
    shindig/trunk/features/src/main/javascript/features/actions/actions_container.js
    shindig/trunk/features/src/main/javascript/features/actions/feature.xml
    shindig/trunk/features/src/main/javascript/features/open-views.ee/feature.xml
    shindig/trunk/features/src/main/javascript/features/open-views.ee/open-views-ee-container.js
    shindig/trunk/features/src/main/javascript/features/open-views.ee/open-views-ee-gadget.js
    shindig/trunk/features/src/test/javascript/features/alltests.js

Added: shindig/trunk/content/samplecontainer/examples/OpenViews-OpenEE.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/OpenViews-OpenEE.xml?rev=1351753&view=auto
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/OpenViews-OpenEE.xml (added)
+++ shindig/trunk/content/samplecontainer/examples/OpenViews-OpenEE.xml Tue Jun 19 15:52:50
2012
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Module specificationVersion="2.0">
+  <ModulePrefs title="OpenViews-OpenEE">
+    <Require feature="open-views"/>
+  </ModulePrefs>
+  <Content type="html"><![CDATA[
+    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
+    <script type="text/javascript">
+      gadgets.util.registerOnLoadHandler(function() {
+	      $(document).ready(function(){
+	        $('input#xml').click(function(event) {
+	          var dataModel = '<embed><url>http://www.opensocial.org</url></embed>';
+	          gadgets.views.openEmbeddedExperience(null, null, dataModel);
+	        });
+	        $('input#obj').click(function(event) {
+	          var dataModel = {url:'http://www.opensocial.org'};
+	          gadgets.views.openEmbeddedExperience(null, null, dataModel);
+	        });
+	      });
+	    });
+    </script>
+    <body>
+      <input id="xml" type="button" value="Open EE with XMl"></input>
+      <input id="obj" type="button" value="Open EE with Object"></input>
+    </body>
+  ]]></Content>
+</Module>
\ No newline at end of file

Propchange: shindig/trunk/content/samplecontainer/examples/OpenViews-OpenEE.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shindig/trunk/content/samplecontainer/examples/OpenViews-OpenEE.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: shindig/trunk/content/samplecontainer/examples/embeddedexperiences/PhotoList.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/embeddedexperiences/PhotoList.xml?rev=1351753&r1=1351752&r2=1351753&view=diff
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/embeddedexperiences/PhotoList.xml (original)
+++ shindig/trunk/content/samplecontainer/examples/embeddedexperiences/PhotoList.xml Tue Jun
19 15:52:50 2012
@@ -57,7 +57,7 @@
          var context;
          function createAlbumHTML(context){
              window.context=context;
-             var photos = context.photoUrls;
+             var photos = [].concat(context.photoUrls);
              var result = "";
              for(var i = 0; i < photos.length; i++){
                  count = i+1;
@@ -71,26 +71,6 @@
          });
 
          function showPreviewPhoto(index, eeGadget) {
-
-            var eeDataModel = {
-                'gadget' : eeGadget,
-                'context' : {
-                  "albumName": context.albumName,
-                  "photoUrls": [context.photoUrls[index]]
-              }
-            };
-
-            // Test the use case of Url data model
-            if (index == context.photoUrls.length-1) {
-              eeDataModel = {
-                'url' : context.photoUrls[index],
-                'context' : {
-                  "albumName": context.albumName,
-                  "photoUrls": [context.photoUrls[index]]
-                }
-              };
-            }
-
             var coordinates = $('#photo' + index).offset();
             coordinates.left = coordinates.left + $('#photo' + index).width();
 
@@ -101,6 +81,27 @@
             var returnCallback = function(returnValue){
               console.log("Return Value: " + returnValue);
             };
+            
+            var eeDataModel;
+            // Test the use case of Url data model
+            if (index == context.photoUrls.length-1) {
+              eeDataModel =
+                  '<embed>'
+                +   '<url>' + context.photoUrls[index] + '</url>'
+                +   '<context>'
+                +     '<albumName>' + context.albumName + '</albumName>'
+                +     '<photoUrls>' + context.photoUrls[index] + '</photoUrls>'
+                +   '</context>'
+                + '</embed>';
+            } else {
+              eeDataModel = {
+                gadget: eeGadget,
+                context: {
+                  albumName: context.albumName,
+                  photoUrls: [context.photoUrls[index]]
+                }
+              };
+            }
             gadgets.views.openEmbeddedExperience(returnCallback, navigateCallback, eeDataModel,
{
               'viewTarget' : index == 0 ? 'preview' : 'FLOAT',
               'coordinates' : coordinates

Modified: shindig/trunk/features/pom.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/features/pom.xml?rev=1351753&r1=1351752&r2=1351753&view=diff
==============================================================================
--- shindig/trunk/features/pom.xml (original)
+++ shindig/trunk/features/pom.xml Tue Jun 19 15:52:50 2012
@@ -214,6 +214,7 @@
                 <source>open-views.ee/open-views-ee-gadget.js</source>
                 <source>open-views.results/open-views-results-container.js</source>
                 <source>open-views.results/open-views-results-gadget.js</source>
+                <source>gadgets.json.ext/json-xmltojson.js</source>
               </sources>
               <testSourceDirectory>${basedir}/src/test/javascript/features</testSourceDirectory>
               <testSuites>

Modified: shindig/trunk/features/src/main/javascript/features/actions/actions_container.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/actions/actions_container.js?rev=1351753&r1=1351752&r2=1351753&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/actions/actions_container.js (original)
+++ shindig/trunk/features/src/main/javascript/features/actions/actions_container.js Tue Jun
19 15:52:50 2012
@@ -319,43 +319,6 @@
   };
 
   /**
-   * Utility function for converting a string representation of XML to a DOM
-   * object
-   *
-   * @param {String}
-   *          xmlString String representation of a valid XML object.
-   * @return {Object} response JSON object whose "data" field will contain the
-   *          DOM object, otherwise, the "errors" field will contain a string
-   *          description.
-   */
-  function createDom(xmlString) {
-    var response = {};
-    var dom;
-    if (typeof ActiveXObject != 'undefined') {
-      dom = new ActiveXObject('Microsoft.XMLDOM');
-      dom.async = false;
-      dom.validateOnParse = false;
-      dom.resolveExternals = false;
-      if (!dom.loadXML(xmlString)) {
-        response.errors = "500 Failed to parse XML";
-        response.rc = 500;
-      } else {
-        response['data'] = dom;
-      }
-    } else {
-      var parser = new DOMParser();
-      dom = parser.parseFromString(xmlString, 'application/xml');
-      if ('parsererror' === dom.documentElement.nodeName) {
-        response.errors = "500 Failed to parse XML";
-        response.rc = 500;
-      } else {
-        response['data'] = dom;
-      }
-    }
-    return response;
-  }
-
-  /**
    * Container handling of an action that has been programmatically added via
    * gadgets.actions.addAction() API
    *
@@ -551,12 +514,15 @@
       // http://code.google.com/p/opensocial-resources/issues/detail?id=1264
       desc = fixActionContributions(desc);
 
-      var domResponse = createDom(desc);
-      if (!domResponse || domResponse.errors) {
+      var dom;
+      try {
+        dom = opensocial.xmlutil.parseXML(desc);
+      } catch(ignore){}
+      if (!dom) {
         continue; // bail
       }
 
-      var jsonDesc = gadgets.json.xml.convertXmlToJson(domResponse['data']),
+      var jsonDesc = gadgets.json.xml.convertXmlToJson(dom),
           actionsJson = jsonDesc['actions'];
       if (!actionsJson) {
         continue; // bail

Modified: shindig/trunk/features/src/main/javascript/features/actions/feature.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/actions/feature.xml?rev=1351753&r1=1351752&r2=1351753&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/actions/feature.xml (original)
+++ shindig/trunk/features/src/main/javascript/features/actions/feature.xml Tue Jun 19 15:52:50
2012
@@ -22,6 +22,7 @@
   <dependency>globals</dependency>
   <dependency>rpc</dependency>
   <dependency>gadgets.json.ext</dependency>
+  <dependency>xmlutil</dependency>
   <gadget>
     <script src="actions.js"/>
     <script src="taming.js"/>

Modified: shindig/trunk/features/src/main/javascript/features/open-views.ee/feature.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/open-views.ee/feature.xml?rev=1351753&r1=1351752&r2=1351753&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/open-views.ee/feature.xml (original)
+++ shindig/trunk/features/src/main/javascript/features/open-views.ee/feature.xml Tue Jun
19 15:52:50 2012
@@ -23,6 +23,8 @@ specific language governing permissions 
   <dependency>container.site.gadget</dependency>
   <dependency>container.site.url</dependency>
   <dependency>embedded-experiences</dependency>
+  <dependency>gadgets.json.ext</dependency>
+  <dependency>xmlutil</dependency>
   <gadget>
     <script src="open-views-ee-gadget.js"/>
     <api>

Modified: shindig/trunk/features/src/main/javascript/features/open-views.ee/open-views-ee-container.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/open-views.ee/open-views-ee-container.js?rev=1351753&r1=1351752&r2=1351753&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/open-views.ee/open-views-ee-container.js
(original)
+++ shindig/trunk/features/src/main/javascript/features/open-views.ee/open-views-ee-container.js
Tue Jun 19 15:52:50 2012
@@ -33,8 +33,9 @@ osapi.container.Container.addMixin('view
    *          resultCallback: Callback function id to be called when the embedded
    *          experience closes. The function will be called with the return
    *          value as a parameter.
-   * @param {Object}
-   *          dataModel: The embedded experiences data model.
+   * @param {Object|string}
+   *          dataModel: The embedded experiences data model object or the xml or
+   *          json string representation of that data model.
    * @param {Object}
    *          opt_params: These are optional parameters which can be used to
    *            open gadgets. The following parameters may be included in this
@@ -60,6 +61,21 @@ osapi.container.Container.addMixin('view
         siteOwnerId = rpcArgs.f,
         gadgetUrl = dataModel.gadget;
 
+    if (typeof(dataModel) == 'string') {
+      var match = new RegExp('^<(embed)>', 'i').exec(dataModel);
+      if (match && match[1]) {
+        try {
+          var parsed = gadgets.json.xml.convertXmlToJson(opensocial.xmlutil.parseXML(dataModel));
+          dataModel = parsed && parsed[match[1]] || dataModel;
+        } catch(ignore){}
+      } else {
+        try {
+          var parsed = gadgets.json.parse(dataModel);
+          dataModel = parsed || dataModel;
+        } catch(ignore){}
+      }
+    }
+
     var navigateEE = function(opt_metadata) {
       var viewTarget = '',
           viewParams = {},

Modified: shindig/trunk/features/src/main/javascript/features/open-views.ee/open-views-ee-gadget.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/open-views.ee/open-views-ee-gadget.js?rev=1351753&r1=1351752&r2=1351753&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/open-views.ee/open-views-ee-gadget.js
(original)
+++ shindig/trunk/features/src/main/javascript/features/open-views.ee/open-views-ee-gadget.js
Tue Jun 19 15:52:50 2012
@@ -35,8 +35,9 @@ gadgets.views = gadgets.views || {};
  * @param {function}
  *          navigateCallback: Callback function to be called with the site and
  *          gadget metadata.
- * @param {function}
- *          dataModel: The embedded experiences data model.
+ * @param {Object|string}
+ *          dataModel: The embedded experiences data model object or the xml or
+ *          json string representation of that data model.
  * @param {Object}
  *          opt_params: These are optional parameters which can be used to
  *            open gadgets. The following parameters may be included in this

Modified: shindig/trunk/features/src/test/javascript/features/alltests.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/test/javascript/features/alltests.js?rev=1351753&r1=1351752&r2=1351753&view=diff
==============================================================================
--- shindig/trunk/features/src/test/javascript/features/alltests.js (original)
+++ shindig/trunk/features/src/test/javascript/features/alltests.js Tue Jun 19 15:52:50 2012
@@ -105,6 +105,7 @@ if (!this.JsUtil) {
   eval(JsUtil.prototype.include(srcDir + '/osapi.base/batch.js'));
   eval(JsUtil.prototype.include(srcDir + '/osapi/jsonrpctransport.js'));
   eval(JsUtil.prototype.include(srcDir + '/osapi/peoplehelpers.js'));
+  eval(JsUtil.prototype.include(srcDir + '/gadgets.json.ext/json-xmltojson.js;));
   eval(JsUtil.prototype.include(testToolsDir + "/JsUnit.js"));
   eval(JsUtil.prototype.include(testToolsDir + '/testutils.js'));
   eval(JsUtil.prototype.include(testSrcDir + "/core/authtest.js"));
@@ -132,6 +133,7 @@ if (!this.JsUtil) {
   eval(JsUtil.prototype.include(testSrcDir + '/container/gadget_holder_test.js'));
   eval(JsUtil.prototype.include(testSrcDir + '/container/gadget_site_test.js'));
   eval(JsUtil.prototype.include(testSrcDir + '/container/container_test.js'));
+  eval(JsUtil.prototype.include(testSrcDir + '/json-xmltojson/jsonxmltojson-test.js'));
 }
 
 function AllTests() {

Added: shindig/trunk/features/src/test/javascript/features/json-xmltojson/jsonxmltojson-test.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/test/javascript/features/json-xmltojson/jsonxmltojson-test.js?rev=1351753&view=auto
==============================================================================
--- shindig/trunk/features/src/test/javascript/features/json-xmltojson/jsonxmltojson-test.js
(added)
+++ shindig/trunk/features/src/test/javascript/features/json-xmltojson/jsonxmltojson-test.js
Tue Jun 19 15:52:50 2012
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+function JsonXmlToJsonTest(name) {
+  TestCase.call(this, name); // super
+}
+JsonXmlToJsonTest.inherits(TestCase);
+JsonXmlToJsonTest.prototype.setUp = function() {};
+JsonXmlToJsonTest.prototype.tearDown = function() {};
+
+JsonXmlToJsonTest.prototype.testConvertXmlToJson = function() {
+  var fakeDom = {
+    nodeName: '#document',
+    nodeType: 9,
+    attributes: [],
+    childNodes: [{
+      nodeName: 'embed',
+      nodeType: 1,
+      attributes: [],
+      childNodes: [{
+        nodeName: 'url',
+        nodeType: 1,
+        attributes: [],
+        childNodes: [{
+          nodeName: '#text',
+          attributes: [],
+          nodeType: 3,
+          nodeValue: 'http://www.example.com'
+        }]
+      }]
+    }]
+  };
+  fakeDom.firstChild = fakeDom.childNodes[0];
+  fakeDom.firstChild.firstChild = fakeDom.firstChild.childNodes[0];
+  fakeDom.firstChild.firstChild.firstChild = fakeDom.firstChild.firstChild.childNodes[0];
+
+  var result = gadgets.json.xml.convertXmlToJson(fakeDom),
+      expected = {embed:{url:'http://www.example.com'}};
+  this.assertEquals(expected, result);
+};
\ No newline at end of file

Propchange: shindig/trunk/features/src/test/javascript/features/json-xmltojson/jsonxmltojson-test.js
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shindig/trunk/features/src/test/javascript/features/json-xmltojson/jsonxmltojson-test.js
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message