You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by ch...@apache.org on 2010/03/22 19:12:03 UTC

svn commit: r926231 - in /shindig/trunk: features/src/main/javascript/features/ features/src/main/javascript/features/osml/ java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/ java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/

Author: chirag
Date: Mon Mar 22 18:12:02 2010
New Revision: 926231

URL: http://svn.apache.org/viewvc?rev=926231&view=rev
Log:
Add the osml feature.
Code Review: http://codereview.appspot.com/593044/show

Added:
    shindig/trunk/features/src/main/javascript/features/osml/
    shindig/trunk/features/src/main/javascript/features/osml/feature.xml
Modified:
    shindig/trunk/features/src/main/javascript/features/features.txt
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/TemplateRewriter.java
    shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/TemplateRewriterTest.java

Modified: shindig/trunk/features/src/main/javascript/features/features.txt
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/features.txt?rev=926231&r1=926230&r2=926231&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/features.txt (original)
+++ shindig/trunk/features/src/main/javascript/features/features.txt Mon Mar 22 18:12:02 2010
@@ -52,6 +52,7 @@ features/opensocial-jsonrpc/feature.xml
 features/opensocial-reference/feature.xml
 features/opensocial-templates/feature.xml
 features/osapi/feature.xml
+features/osml/feature.xml
 features/pubsub/feature.xml
 features/rpc/feature.xml
 features/security-token/feature.xml

