Author: evan
Date: Mon Feb  2 20:49:01 2009
New Revision: 740102

URL: http://svn.apache.org/viewvc?rev=740102&view=rev
Log:
Patch for SHINDIG-880

This patch removes all artifacts of Data Pipelining from the
"opensocial-templates" feature.

Common dependencies with "opensocial-data" have been moved to an "xmlutil"
feature.

Removed:
    incubator/shindig/trunk/features/opensocial-templates/data.js
    incubator/shindig/trunk/features/opensocial-templates/data_test.js
    
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/data_test.js
Modified:
    incubator/shindig/trunk/features/opensocial-templates/base.js
    incubator/shindig/trunk/features/opensocial-templates/compiler.js
    incubator/shindig/trunk/features/opensocial-templates/container.js
    incubator/shindig/trunk/features/opensocial-templates/feature.xml
    incubator/shindig/trunk/features/opensocial-templates/loader.js
    incubator/shindig/trunk/features/opensocial-templates/namespaces.js
    incubator/shindig/trunk/features/opensocial-templates/ost_test.html
    incubator/shindig/trunk/features/opensocial-templates/template_test.js
    
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/ost_test.xml

Modified: incubator/shindig/trunk/features/opensocial-templates/base.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-templates/base.js?rev=740102&r1=740101&r2=740102&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-templates/base.js (original)
+++ incubator/shindig/trunk/features/opensocial-templates/base.js Mon Feb  2 
20:49:01 2009
@@ -121,8 +121,8 @@
  * @return {os.Template} A compiled Template object.
  */
 os.compileTemplateString = function(src, opt_id) {
-  src = os.prepareTemplateXML_(src);
-  var doc = os.parseXML_(src);
+  src = opensocial.xmlutil.prepareXML(src);
+  var doc = opensocial.xmlutil.parseXML(src);
   return os.compileXMLDoc(doc, opt_id);
 };
 

