You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by jo...@apache.org on 2010/12/07 04:01:29 UTC

svn commit: r1042895 - in /shindig/trunk/features: ./ src/main/javascript/features/core.json/ src/test/javascript/features/ src/test/javascript/features/opensocial-templates/

Author: johnh
Date: Tue Dec  7 03:01:28 2010
New Revision: 1042895

URL: http://svn.apache.org/viewvc?rev=1042895&view=rev
Log:
Split core.json implementation into 3 files with equivalent logic:
* Native window.JSON pass through impl
* JS port impl
* gadgets.json.flatten helper

This helps pave the way to browser-specific gadgets.json for modern browsers, reducing payload size.


Added:
    shindig/trunk/features/src/main/javascript/features/core.json/json-flatten.js
    shindig/trunk/features/src/main/javascript/features/core.json/json-jsimpl.js
      - copied, changed from r1042832, shindig/trunk/features/src/main/javascript/features/core.json/json.js
    shindig/trunk/features/src/main/javascript/features/core.json/json-native.js
Removed:
    shindig/trunk/features/src/main/javascript/features/core.json/json.js
Modified:
    shindig/trunk/features/pom.xml
    shindig/trunk/features/src/main/javascript/features/core.json/feature.xml
    shindig/trunk/features/src/test/javascript/features/alltests.js
    shindig/trunk/features/src/test/javascript/features/opensocial-templates/index.html

Modified: shindig/trunk/features/pom.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/features/pom.xml?rev=1042895&r1=1042894&r2=1042895&view=diff
==============================================================================
--- shindig/trunk/features/pom.xml (original)
+++ shindig/trunk/features/pom.xml Tue Dec  7 03:01:28 2010
@@ -109,7 +109,9 @@
                 <source>core.config/config.js</source>
                 <source>core.config/configcontainer.js</source>
                 <source>core.config/configgadget.js</source>
-                <source>core.json/json.js</source>
+                <source>core.json/json-native.js</source>
+                <source>core.json/json-jsimpl.js</source>
+                <source>core.json/json-flatten.js</source>
                 <source>shindig.auth/auth.js</source>
                 <source>core.util/util.js</source>
                 <source>core.prefs/prefs.js</source>

Modified: shindig/trunk/features/src/main/javascript/features/core.json/feature.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/core.json/feature.xml?rev=1042895&r1=1042894&r2=1042895&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/core.json/feature.xml (original)
+++ shindig/trunk/features/src/main/javascript/features/core.json/feature.xml Tue Dec  7 03:01:28 2010
@@ -20,11 +20,15 @@
   <name>core.json</name>
   <dependency>globals</dependency>
   <gadget>
-    <script src="json.js"/>
+    <script src="json-native.js"/>
+    <script src="json-jsimpl.js"/>
+    <script src="json-flatten.js"/>
     <script src="taming.js"/>
   </gadget>
   <container>
-    <script src="json.js"/>
+    <script src="json-native.js"/>
+    <script src="json-jsimpl.js"/>
+    <script src="json-flatten.js"/>
     <script src="taming.js"/>
   </container>
 </feature>

Added: shindig/trunk/features/src/main/javascript/features/core.json/json-flatten.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/core.json/json-flatten.js?rev=1042895&view=auto
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/core.json/json-flatten.js (added)
+++ shindig/trunk/features/src/main/javascript/features/core.json/json-flatten.js Tue Dec  7 03:01:28 2010
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+/**
+ * Flatten an object to a stringified values. Useful for dealing with
+ * json->querystring transformations. Note: not in official specification yet
+ *
+ * @param {Object} obj
+ * @return {Object} object with only string values.
+ */
+gadgets['json'].flatten = function(obj) {
+  var flat = {};
+
+  if (obj === null || obj === undefined) return flat;
+
+  for (var k in obj) {
+    if (obj.hasOwnProperty(k)) {
+      var value = obj[k];
+      if (null === value || undefined === value) {
+        continue;
+      }
+      flat[k] = (typeof value === 'string') ? value : gadgets.json.stringify(value);
+    }
+  }
+  return flat;
+};

Copied: shindig/trunk/features/src/main/javascript/features/core.json/json-jsimpl.js (from r1042832, shindig/trunk/features/src/main/javascript/features/core.json/json.js)
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/core.json/json-jsimpl.js?p2=shindig/trunk/features/src/main/javascript/features/core.json/json-jsimpl.js&p1=shindig/trunk/features/src/main/javascript/features/core.json/json.js&r1=1042832&r2=1042895&rev=1042895&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/core.json/json.js (original)
+++ shindig/trunk/features/src/main/javascript/features/core.json/json-jsimpl.js Tue Dec  7 03:01:28 2010
@@ -35,41 +35,15 @@
  */
 
 /**
+ * JavaScript-based implementation when window.JSON is not present.
  * Port of the public domain JSON library by Douglas Crockford.
  * See: http://www.json.org/json2.js
  */
