shindig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hsapu...@apache.org
Subject svn commit: r1355096 - in /shindig/trunk/java: common/conf/shindig.properties gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/AbsolutePathReferenceRewriter.java
Date Thu, 28 Jun 2012 18:31:42 GMT
Author: hsaputra
Date: Thu Jun 28 18:31:41 2012
New Revision: 1355096

URL: http://svn.apache.org/viewvc?rev=1355096&view=rev
Log:
Add optional shindig property shindig.gadgets.rewriter.absolutePath.tags to add possible tags
that could have its path to be rewritten as absolute. Set default as RESOURCES.

Modified:
    shindig/trunk/java/common/conf/shindig.properties
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/AbsolutePathReferenceRewriter.java

Modified: shindig/trunk/java/common/conf/shindig.properties
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/conf/shindig.properties?rev=1355096&r1=1355095&r2=1355096&view=diff
==============================================================================
--- shindig/trunk/java/common/conf/shindig.properties (original)
+++ shindig/trunk/java/common/conf/shindig.properties Thu Jun 28 18:31:41 2012
@@ -204,4 +204,8 @@ shindig.oauth2.accessTokenExpiration=180
 shindig.oauth2.refreshTokenExpiration=432000000
 
 # Allows unauthenticated requests to Shindig
-shindig.allowUnauthenticated=true
\ No newline at end of file
+shindig.allowUnauthenticated=true
+
+# Comma separated tags that need to have its relative path to be resolved as absolute.
+# Possible values are RESOURCES and HYPERLINKS
+shindig.gadgets.rewriter.absolutePath.tags=RESOURCES

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/AbsolutePathReferenceRewriter.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/AbsolutePathReferenceRewriter.java?rev=1355096&r1=1355095&r2=1355096&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/AbsolutePathReferenceRewriter.java
(original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/AbsolutePathReferenceRewriter.java
Thu Jun 28 18:31:41 2012
@@ -19,12 +19,16 @@
 package org.apache.shindig.gadgets.rewrite;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
 import com.google.inject.Inject;
+import com.google.inject.name.Named;
 
 import org.apache.shindig.common.uri.Uri;
 import org.apache.shindig.gadgets.Gadget;
 
 import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /**
  * Rewriter that converts all url's to absolute.
@@ -32,12 +36,37 @@ import java.util.List;
  * @since 2.0.0
  */
 public class AbsolutePathReferenceRewriter extends DomWalker.Rewriter {
+  private static final Logger LOG = Logger.getLogger(AbsolutePathReferenceRewriter.class.getName());
+
+  private AbsolutePathReferenceVisitor.Tags[] tags = {AbsolutePathReferenceVisitor.Tags.RESOURCES};
+
   @Inject
   public AbsolutePathReferenceRewriter() {}
 
+  @Inject(optional=true)
+  public void setAbsolutePathTags(@Named("shindig.gadgets.rewriter.absolutePath.tags")
+                                         String absolutePathTags) {
+    if(LOG.isLoggable(Level.FINE)) {
+      LOG.fine("Tags that should have the reference resolved to absolute path: " + absolutePathTags);
+    }
+    String[] tagsArray = absolutePathTags.split(",");
+    List<AbsolutePathReferenceVisitor.Tags> tagsList = Lists.newArrayList();
+    for(String tagValue : tagsArray) {
+      try {
+        AbsolutePathReferenceVisitor.Tags tag = AbsolutePathReferenceVisitor.Tags.valueOf(tagValue);
+        if(!tagsList.contains(tag)) {
+          tagsList.add(tag);
+        }
+      } catch (Exception ex) {
+        LOG.warning("Invalid absolute path tag name : " + tagValue);
+        continue;
+      }
+    }
+    this.tags = tagsList.toArray(new AbsolutePathReferenceVisitor.Tags[tagsList.size()]);
+  }
+
   @Override
   protected List<DomWalker.Visitor> makeVisitors(Gadget context, Uri gadgetUri) {
-    return ImmutableList.<DomWalker.Visitor>of(
-        new AbsolutePathReferenceVisitor(AbsolutePathReferenceVisitor.Tags.RESOURCES));
+    return ImmutableList.<DomWalker.Visitor>of(new AbsolutePathReferenceVisitor(tags));
   }
 }



Mime
View raw message