Modified: incubator/shindig/trunk/features/opensocial-templates/compiler.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-templates/compiler.js?rev=740102&r1=740101&r2=740102&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-templates/compiler.js (original)
+++ incubator/shindig/trunk/features/opensocial-templates/compiler.js Mon Feb  
2 20:49:01 2009
@@ -81,30 +81,6 @@
 };
 
 /**
- * Parses an XML string into an XML Document.
- * @param {string} str A string of well-formed XML.
- * @return {Document} XML document.
- */
-os.parseXML_ = function(str) {
-  if (typeof(DOMParser) != "undefined") {
-    os.parser_ = os.parser_ || new DOMParser();
-    var doc = os.parser_.parseFromString(str, "text/xml");
-    if (doc.firstChild && doc.firstChild.tagName == 'parsererror') {
-      throw doc.firstChild.firstChild.nodeValue;
-    }
-    return doc;
-  } else {
-    var doc = new ActiveXObject("MSXML2.DomDocument");
-    doc.validateOnParse = false;
-    doc.loadXML(str);
-    if (doc.parseError && doc.parseError.errorCode) {
-      throw doc.parseError.reason;
-    }
-    return doc;
-  }
-};
-
-/**
  * Map of special operators to be transformed.
  */
 os.operatorMap = {
@@ -497,18 +473,6 @@
 os.ENTITIES = "<!ENTITY nbsp \"&#160;\">";
 
 /**
- * Prepares an XML string to be compiled as a template. Injects a DOCTYPE
- * with entities and a top-level <root> element to encapsulate the template.
- * @param {string} templateSrc XML string to be prepared.
- * @return {string} XML string prepared for template compilation.
- */
-os.prepareTemplateXML_ = function(templateSrc) {
-  var namespaces = os.getRequiredNamespaces(templateSrc);
-  return "<!DOCTYPE root [" + os.ENTITIES + "]><root xml:space=\"preserve\"" +
-      namespaces + ">" + templateSrc + "</root>";;
-};
-
-/**
  * Creates an HTML node that's a shallow copy of an XML node
  * (includes attributes).
  */

Modified: incubator/shindig/trunk/features/opensocial-templates/container.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-templates/container.js?rev=740102&r1=740101&r2=740102&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-templates/container.js 
(original)
+++ incubator/shindig/trunk/features/opensocial-templates/container.js Mon Feb  
2 20:49:01 2009
@@ -71,9 +71,9 @@
   if (gadgets && gadgets.util) {
     gadgets.util.registerOnLoadHandler(os.Container.onDomLoad_);
   } else if (navigator.product == 'Gecko') {
-    window.addEventListener("DOMContentLoaded", os.Container.onDomLoad_, 
false);
+    window.addEventListener('DOMContentLoaded', os.Container.onDomLoad_, 
false);
   } if (window.addEventListener) {
-    window.addEventListener("load", os.Container.onDomLoad_, false);
+    window.addEventListener('load', os.Container.onDomLoad_, false);
   } else {
     if (!document.body) {
       setTimeout(arguments.callee, 0);
@@ -170,6 +170,19 @@
   }
 };
 
+os.Container.defaultContext = null;
+
+os.Container.getDefaultContext = function() {
+  if (!os.Container.defaultContext) {
+    if (window['gadgets'] && gadgets.util.hasFeature('opensocial-data')) {
+      os.Container.defaultContext = 
os.createContext(opensocial.data.DataContext.dataSets_);
+    } else {
+      os.Container.defaultContext = os.createContext({});
+    }
+  }
+  return os.Container.defaultContext;
+};
+
 /**
  * Renders any registered inline templates.
  * @param {Object} opt_data Optional JSON data.
@@ -178,7 +191,7 @@
 os.Container.renderInlineTemplates = function(opt_data, opt_doc) {
   var doc = opt_doc || document;
   var context = opt_data ?
-      os.createContext(opt_data) : os.data.getDataContext().getContext();
+      os.createContext(opt_data) : os.Container.getDefaultContext();
   var inlined = os.Container.inlineTemplates_;
   for (var i = 0; i < inlined.length; ++i) {
     var template = inlined[i].template;
@@ -191,23 +204,29 @@
       node.parentNode.insertBefore(el, node);
     }
 
-    var beforeData = node.getAttribute('before') ||
-        node.getAttribute('beforeData');
-    if (beforeData) {
-      // Automatically hide this template when specified data is available.
-      var keys = beforeData.split(/[\, ]+/);
-      os.data.DataContext.registerListener(keys,
-          os.Container.createHideElementClosure(el));
-    }
+    // Only honor @before and @require attributes if the opensocial-data
+    // feature is present.
+    if (window['gadgets'] && gadgets.util.hasFeature('opensocial-data')) {
+      var beforeData = node.getAttribute('before') ||
+          node.getAttribute('beforeData');
+      if (beforeData) {
+        // Automatically hide this template when specified data is available.
+        var keys = beforeData.split(/[\, ]+/);
+        opensocial.data.DataContext.registerListener(keys,
+            os.Container.createHideElementClosure(el));
+      }
 
-    var requiredData = node.getAttribute('require') ||
-        node.getAttribute('requireData');
-    if (requiredData) {
-      // This template will render when the specified data is available.
-      var keys = requiredData.split(/[\, ]+/);
-      os.data.DataContext.registerListener(keys,
-          os.Container.createRenderClosure(template, el, null,
-              os.data.DataContext.getContext()));
+      var requiredData = node.getAttribute('require') ||
+          node.getAttribute('requireData');
+      if (requiredData) {
+        // This template will render when the specified data is available.
+        var keys = requiredData.split(/[\, ]+/);
+        opensocial.data.DataContext.registerListener(keys,
+            os.Container.createRenderClosure(template, el, null,
+                os.Container.getDefaultContext()));
+      } else {
+        template.renderInto(el, null, context);
+      }
     } else {
       template.renderInto(el, null, context);
     }

Modified: incubator/shindig/trunk/features/opensocial-templates/feature.xml
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-templates/feature.xml?rev=740102&r1=740101&r2=740102&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-templates/feature.xml (original)
+++ incubator/shindig/trunk/features/opensocial-templates/feature.xml Mon Feb  
2 20:49:01 2009
@@ -32,6 +32,7 @@
 <feature>
   <name>opensocial-templates</name>
   <dependency>opensocial-0.8</dependency>
+  <dependency>xmlutil</dependency>
   <gadget>
     <script 
src="http://google-jstemplate.googlecode.com/svn/trunk/util.js";></script>
     <script 
src="http://google-jstemplate.googlecode.com/svn/trunk/jsevalcontext.js";></script>
@@ -45,6 +46,5 @@
     <script src="loader.js"></script>
     <script src="container.js"></script>
     <script src="os.js"></script>
-    <script src="data.js"></script>
   </gadget>
 </feature>

Modified: incubator/shindig/trunk/features/opensocial-templates/loader.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-templates/loader.js?rev=740102&r1=740101&r2=740102&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-templates/loader.js (original)
+++ incubator/shindig/trunk/features/opensocial-templates/loader.js Mon Feb  2 
20:49:01 2009
@@ -143,7 +143,7 @@
  * Processes the XML markup of a Template Library.
  */
 os.Loader.loadContent = function(xmlString) {
-  var doc = os.parseXML_(xmlString);
+  var doc = opensocial.xmlutil.parseXML(xmlString);
   var templatesNode = doc.firstChild;
   os.Loader.processTemplatesNode(templatesNode);
 };

Modified: incubator/shindig/trunk/features/opensocial-templates/namespaces.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-templates/namespaces.js?rev=740102&r1=740101&r2=740102&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-templates/namespaces.js 
(original)
+++ incubator/shindig/trunk/features/opensocial-templates/namespaces.js Mon Feb 
 2 20:49:01 2009
@@ -45,13 +45,6 @@
  */
 os.nsmap_ = {};
 
-/**
- * Map of namespace prefixes to full urls.
- * @type {Object}
- * @private
- */
-os.nsurls_ = {};
-
 /***
  * Registers the given namespace with a specified URL. Throws an error if it
  * already exists as a different URL.
@@ -64,12 +57,13 @@
   if (!tags) {
     tags = {};
     os.nsmap_[ns] = tags;
-    os.nsurls_[ns] = url;
-  } else if (os.nsurls_[ns] == null ) {
+    opensocial.xmlutil.NSMAP[ns] = url;
+  } else if (opensocial.xmlutil.NSMAP[ns] == null ) {
     // Lazily register an auto-created namespace.
-    os.nsurls_[ns] = url;
-  } else if (os.nsurls_[ns] != url) {
-    throw("Namespace " + ns + " already defined with url " + os.nsurls_[ns]);
+    opensocial.xmlutil.NSMAP[ns] = url;
+  } else if (opensocial.xmlutil.NSMAP[ns] != url) {
+    throw("Namespace " + ns + " already defined with url " +
+        opensocial.xmlutil.NSMAP[ns]);
   }
   return tags;
 };
@@ -81,18 +75,18 @@
   return os.nsmap_[prefix];
 };
 
-os.addNamespace = function(ns, url, nsObj) {  
+os.addNamespace = function(ns, url, nsObj) {
   if (os.nsmap_[ns]) {
-    if (os.nsurls_[ns] == null) {
+    if (opensocial.xmlutil.NSMAP[ns] == null) {
       // Lazily register an auto-created namespace.
-      os.nsurls_[ns] = url;
+      opensocial.xmlutil.NSMAP[ns] = url;
       return;
     } else {
       throw ("Namespace '" + ns + "' already exists!");
     }
   }
   os.nsmap_[ns] = nsObj;
-  os.nsurls_[ns] = url;
+  opensocial.xmlutil.NSMAP[ns] = url;
 };
 
 os.getCustomTag = function(ns, tag) {
@@ -108,26 +102,6 @@
 };
 
 /**
- * Returns the XML namespace declarations that need to be injected into a
- * particular template to make it valid XML. Uses the defined namespaces to
- * see which are available, and checks that they are used in the supplied code.
- * An empty string is returned if no injection is needed.
- *
- * @param {string} templateSrc Template source code.
- * @return {string} A string of xmlns delcarations required for this tempalte.
- */
-os.getRequiredNamespaces = function(templateSrc) {
-  var codeToInject = "";
-  for (var ns in os.nsurls_) {
-    if (templateSrc.indexOf("<" + ns + ":") >= 0 &&
-        templateSrc.indexOf("xmlns:" + ns + ":") < 0) {
-      codeToInject += " xmlns:" + ns + "=\"" + os.nsurls_[ns] + "\"";
-    }
-  }
-  return codeToInject;
-};
-
-/**
  * Define 'os:renderAll' and 'os:Html' tags and the @onAttach attribute
  */
 os.defineBuiltinTags = function() {

Modified: incubator/shindig/trunk/features/opensocial-templates/ost_test.html
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-templates/ost_test.html?rev=740102&r1=740101&r2=740102&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-templates/ost_test.html 
(original)
+++ incubator/shindig/trunk/features/opensocial-templates/ost_test.html Mon Feb 
 2 20:49:01 2009
@@ -23,6 +23,8 @@
     <script 
src="http://google-jstemplate.googlecode.com/svn/trunk/jsevalcontext.js";></script>
     <script 
src="http://google-jstemplate.googlecode.com/svn/trunk/jstemplate.js";></script>
     <script src="jstemplate_debug.js"></script>
+    <script src="../xmlutil/xmlutil.js"></script>
+    <script src="../opensocial-data/data.js"></script>
     <script src="base.js"></script>
     <script src="namespaces.js"></script>
     <script src="util.js"></script>
@@ -31,11 +33,9 @@
     <script src="loader.js"></script>
     <script src="container.js"></script>
     <script src="os.js"></script>
-    <script src="data.js"></script>
     <!-- the JsUnit tests -->
     <script src="domutil.js"></script>
     <script type="text/javascript" src="compiler_test.js"></script>
-    <script type="text/javascript" src="data_test.js"></script>
     <script type="text/javascript" src="container_test.js"></script>
     <script type="text/javascript" src="loader_test.js"></script>
     <script type="text/javascript" src="os_test.js"></script>
@@ -53,7 +53,7 @@
         }
         return testFunctionNames;
       }
