You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by do...@apache.org on 2008/03/25 14:30:53 UTC

svn commit: r640803 - in /incubator/shindig/trunk/javascript: ./ container/

Author: doll
Date: Tue Mar 25 06:30:48 2008
New Revision: 640803

URL: http://svn.apache.org/viewvc?rev=640803&view=rev
Log:
Separated out the cookies based user pref impl from gadgets.js. The cookie impl is not production safe and should not be used as a default implementation. However, the samples need something to work and so pull in this file separately. 

I replaced the default impl with an empty implementation. At some point in the future we need to replace this with something better.

In the future we should also consider separating all of the gadgets classes into their own files but this needs to go hand in hand with a general improvement to the overall framework. 


gadgets.js by itself is now production safe.



Added:
    incubator/shindig/trunk/javascript/container/cookiebaseduserprefstore.js
Modified:
    incubator/shindig/trunk/javascript/README
    incubator/shindig/trunk/javascript/container/gadgets.js
    incubator/shindig/trunk/javascript/container/sample1.html
    incubator/shindig/trunk/javascript/container/sample2.html
    incubator/shindig/trunk/javascript/container/sample3.html
    incubator/shindig/trunk/javascript/container/sample4.html
    incubator/shindig/trunk/javascript/container/sample5.html
    incubator/shindig/trunk/javascript/container/sample6.html
    incubator/shindig/trunk/javascript/container/sample7.html

Modified: incubator/shindig/trunk/javascript/README
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/README?rev=640803&r1=640802&r2=640803&view=diff
==============================================================================
--- incubator/shindig/trunk/javascript/README (original)
+++ incubator/shindig/trunk/javascript/README Tue Mar 25 06:30:48 2008
@@ -29,6 +29,7 @@
       <script type="text/javascript" src="../../js/rpc.js?c=1"></script>
       <script type="text/javascript" src="cookies.js"></script>
       <script type="text/javascript" src="gadgets.js"></script>
+      <script type="text/javascript" src="cookiebaseduserprefstore.js"></script>
 
    B) For each Gadget you wish to add to the page:
       i) Create it. Example, for Gadget whose spec is at http://foo.com/spec.xml

Added: incubator/shindig/trunk/javascript/container/cookiebaseduserprefstore.js
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/container/cookiebaseduserprefstore.js?rev=640803&view=auto
==============================================================================
--- incubator/shindig/trunk/javascript/container/cookiebaseduserprefstore.js (added)
+++ incubator/shindig/trunk/javascript/container/cookiebaseduserprefstore.js Tue Mar 25 06:30:48 2008
@@ -0,0 +1,69 @@
+/**
+ * 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 Implements the gadgets.UserPrefStore interface using a cookies
+ * based implementation. Depends on cookies.js. This code should not be used in
+ * a production environment.
+ */
+
+/**
+ * Cookie-based user preference store.
+ * @constructor
+ */
+gadgets.CookieBasedUserPrefStore = function() {
+  gadgets.UserPrefStore.call(this);
+};
+
+gadgets.CookieBasedUserPrefStore.inherits(gadgets.UserPrefStore);
+
+gadgets.CookieBasedUserPrefStore.prototype.USER_PREFS_PREFIX =
+    'gadgetUserPrefs-';
+
+gadgets.CookieBasedUserPrefStore.prototype.getPrefs = function(gadget) {
+  var userPrefs = {};
+  var cookieName = this.USER_PREFS_PREFIX + gadget.id;
+  var cookie = goog.net.cookies.get(cookieName);
+  if (cookie) {
+    var pairs = cookie.split('&');
+    for (var i = 0; i < pairs.length; i++) {
+      var nameValue = pairs[i].split('=');
+      var name = decodeURIComponent(nameValue[0]);
+      var value = decodeURIComponent(nameValue[1]);
+      userPrefs[name] = value;
+    }
+  }
+
+  return userPrefs;
+};
+
+gadgets.CookieBasedUserPrefStore.prototype.savePrefs = function(gadget) {
+  var pairs = [];
+  for (var name in gadget.getUserPrefs()) {
+    var value = gadget.getUserPref(name);
+    var pair = encodeURIComponent(name) + '=' + encodeURIComponent(value);
+    pairs.push(pair);
+  }
+
+  var cookieName = this.USER_PREFS_PREFIX + gadget.id;
+  var cookieValue = pairs.join('&');
+  goog.net.cookies.set(cookieName, cookieValue);
+};
+
+gadgets.Container.prototype.userPrefStore =
+    new gadgets.CookieBasedUserPrefStore();
\ No newline at end of file

