abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1209294 - in /abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model: ASBase.java ASObject.java MediaLink.java objects/BookmarkObject.java objects/FileObject.java objects/TaskObject.java
Date Thu, 01 Dec 2011 22:56:34 GMT
Author: jmsnell
Date: Thu Dec  1 22:56:29 2011
New Revision: 1209294

URL: http://svn.apache.org/viewvc?rev=1209294&view=rev
Log:
The activity streams implementation includes a number of non-standard experimental features...
to differentiate these from the core standard features, this checkin creates a new experimental
mode on the Builders that must be set prior to building Activity objects that use the experimental
features.

Modified:
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASBase.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASObject.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/MediaLink.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/BookmarkObject.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/FileObject.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/TaskObject.java

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASBase.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASBase.java?rev=1209294&r1=1209293&r2=1209294&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASBase.java
(original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASBase.java
Thu Dec  1 22:56:29 2011
@@ -28,6 +28,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.Callable;
 import java.util.concurrent.Future;
+import java.util.logging.Logger;
 
 import org.apache.abdera2.activities.extra.Difference;
 import org.apache.abdera2.activities.extra.Extra;
@@ -45,7 +46,9 @@ import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.base.Supplier;
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMultimap;
 import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
 import com.google.common.collect.Maps;
 
 import static com.google.common.collect.Maps.filterEntries;
@@ -58,6 +61,8 @@ import static com.google.common.collect.
 public class ASBase 
   implements Iterable<String>, Cloneable {
   
+  public static Logger log = Logger.getLogger(ASBase.class.getName());
+  
   public static ASBuilder make() {
     return new ASBuilder();
   }
@@ -97,6 +102,9 @@ public class ASBase 
       ImmutableMap.builder();
     private final Function<Object[],X> con;
     private final Function<Object[],M> bld;
+    private boolean experimental = false; // true if experimental extensions have been enabled
on this builder
+    private ImmutableMultimap.Builder<String, IRI> links = ImmutableMultimap.builder();
+    private boolean y = false;
     
     protected Builder(Class<X> _class, Class<M> _builder) {
       con = createInstance(_class, Map.class);
@@ -108,7 +116,28 @@ public class ASBase 
       this.map.putAll(map);
     }
     
-    public Object val(Object val) {
+    /**
+     * Enables experimental features on the builder. Abdera supports a number
+     * of non-standard, experimental features such as object reactions, $rel
+     * links and metadata conventions that are not a part of the core Activity
+     * Streams specification. In order to use the builder to work with these
+     * extensions, you must first call the experimental() method on the builder
+     * to enable them. 
+     */
+    public M experimental() {
+      log.warning(
+        String.format(
+          "Non-standard, experimental features have been enabled in a builder instance. [%s]",

+          getClass().getSimpleName()));
+      this.experimental = true;
+      return (M)this;
+    }
+    
+    protected boolean isExperimentalEnabled() {
+      return experimental;
+    }
+    
+    protected Object val(Object val) {
       if (val == null) return null;
       else if (val instanceof Supplier)
         return val(((Supplier<?>)val).get());
@@ -182,7 +211,58 @@ public class ASBase 
       set("@base",iri);
       return (M)this;
     }
-    protected void preGet() {}
+    /**
+     * Add a new $rel style link field to the object. This is an
+     * experimental feature. You must call experimental() before
+     * calling this method
+     */
+    public M link(String rel, IRI url) {
+      checkState(isExperimentalEnabled(),"Experimental features not yet enabled. Call experimental()
first.");
+      y = true;
+      links.put(rel, url);
+      return (M)this;
+    }
+
+    /**
+     * Add a new $rel style link field to the object. This is an
+     * experimental feature. You must call experimental() before
+     * calling this method
+     */
+    public M link(String rel, String url) {
+      return link(rel, new IRI(checkNotNull(url)));
+    }
+    /**
+     * Add a new metadata field to the object. This is an 
+     * experimental feature. You must call experimental() before
+     * calling this method
+     */
+    public M meta(String token, Object val) {
+      return meta(token,val,false);
+    }
+    /**
+     * Add a new metadata field to the object. This is an 
+     * experimental feature. You must call experimental() before
+     * calling this method
+     */
+    public M meta(String token, Object val, boolean isPrivate) {
+      checkState(isExperimentalEnabled(),"Experimental features not yet enabled. Call experimental()
first.");
+      set(String.format("%s%s",isPrivate?"_":"@",token),val);
+      return (M)this;
+    }
+    protected void preGet() {
+      if (y && isExperimentalEnabled()) {
+        ImmutableMultimap<String,IRI> map = links.build();
+        for (String key : map.keySet()) {
+          Iterable<IRI> links = map.get(key);
+          if (links == null) continue;
+          int s = Iterables.size(links);
+          set(String.format("$%s",key.toLowerCase()),
+            s == 1 ? 
+              links.iterator().next() : 
+              links.iterator());
+        }
+      }
+    }
     public X get() {
       preGet();
       return con.apply(array(map.build()));
@@ -210,11 +290,13 @@ public class ASBase 
   }
   
   public Lang getLang() {
-    return getProperty("@language");
+    Object lang = getProperty("@language");
+    return lang instanceof Lang ? (Lang)lang : new Lang(lang.toString());
   }
   
   public IRI getBase() {
-    return getProperty("@base");
+    Object base = getProperty("@base");
+    return base instanceof IRI ? (IRI)base : new IRI(base.toString());
   }
   
   public <T>T getProperty(String name) {

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASObject.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASObject.java?rev=1209294&r1=1209293&r2=1209294&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASObject.java
(original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASObject.java
Thu Dec  1 22:56:29 2011
@@ -35,6 +35,8 @@ import org.apache.abdera2.common.selecto
 import com.google.common.base.Supplier;
 import com.google.common.collect.ImmutableSet;
 
+import static com.google.common.base.Preconditions.*;
+
 /**
  * Base class for all Activity Streams Objects.
  */
@@ -107,32 +109,57 @@ public class ASObject extends ASBase {
       super(map,_class,_builder);
     }
     
+    /**
+     * Add a new reaction to the object. You must call experimental() before
+     * calling this method.
+     */
     public M reaction(Supplier<? extends TaskObject> object) {
+      checkState(isExperimentalEnabled(),"Experimental features not yet enabled. Call experimental()
first.");
       return reaction(object.get());
     }
     
+    /**
+     * Add a new reaction to the object. You must call experimental() before
+     * calling this method.
+     */
     public M reaction(TaskObject object) {
+      checkState(isExperimentalEnabled(),"Experimental features not yet enabled. Call experimental()
first.");
       if (object == null) return (M)this;
       z = true;
       tasks.add(object);
       return (M)this;
     }
     
+    /**
+     * Add a new reaction to the object. You must call experimental() before
+     * calling this method.
+     */
     public M reaction(Supplier<? extends TaskObject>... objects) {
+      checkState(isExperimentalEnabled(),"Experimental features not yet enabled. Call experimental()
first.");
       if (objects == null) return (M)this;
       for (Supplier<? extends TaskObject> object : objects)
         reaction(object.get());
       return (M)this;
     }
     
+    /**
+     * Add a new reaction to the object. You must call experimental() before
+     * calling this method.
+     */
     public M reaction(TaskObject... objects) {
+      checkState(isExperimentalEnabled(),"Experimental features not yet enabled. Call experimental()
first.");
       if (objects == null) return (M)this;
       for (TaskObject obj : objects)
         reaction(obj);
       return (M)this;
     }
     
+    /**
+     * Add a new reaction to the object. You must call experimental() before
+     * calling this method.
+     */
     public M reaction(Iterable<? extends TaskObject> objects) {
+      checkState(isExperimentalEnabled(),"Experimental features not yet enabled. Call experimental()
first.");
       if (objects == null) return (M)this;
       for (TaskObject obj : objects)
         reaction(obj);
@@ -325,6 +352,11 @@ public class ASObject extends ASBase {
       return (M)this;
     }
     
+    public M id(IRI id) {
+      set(ID,checkNotNull(id).toString());
+      return (M)this;
+    }
+    
     public M image(Supplier<MediaLink> object) {
       return image(object.get());
     }
@@ -396,6 +428,10 @@ public class ASObject extends ASBase {
     
     public M url(IRI url) {
       set(URL,url);
+      try {
+        if (isExperimentalEnabled())
+          link("alternate",url);
+      } catch (IllegalStateException t) {}
       return (M)this;
     }
     

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/MediaLink.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/MediaLink.java?rev=1209294&r1=1209293&r2=1209294&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/MediaLink.java
(original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/MediaLink.java
Thu Dec  1 22:56:29 2011
@@ -97,6 +97,10 @@ public final class MediaLink extends ASB
     
     public Builder url(IRI iri) {
       set(URL,iri);
+      try {
+        if (isExperimentalEnabled())
+          link("alternate",iri);
+      } catch (IllegalStateException e) {}
       return this;
     }
     

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/BookmarkObject.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/BookmarkObject.java?rev=1209294&r1=1209293&r2=1209294&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/BookmarkObject.java
(original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/BookmarkObject.java
Thu Dec  1 22:56:29 2011
@@ -83,6 +83,10 @@ public class BookmarkObject 
     }
     public M targetUrl(IRI uri) {
       set(TARGETURL,uri);
+      try {
+        if (isExperimentalEnabled())
+          link("bookmark",uri);
+      } catch (IllegalStateException e) {}
       return (M)this;
     }    
   }

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/FileObject.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/FileObject.java?rev=1209294&r1=1209293&r2=1209294&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/FileObject.java
(original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/FileObject.java
Thu Dec  1 22:56:29 2011
@@ -123,6 +123,10 @@ public class FileObject 
     }
     public M fileUrl(IRI iri) {
       set(FILEURL,iri);
+      try {
+        if (isExperimentalEnabled())
+          link("enclosure",iri);
+      } catch (IllegalStateException e) {}
       return (M)this;
     }
     public M fileUrl(String uri) {

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/TaskObject.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/TaskObject.java?rev=1209294&r1=1209293&r2=1209294&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/TaskObject.java
(original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/TaskObject.java
Thu Dec  1 22:56:29 2011
@@ -91,12 +91,15 @@ public class TaskObject extends ASObject
     
     public Builder(Class<X>_class,Class<M>_builder) {
       super(_class,_builder);
+      experimental();
     }
     public Builder(String objectType,Class<X>_class,Class<M>_builder) {
       super(objectType,_class,_builder);
+      experimental();
     }
     public Builder(Map<String,Object> map,Class<X>_class,Class<M>_builder)
{
       super(map,_class,_builder);
+      experimental();
     }
     public M object(Supplier<? extends ASObject> object) {
       return object(object.get());
@@ -134,6 +137,7 @@ public class TaskObject extends ASObject
     }
     public M selfLink(IRI iri) {
       set("selfLink", iri);
+      link("self",iri);
       return (M)this;
     }
     public M selfLink(String iri) {
@@ -145,6 +149,7 @@ public class TaskObject extends ASObject
     }
     public M resourceLink(IRI iri) {
       set("resourceLink",iri);
+      link("alternate",iri);
       return (M)this;
     }
     public M resourceLink(String iri) {



Mime
View raw message