- 
+
       os.createNamespace("test", "http://www.google.com/#test";);
     </script>
   </head>
@@ -126,7 +126,7 @@
           <body>world</body>
         </item>
       </custom:list>
-    </xmp>  
+    </xmp>
 
     <xmp id="_T_Tag_blink" style="display: none">
       <custom:blink>blink text</custom:blink>

Modified: incubator/shindig/trunk/features/opensocial-templates/template_test.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-templates/template_test.js?rev=740102&r1=740101&r2=740102&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-templates/template_test.js 
(original)
+++ incubator/shindig/trunk/features/opensocial-templates/template_test.js Mon 
Feb  2 20:49:01 2009
@@ -159,7 +159,7 @@
     for (var i = 0; i < namedTemplates.length; i++) {
       var text = '<Templates xmlns:os="uri:unused">' + namedTemplates[i] +
           '</Templates>';
-      var dom = os.parseXML_(text);
+      var dom = opensocial.xmlutil.parseXML(text);
       os.Loader.processTemplatesNode(dom);
     }
   }

Modified: 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/ost_test.xml
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/ost_test.xml?rev=740102&r1=740101&r2=740102&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/ost_test.xml
 (original)
+++ 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/ost_test.xml
 Mon Feb  2 20:49:01 2009
@@ -27,7 +27,6 @@
     <script type="text/javascript" 
src="/opensocial-templates/testadapter.js"></script>
     <!-- the JsUnit tests -->
     <script type="text/javascript" 
src="/opensocial-templates/compiler_test.js"></script>
-    <script type="text/javascript" 
src="/opensocial-templates/data_test.js"></script>
     <script type="text/javascript" 
src="/opensocial-templates/container_test.js"></script>
     <script type="text/javascript" 
src="/opensocial-templates/loader_test.js"></script>
     <script type="text/javascript" 
src="/opensocial-templates/os_test.js"></script>


Reply via email to