Modified: incubator/shindig/trunk/javascript/container/gadgets.js
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/container/gadgets.js?rev=640803&r1=640802&r2=640803&view=diff
==============================================================================
--- incubator/shindig/trunk/javascript/container/gadgets.js (original)
+++ incubator/shindig/trunk/javascript/container/gadgets.js Tue Mar 25 06:30:48 2008
@@ -143,51 +143,22 @@
 };
 
 
-// ------------------------
-// CookieBasedUserPrefStore
+// -------------
+// DefaultUserPrefStore
 
 /**
- * Cookie-based user preference store.
+ * User preference store implementation.
+ * TODO: Turn this into a real implementation that is production safe
  * @constructor
  */
-gadgets.CookieBasedUserPrefStore = function() {
+gadgets.DefaultUserPrefStore = function() {
   gadgets.UserPrefStore.call(this);
 };
+gadgets.DefaultUserPrefStore.inherits(gadgets.UserPrefStore);
 
-gadgets.CookieBasedUserPrefStore.inherits(gadgets.UserPrefStore);
-
-gadgets.CookieBasedUserPrefStore.prototype.USER_PREFS_PREFIX =
-    'gadgetUserPrefs-';
-
-gadgets.CookieBasedUserPrefStore.prototype.getPrefs = function(gadget) {
-  var userPrefs = {};
-  var cookieName = this.USER_PREFS_PREFIX + gadget.id;
-  var cookie = goog.net.cookies.get(cookieName);
-  if (cookie) {
-    var pairs = cookie.split('&');
-    for (var i = 0; i < pairs.length; i++) {
-      var nameValue = pairs[i].split('=');
-      var name = decodeURIComponent(nameValue[0]);
-      var value = decodeURIComponent(nameValue[1]);
-      userPrefs[name] = value;
-    }
-  }
-
-  return userPrefs;
-};
-
-gadgets.CookieBasedUserPrefStore.prototype.savePrefs = function(gadget) {
-  var pairs = [];
-  for (var name in gadget.getUserPrefs()) {
-    var value = gadget.getUserPref(name);
-    var pair = encodeURIComponent(name) + '=' + encodeURIComponent(value);
-    pairs.push(pair);
-  }
+gadgets.DefaultUserPrefStore.prototype.getPrefs = function(gadget) { };
 
-  var cookieName = this.USER_PREFS_PREFIX + gadget.id;
-  var cookieValue = pairs.join('&');
-  goog.net.cookies.set(cookieName, cookieValue);
-};
+gadgets.DefaultUserPrefStore.prototype.savePrefs = function(gadget) { };
 
 
 // -------------
@@ -665,8 +636,7 @@
 
 gadgets.Container.prototype.gadgetClass = gadgets.Gadget;
 
-gadgets.Container.prototype.userPrefStore =
-    new gadgets.CookieBasedUserPrefStore();
+gadgets.Container.prototype.userPrefStore = new gadgets.DefaultUserPrefStore();
 
 gadgets.Container.prototype.gadgetService = new gadgets.GadgetService();
 

Modified: incubator/shindig/trunk/javascript/container/sample1.html
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/container/sample1.html?rev=640803&r1=640802&r2=640803&view=diff
==============================================================================
--- incubator/shindig/trunk/javascript/container/sample1.html (original)
+++ incubator/shindig/trunk/javascript/container/sample1.html Tue Mar 25 06:30:48 2008
@@ -7,6 +7,7 @@
 <script type="text/javascript" src="../../js/rpc.js?c=1&debug=1"></script>
 <script type="text/javascript" src="cookies.js"></script>
 <script type="text/javascript" src="gadgets.js"></script>
+<script type="text/javascript" src="cookiebaseduserprefstore.js"></script>
 <script type="text/javascript">
 var specUrl0 = 'http://www.google.com/ig/modules/horoscope.xml';
 var specUrl1 = 'http://www.labpixies.com/campaigns/todo/todo.xml';

Modified: incubator/shindig/trunk/javascript/container/sample2.html
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/container/sample2.html?rev=640803&r1=640802&r2=640803&view=diff
==============================================================================
--- incubator/shindig/trunk/javascript/container/sample2.html (original)
+++ incubator/shindig/trunk/javascript/container/sample2.html Tue Mar 25 06:30:48 2008
@@ -7,6 +7,7 @@
 <script type="text/javascript" src="../../js/rpc.js?c=1&debug=1"></script>
 <script type="text/javascript" src="cookies.js"></script>
 <script type="text/javascript" src="gadgets.js"></script>
+<script type="text/javascript" src="cookiebaseduserprefstore.js"></script>
 <script type="text/javascript">
 var my = {};
 

Modified: incubator/shindig/trunk/javascript/container/sample3.html
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/container/sample3.html?rev=640803&r1=640802&r2=640803&view=diff
==============================================================================
--- incubator/shindig/trunk/javascript/container/sample3.html (original)
+++ incubator/shindig/trunk/javascript/container/sample3.html Tue Mar 25 06:30:48 2008
@@ -7,6 +7,7 @@
 <script type="text/javascript" src="../../js/rpc.js?c=1&debug=1"></script>
 <script type="text/javascript" src="cookies.js"></script>
 <script type="text/javascript" src="gadgets.js"></script>
+<script type="text/javascript" src="cookiebaseduserprefstore.js"></script>
 <script type="text/javascript">
 var specUrl0 = 'http://www.google.com/ig/modules/horoscope.xml';
 

Modified: incubator/shindig/trunk/javascript/container/sample4.html
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/container/sample4.html?rev=640803&r1=640802&r2=640803&view=diff
==============================================================================
--- incubator/shindig/trunk/javascript/container/sample4.html (original)
+++ incubator/shindig/trunk/javascript/container/sample4.html Tue Mar 25 06:30:48 2008
@@ -7,6 +7,7 @@
 <script type="text/javascript" src="../../js/rpc.js?c=1&debug=1"></script>
 <script type="text/javascript" src="cookies.js"></script>
 <script type="text/javascript" src="gadgets.js"></script>
+<script type="text/javascript" src="cookiebaseduserprefstore.js"></script>
 <script type="text/javascript">
 var specUrl0 = 'http://www.google.com/ig/modules/test_setprefs_multiple_ifpc.xml';
 

Modified: incubator/shindig/trunk/javascript/container/sample5.html
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/container/sample5.html?rev=640803&r1=640802&r2=640803&view=diff
==============================================================================
--- incubator/shindig/trunk/javascript/container/sample5.html (original)
+++ incubator/shindig/trunk/javascript/container/sample5.html Tue Mar 25 06:30:48 2008
@@ -7,6 +7,7 @@
 <script type="text/javascript" src="../../js/rpc.js?c=1&debug=1"></script>
 <script type="text/javascript" src="cookies.js"></script>
 <script type="text/javascript" src="gadgets.js"></script>
+<script type="text/javascript" src="cookiebaseduserprefstore.js"></script>
 <script type="text/javascript">
 var specUrl0 = 'http://www.google.com/ig/modules/test_setprefs_multiple_ifpc.xml';
 

Modified: incubator/shindig/trunk/javascript/container/sample6.html
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/container/sample6.html?rev=640803&r1=640802&r2=640803&view=diff
==============================================================================
--- incubator/shindig/trunk/javascript/container/sample6.html (original)
+++ incubator/shindig/trunk/javascript/container/sample6.html Tue Mar 25 06:30:48 2008
@@ -7,6 +7,7 @@
 <script type="text/javascript" src="../../js/rpc.js?c=1&debug=1"></script>
 <script type="text/javascript" src="cookies.js"></script>
 <script type="text/javascript" src="gadgets.js"></script>
+<script type="text/javascript" src="cookiebaseduserprefstore.js"></script>
 <script type="text/javascript">
 var specUrl0 = 'http://www.google.com/ig/modules/aue07otr.xml';
 

Modified: incubator/shindig/trunk/javascript/container/sample7.html
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/container/sample7.html?rev=640803&r1=640802&r2=640803&view=diff
==============================================================================
--- incubator/shindig/trunk/javascript/container/sample7.html (original)
+++ incubator/shindig/trunk/javascript/container/sample7.html Tue Mar 25 06:30:48 2008
@@ -7,6 +7,7 @@
 <script type="text/javascript" src="../../js/rpc.js?c=1&debug=1"></script>
 <script type="text/javascript" src="cookies.js"></script>
 <script type="text/javascript" src="gadgets.js"></script>
+<script type="text/javascript" src="cookiebaseduserprefstore.js"></script>
 <script type="text/javascript">
 var specUrl0 = 'http://www.google.com/ig/modules/test_settitle_html.xml';