-if (window.JSON && window.JSON.parse && window.JSON.stringify) {
-  // HTML5 implementation, or already defined.
-  // Not a direct alias as the opensocial specification disagrees with the HTML5 JSON spec.
-  // JSON says to throw on parse errors and to support filtering functions. OS does not.
-  gadgets['json'] = (function() {
-    var endsWith___ = /___$/;
-    return {
-      /* documented below */
-      'parse': function(str) {
-        try {
-          return window.JSON.parse(str);
-        } catch (e) {
-          return false;
-        }
-      },
-      /* documented below */
-      'stringify': function(obj) {
-        try {
-          return window.JSON.stringify(obj, function(k,v) {
-            return !endsWith___.test(k) ? v : null;
-          });
-        } catch (e) {
-          return null;
-        }
-      }
-    };
-  })();
-} else {
+if (!(window.JSON && window.JSON.parse && window.JSON.stringify)) {
   /**
- * Port of the public domain JSON library by Douglas Crockford.
- * See: http://www.json.org/json2.js
- */
+   * Port of the public domain JSON library by Douglas Crockford.
+   * See: http://www.json.org/json2.js
+   */
   gadgets['json'] = function() {
 
     /**
@@ -207,27 +181,3 @@ if (window.JSON && window.JSON.parse && 
     };
   }();
 }
-/**
- * Flatten an object to a stringified values. Useful for dealing with
- * json->querystring transformations. Note: not in official specification yet
- *
- * @param {Object} obj
- * @return {Object} object with only string values.
- */
-
-gadgets['json'].flatten = function(obj) {
-  var flat = {};
-
-  if (obj === null || obj === undefined) return flat;
-
-  for (var k in obj) {
-    if (obj.hasOwnProperty(k)) {
-      var value = obj[k];
-      if (null === value || undefined === value) {
-        continue;
-      }
-      flat[k] = (typeof value === 'string') ? value : gadgets.json.stringify(value);
-    }
-  }
-  return flat;
-};

Added: shindig/trunk/features/src/main/javascript/features/core.json/json-native.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/core.json/json-native.js?rev=1042895&view=auto
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/core.json/json-native.js (added)
+++ shindig/trunk/features/src/main/javascript/features/core.json/json-native.js Tue Dec  7 03:01:28 2010
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+/**
+ * @fileoverview
+ * The global object gadgets.json contains two methods.
+ *
+ * gadgets.json.stringify(value) takes a JavaScript value and produces a JSON
+ * text. The value must not be cyclical.
+ *
+ * gadgets.json.parse(text) takes a JSON text and produces a JavaScript value.
+ * It will return false if there is an error.
+ */
+
+/**
+ * @static
+ * @class Provides operations for translating objects to and from JSON.
+ * @name gadgets.json
+ */
+
+/**
+ * Just wrap native JSON calls when available.
+ */
+if (window.JSON && window.JSON.parse && window.JSON.stringify) {
+  // HTML5 implementation, or already defined.
+  // Not a direct alias as the opensocial specification disagrees with the HTML5 JSON spec.
+  // JSON says to throw on parse errors and to support filtering functions. OS does not.
+  gadgets['json'] = (function() {
+    var endsWith___ = /___$/;
+    return {
+      /* documented below */
+      'parse': function(str) {
+        try {
+          return window.JSON.parse(str);
+        } catch (e) {
+          return false;
+        }
+      },
+      /* documented below */
+      'stringify': function(obj) {
+        try {
+          return window.JSON.stringify(obj, function(k,v) {
+            return !endsWith___.test(k) ? v : null;
+          });
+        } catch (e) {
+          return null;
+        }
+      }
+    };
+  })();
+}

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=1042895&r1=1042894&r2=1042895&view=diff
==============================================================================
--- shindig/trunk/features/src/test/javascript/features/alltests.js (original)
+++ shindig/trunk/features/src/test/javascript/features/alltests.js Tue Dec  7 03:01:28 2010
@@ -36,7 +36,9 @@ if (!this.JsUtil) {
   eval(JsUtil.prototype.include(testSrcDir + '/mocks/env.js'));
   eval(JsUtil.prototype.include(testSrcDir + '/mocks/xhr.js'));
   eval(JsUtil.prototype.include(srcDir + '/core/config.js'));
-  eval(JsUtil.prototype.include(srcDir + '/core/json.js'));
+  eval(JsUtil.prototype.include(srcDir + '/core/json-native.js'));
+  eval(JsUtil.prototype.include(srcDir + '/core/json-jsimpl.js'));
+  eval(JsUtil.prototype.include(srcDir + '/core/json-flatten.js'));
   eval(JsUtil.prototype.include(srcDir + '/core/auth.js'));
   eval(JsUtil.prototype.include(srcDir + '/core/util.js'));
   eval(JsUtil.prototype.include(srcDir + '/core/prefs.js'));

Modified: shindig/trunk/features/src/test/javascript/features/opensocial-templates/index.html
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/test/javascript/features/opensocial-templates/index.html?rev=1042895&r1=1042894&r2=1042895&view=diff
==============================================================================
--- shindig/trunk/features/src/test/javascript/features/opensocial-templates/index.html (original)
+++ shindig/trunk/features/src/test/javascript/features/opensocial-templates/index.html Tue Dec  7 03:01:28 2010
@@ -49,7 +49,9 @@ under the License.
     <script src="../../../../main/javascript/features/opensocial-data-context/datacontext.js"></script>
     <script src="../../../../main/javascript/features/jsondom/jsondom.js"></script>
     <script src="../../../../main/javascript/features/xmlutil/xmlutil.js"></script>
-    <script src="../../../../main/javascript/features/core.json/json.js"></script>
+    <script src="../../../../main/javascript/features/core.json/json-native.js"></script>
+    <script src="../../../../main/javascript/features/core.json/json-jsimpl.js"></script>
+    <script src="../../../../main/javascript/features/core.json/json-flatten.js"></script>
     <script src="../../../../main/javascript/features/core.util/util.js"></script>
     <script src="../../../../main/javascript/features/opensocial-data/data.js"></script>
     <script src="../../../../main/javascript/features/opensocial-templates/base.js"></script>