abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1209185 - in /abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities: client/ extra/ io/gson/ model/ model/objects/
Date Thu, 01 Dec 2011 18:59:08 GMT
Author: jmsnell
Date: Thu Dec  1 18:59:06 2011
New Revision: 1209185

URL: http://svn.apache.org/viewvc?rev=1209185&view=rev
Log:
A few minor updates to a couple of the object types

Modified:
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/client/ActivityEntity.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/extra/Extra.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/BaseAdapter.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASBase.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AccountObject.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/Address.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/PlaceObject.java

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/client/ActivityEntity.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/client/ActivityEntity.java?rev=1209185&r1=1209184&r2=1209185&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/client/ActivityEntity.java
(original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/client/ActivityEntity.java
Thu Dec  1 18:59:06 2011
@@ -23,6 +23,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import javax.activation.MimeType;
+
+import org.apache.abdera2.activities.extra.Extra;
 import org.apache.abdera2.activities.model.ASBase;
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
@@ -46,7 +49,7 @@ public class ActivityEntity
      * element passed in.
      */
     public ActivityEntity(ASBase base) {
-      this(base,false,null);
+      this(base,false,(String)null);
     }
     
     /**
@@ -59,6 +62,10 @@ public class ActivityEntity
       this(base,false,contentType);
     }
     
+    public ActivityEntity(ASBase base, MimeType contentType) {
+      this(base,false,contentType);
+    }
+    
     /**
      * Create the entity using the specified Activity document or element.
      * The content length will be automatically calculated if the 
@@ -66,7 +73,7 @@ public class ActivityEntity
      * detected based on the type of element passed in.
      */
     public ActivityEntity(ASBase base, boolean calclen) {
-      this(base,calclen,null);
+      this(base,calclen,(String)null);
     }
     
     /**
@@ -80,7 +87,9 @@ public class ActivityEntity
         this.base = base;
         this.ct = new BasicHeader(
           "Content-Type", 
-          contentType!=null?contentType:"application/json");
+          contentType!=null?
+            contentType:
+            Extra.getMediaType(base).toString());
         if (calclen) {
           ByteArrayOutputStream out = 
             new ByteArrayOutputStream();
@@ -90,6 +99,10 @@ public class ActivityEntity
         } else len = -1;
     }
 
+    public ActivityEntity(ASBase base, boolean calclen, MimeType contentType) {
+      this(base,calclen,contentType.toString());
+    }
+    
     public boolean isRepeatable() {
         return true;
     }

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/extra/Extra.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/extra/Extra.java?rev=1209185&r1=1209184&r2=1209185&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/extra/Extra.java
(original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/extra/Extra.java
Thu Dec  1 18:59:06 2011
@@ -27,6 +27,9 @@ import java.util.Comparator;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
+
+import javax.activation.MimeType;
+
 import net.sf.cglib.proxy.Enhancer;
 import net.sf.cglib.proxy.MethodInterceptor;
 import net.sf.cglib.proxy.MethodProxy;
@@ -41,6 +44,7 @@ import org.apache.abdera2.activities.mod
 import org.apache.abdera2.activities.model.Verb;
 import org.apache.abdera2.common.anno.Name;
 import org.apache.abdera2.common.date.DateTimes;
+import org.apache.abdera2.common.misc.ExceptionHelper;
 import org.apache.abdera2.common.misc.MoreFunctions;
 import org.apache.abdera2.common.selector.AbstractSelector;
 import org.apache.abdera2.common.selector.PropertySelector;
@@ -51,6 +55,7 @@ import org.joda.time.DateTime;
 import com.google.common.base.CaseFormat;
 import com.google.common.base.Equivalence;
 import com.google.common.base.Function;
+import com.google.common.base.Joiner;
 import com.google.common.base.Predicate;
 import com.google.common.base.Supplier;
 import com.google.common.collect.ImmutableMap;
@@ -1493,4 +1498,35 @@ public final class Extra {
     }
     
   }
+  
+  private static final Joiner types_joiner = Joiner.on(' ');
+  
+  public static MimeType getMediaType(ASBase base) {
+    MimeType mt = null;
+    try {
+      mt = new MimeType("application/json");
+      if (base instanceof ASObject) {
+        ASObject obj = (ASObject) base;
+        String otype = obj.getObjectType();
+        if (otype != null)
+          mt.setParameter("type", otype);
+      }
+      if (base instanceof Collection) {
+        Collection<?> col = (Collection<?>) base;
+        Iterable<String> otypes = col.getObjectTypes();
+        if (!Iterables.isEmpty(otypes))
+          mt.setParameter("items", types_joiner.join(otypes));
+        else if (!Iterables.isEmpty(col.getItems())) {
+          ImmutableSet.Builder<String> set = ImmutableSet.builder();
+          for (ASObject obj : col.getItems())
+            if (obj.has("objectType"))
+              set.add(obj.getObjectType());
+          mt.setParameter("items", types_joiner.join(set.build()));
+        }
+      }
+    } catch (Throwable t) {
+      throw ExceptionHelper.propogate(t);
+    }
+    return mt;
+  }
 }

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/BaseAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/BaseAdapter.java?rev=1209185&r1=1209184&r2=1209185&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/BaseAdapter.java
(original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/BaseAdapter.java
Thu Dec  1 18:59:06 2011
@@ -101,6 +101,9 @@ final class BaseAdapter 
     map.put("updated", DateTime.class);
     map.put("published", DateTime.class);
     map.put("lang", Lang.class);
+    map.put("@language", Lang.class);
+    map.put("@base", IRI.class);
+    map.put("$ref", IRI.class); // for JSON Reference...
     map.put("icon", MediaLink.class);
     map.put("image", MediaLink.class);
     map.put("totalItems", Integer.class);

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=1209185&r1=1209184&r2=1209185&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 18:59:06 2011
@@ -31,6 +31,7 @@ import java.util.concurrent.Future;
 
 import org.apache.abdera2.activities.extra.Difference;
 import org.apache.abdera2.activities.extra.Extra;
+import org.apache.abdera2.common.iri.IRI;
 import org.apache.abdera2.common.lang.Lang;
 import org.apache.abdera2.common.misc.ExceptionHelper;
 import org.apache.abdera2.common.misc.Pair;
@@ -171,7 +172,14 @@ public class ASBase 
       return lang(new Lang(lang));
     }
     public M lang(Lang lang) {
-      set("lang",lang);
+      set("@language",lang);
+      return (M)this;
+    }
+    public M base(String iri) {
+      return base(new IRI(checkNotNull(iri)));
+    }
+    public M base(IRI iri) {
+      set("@base",iri);
       return (M)this;
     }
     protected void preGet() {}
@@ -202,7 +210,11 @@ public class ASBase 
   }
   
   public Lang getLang() {
-    return getProperty("lang");
+    return getProperty("@language");
+  }
+  
+  public IRI getBase() {
+    return getProperty("@base");
   }
   
   public <T>T getProperty(String name) {

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AccountObject.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AccountObject.java?rev=1209185&r1=1209184&r2=1209185&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AccountObject.java
(original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AccountObject.java
Thu Dec  1 18:59:06 2011
@@ -22,10 +22,13 @@ import java.util.Map;
 import org.apache.abdera2.activities.model.ASObject;
 import org.apache.abdera2.common.anno.Name;
 
+/**
+ * Represents a user account, generally specified in terms of a unique 
+ * user id, username and domain. 
+ */
 public class AccountObject 
   extends ServiceObject {
 
-
   public AccountObject(Map<String,Object> map) {
     super(map,AccountBuilder.class,AccountObject.class);
   }

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/Address.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/Address.java?rev=1209185&r1=1209184&r2=1209185&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/Address.java
(original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/Address.java
Thu Dec  1 18:59:06 2011
@@ -22,6 +22,9 @@ import java.util.Map;
 import org.apache.abdera2.activities.model.ASObject;
 import org.apache.abdera2.common.anno.Name;
 
+/**
+ * Represents a mailing address. 
+ */
 public class Address extends ASObject {
 
   public static final String FORMATTED = "formatted";
@@ -30,6 +33,8 @@ public class Address extends ASObject {
   public static final String REGION = "region";
   public static final String POSTALCODE = "postalCode";
   public static final String COUNTRY = "country";
+  public static final String BUILDING = "building";
+  public static final String FLOOR = "floor";
   
   public Address(Map<String,Object> map) {
     super(map,AddressBuilder.class,Address.class);
@@ -63,6 +68,14 @@ public class Address extends ASObject {
     return getProperty(COUNTRY);
   }
   
+  public String getBuilding() {
+    return getProperty(BUILDING);
+  }
+  
+  public String getFloor() {
+    return getProperty(FLOOR);
+  }
+  
   public String toString() {
     StringBuilder buf = new StringBuilder();
     if (getFormatted() != null) {
@@ -122,6 +135,14 @@ public class Address extends ASObject {
       set(REGION, region);
       return (M)this;
     }
+    public M building(String building) {
+      set(BUILDING,building);
+      return (M)this;
+    }
+    public M floor(String floor) {
+      set(FLOOR,floor);
+      return (M)this;
+    }
     public M streetAddress(String address) {
       set(STREETADDRESS,address);
       return (M)this;

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/PlaceObject.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/PlaceObject.java?rev=1209185&r1=1209184&r2=1209185&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/PlaceObject.java
(original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/PlaceObject.java
Thu Dec  1 18:59:06 2011
@@ -27,6 +27,11 @@ import org.apache.abdera2.common.geo.Poi
 
 import com.google.common.base.Supplier;
 
+/**
+ * Represents a location... can be logical or physical. At a minimum, the 
+ * place can be described in terms of a geological coordinates, an address, 
+ * or a name. 
+ */
 public class PlaceObject 
   extends ASObject {
   public static final String ADDRESS = "address";



Mime
View raw message