Added: shindig/trunk/features/src/main/javascript/features/osml/feature.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/osml/feature.xml?rev=926231&view=auto
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/osml/feature.xml (added)
+++ shindig/trunk/features/src/main/javascript/features/osml/feature.xml Mon Mar 22 18:12:02 2010
@@ -0,0 +1,28 @@
+<?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.
+-->
+<feature>
+  <!--
+    The osml feature signals TemplateRewriter to only process OSML tags, a strict
+    subset of OpenSocial Templating. This is defined by section 3 of the
+    OpenSocial Markup Language Tags Specification v0.9
+  -->
+  <name>osml</name>
+  <dependency>opensocial-data</dependency>
+  <dependency>opensocial-templates</dependency>
+</feature>

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/TemplateRewriter.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/TemplateRewriter.java?rev=926231&r1=926230&r2=926231&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/TemplateRewriter.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/TemplateRewriter.java Mon Mar 22 18:12:02 2010
@@ -73,6 +73,8 @@ import java.util.logging.Logger;
 public class TemplateRewriter implements GadgetRewriter {
 
   public final static Set<String> TAGS = ImmutableSet.of("script");
+  public static final String TEMPLATES_FEATURE_NAME = "opensocial-templates";
+  public static final String OSML_FEATURE_NAME = "osml";
 
   /** Set to true to block auto-processing of templates */
   static final String DISABLE_AUTO_PROCESSING_PARAM = "disableAutoProcessing";
@@ -81,7 +83,7 @@ public class TemplateRewriter implements
   static final String REQUIRE_LIBRARY_PARAM = "requireLibrary";
   
   /** Enable client support? **/
-  static final String CLIENT_SUPPORT_PARAM = "client";  
+  static final String CLIENT_SUPPORT_PARAM = "client";
 
   private static final Logger logger = Logger.getLogger(TemplateRewriter.class.getName());
   
@@ -110,8 +112,14 @@ public class TemplateRewriter implements
   }
 
   public void rewrite(Gadget gadget, MutableContent content) throws RewritingException {
-    Feature f = gadget.getSpec().getModulePrefs().getFeatures()
-        .get("opensocial-templates");
+    Map<String, Feature> directFeatures = gadget.getSpec().getModulePrefs()
+        .getFeatures();
+
+    Feature f = directFeatures.get(TEMPLATES_FEATURE_NAME);
+    if (f == null && directFeatures.containsKey(OSML_FEATURE_NAME)) {
+      f = directFeatures.get(OSML_FEATURE_NAME);
+    }
+    
     if (f != null && isServerTemplatingEnabled(f)) {
       try {
         rewriteImpl(gadget, f, content);
@@ -155,11 +163,13 @@ public class TemplateRewriter implements
     }
     List<Element> templates = builder.build();
 
-    // User-defined custom tags - Priority 3
-    registries.add(registerCustomTags(templates));
-    
-    // User-defined libraries - Priority 4
-    loadTemplateLibraries(gadget.getContext(), f, registries, libraries);
+    if (!OSML_FEATURE_NAME.equals(f.getName())) {
+      // User-defined custom tags - Priority 3
+      registries.add(registerCustomTags(templates));
+
+      // User-defined libraries - Priority 4
+      loadTemplateLibraries(gadget.getContext(), f, registries, libraries);
+    }
     
     TagRegistry registry = new CompositeTagRegistry(registries);
     
@@ -202,7 +212,7 @@ public class TemplateRewriter implements
 
     // If we don't need the feature, remove it and all templates from the gadget
     if (!needsFeature) {
-      templateContext.getGadget().removeFeature("opensocial-templates");
+      templateContext.getGadget().removeFeature(TEMPLATES_FEATURE_NAME);
       for (Element template : allTemplates) {
         Node parent = template.getParentNode();
         if (parent != null) {

Modified: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/TemplateRewriterTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/TemplateRewriterTest.java?rev=926231&r1=926230&r2=926231&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/TemplateRewriterTest.java (original)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/TemplateRewriterTest.java Mon Mar 22 18:12:02 2010
@@ -200,6 +200,16 @@ public class TemplateRewriterTest {
     
     testFeatureRemoved();
   }
+
+  @Test
+  public void osmlWithLibrary() throws Exception {
+    setupGadget(getGadgetXmlWithLibrary(CONTENT_WITH_TAG_FROM_LIBRARY, "osml"));
+    rewriter.rewrite(gadget, content);
+    assertTrue("Custom tags were evaluated", content.getContent().equals(
+        "<html><head></head><body><my:Tag4></my:Tag4></body></html>"));
+
+    testFeatureRemoved();
+  }
   
   @Test
   public void tagPrecedenceRules() throws Exception {
@@ -219,6 +229,24 @@ public class TemplateRewriterTest {
    
     testFeatureRemoved();
   }
+
+  @Test
+  public void tagPrecedenceRulesWithOSMLFeature() throws Exception {
+    // A strict subset of os templating is enabled when the osml feature is required
+    // Tag definitions include:
+    // Default handlers: tag1 default1
+    // OSML: tag1 osml1 tag2 osml2
+
+    config.put("${Cur['gadgets.features'].osml.library}",
+        "org/apache/shindig/gadgets/rewrite/OSML_test.xml");
+
+    setupGadget(getGadgetXmlWithLibrary(CONTENT_TESTING_PRECEDENCE_RULES, "osml"));
+    rewriter.rewrite(gadget, content);
+    assertTrue("Precedence rules violated", content.getContent().indexOf(
+        "default1osml2<my:Tag3></my:Tag3><my:Tag4></my:Tag4>") > 0);
+
+    testFeatureRemoved();
+  }
   
   @Test
   public void tagPrecedenceRulesWithoutOSML() throws Exception {
@@ -328,8 +356,12 @@ public class TemplateRewriterTest {
   }
   
   private static String getGadgetXmlWithLibrary(String content) {
+    return getGadgetXmlWithLibrary(content, "opensocial-templates");
+  }
+
+  private static String getGadgetXmlWithLibrary(String content, String feature) {
     return "<Module>" + "<ModulePrefs title='Title'>"
-        + "  <Require feature='opensocial-templates'>"
+        + "  <Require feature='" + feature + "'>"
         + "    <Param name='" + TemplateRewriter.REQUIRE_LIBRARY_PARAM + "'>"
         + TEMPLATE_LIBRARY_URI
         + "    </Param>"