abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1174409 - in /abdera/abdera2: ./ activities/ client/ common/ core/ core/src/main/java/org/apache/abdera2/model/ core/src/main/java/org/apache/abdera2/parser/axiom/ ext/ ext/src/main/java/org/apache/abdera2/ext/activities/ ext/src/main/java...
Date Thu, 22 Sep 2011 21:58:03 GMT
Author: jmsnell
Date: Thu Sep 22 21:58:02 2011
New Revision: 1174409

URL: http://svn.apache.org/viewvc?rev=1174409&view=rev
Log:
Several changes: 

1. Ignore mvn build artifacts 
2. New method on Link/FOMLink.. getCanonicalRel()
3. Generic Atom Feed to JSON Activity Stream conversion utility 

Added:
    abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/activities/
    abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/activities/FeedToActivityConverter.java
  (with props)
Modified:
    abdera/abdera2/   (props changed)
    abdera/abdera2/activities/   (props changed)
    abdera/abdera2/client/   (props changed)
    abdera/abdera2/common/   (props changed)
    abdera/abdera2/core/   (props changed)
    abdera/abdera2/core/src/main/java/org/apache/abdera2/model/Link.java
    abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMLink.java
    abdera/abdera2/ext/   (props changed)
    abdera/abdera2/ext/pom.xml
    abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/json/JSONWriter.java
    abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssEnclosure.java
    abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssGuid.java
    abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssLink.java
    abdera/abdera2/security/   (props changed)
    abdera/abdera2/server/   (props changed)
    abdera/abdera2/test/   (props changed)

Propchange: abdera/abdera2/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Sep 22 21:58:02 2011
@@ -0,0 +1 @@
+target

Propchange: abdera/abdera2/activities/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Sep 22 21:58:02 2011
@@ -0,0 +1 @@
+target

Propchange: abdera/abdera2/client/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Sep 22 21:58:02 2011
@@ -0,0 +1 @@
+target

Propchange: abdera/abdera2/common/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Sep 22 21:58:02 2011
@@ -0,0 +1 @@
+target

Propchange: abdera/abdera2/core/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Sep 22 21:58:02 2011
@@ -0,0 +1 @@
+target

Modified: abdera/abdera2/core/src/main/java/org/apache/abdera2/model/Link.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/model/Link.java?rev=1174409&r1=1174408&r2=1174409&view=diff
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/model/Link.java (original)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/model/Link.java Thu Sep 22 21:58:02
2011
@@ -128,6 +128,13 @@ public interface Link extends Extensible
     String getRel();
 
     /**
+     * Get the canonical rel attribute value (e.g. if the rel is a known 
+     * type but uses the IANA url base, strip that and return just the simple 
+     * name, otherwise, return the full URI form)
+     */
+    String getCanonicalRel();
+    
+    /**
      * <p>
      * RFC4287: atom:link elements MAY have a "rel" attribute that indicates the link relation
type. If the "rel"
      * attribute is not present, the link element MUST be interpreted as if the link relation
type is "alternate"... The

Modified: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMLink.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMLink.java?rev=1174409&r1=1174408&r2=1174409&view=diff
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMLink.java (original)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMLink.java Thu Sep
22 21:58:02 2011
@@ -91,6 +91,13 @@ public class FOMLink extends FOMExtensib
     public String getRel() {
         return getAttributeValue(REL);
     }
+    
+    public String getCanonicalRel() {
+      String rel = getRel();
+      if (rel != null && rel.startsWith(IANA_BASE))
+        rel = Link.Helper.getRelEquiv(rel);
+      return rel != null ? rel : Link.REL_ALTERNATE;
+    }
 
     public Link setRel(String rel) {
       complete();

Propchange: abdera/abdera2/ext/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Sep 22 21:58:02 2011
@@ -0,0 +1 @@
+target

Modified: abdera/abdera2/ext/pom.xml
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/pom.xml?rev=1174409&r1=1174408&r2=1174409&view=diff
==============================================================================
--- abdera/abdera2/ext/pom.xml (original)
+++ abdera/abdera2/ext/pom.xml Thu Sep 22 21:58:02 2011
@@ -70,6 +70,12 @@
       <version>2.0-SNAPSHOT</version>  
       <scope>compile</scope>
     </dependency> 
+    <dependency>
+      <groupId>org.apache.abdera2</groupId>
+      <artifactId>abdera2-activities</artifactId>
+      <version>2.0-SNAPSHOT</version>  
+      <scope>compile</scope>
+    </dependency> 
     
     <dependency>
       <groupId>javax</groupId>

Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/activities/FeedToActivityConverter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/activities/FeedToActivityConverter.java?rev=1174409&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/activities/FeedToActivityConverter.java
(added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/activities/FeedToActivityConverter.java
Thu Sep 22 21:58:02 2011
@@ -0,0 +1,240 @@
+package org.apache.abdera2.ext.activities;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.activities.model.ASBase;
+import org.apache.abdera2.activities.model.ASObject;
+import org.apache.abdera2.activities.model.Activity;
+import org.apache.abdera2.activities.model.Collection;
+import org.apache.abdera2.activities.model.CollectionWriter;
+import org.apache.abdera2.activities.model.MediaLink;
+import org.apache.abdera2.activities.model.Verb;
+import org.apache.abdera2.activities.model.objects.PersonObject;
+import org.apache.abdera2.activities.model.objects.ServiceObject;
+import org.apache.abdera2.common.Constants;
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.common.selector.Selector;
+import org.apache.abdera2.ext.history.FeedPagingHelper;
+import org.apache.abdera2.model.Category;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.ExtensibleElement;
+import org.apache.abdera2.model.Feed;
+import org.apache.abdera2.model.Link;
+import org.apache.abdera2.model.Person;
+import org.apache.abdera2.model.Generator;
+import org.apache.abdera2.model.Text;
+import org.apache.abdera2.model.selector.LinkRelSelector;
+
+/**
+ * A default Atom Feed to Activity Stream Conversion implementation. 
+ * Applications can customize the conversion process by subclassing
+ * this class and overriding the various conversion methods.
+ */
+public class FeedToActivityConverter {
+
+  public static final String NS = "http://activitystrea.ms/spec/1.0/";
+  
+  public static final QName VERB = new QName(NS,"verb");
+  public static final QName TARGET = new QName(NS,"target");
+  public static final QName OBJECT = new QName(NS,"object");
+  public static final QName OBJECTTYPE = new QName(NS,"object-type");
+  
+  public void convert(Feed feed, CollectionWriter writer) {
+    convert(feed,writer,null);
+  }
+  
+  public void convert(
+    Feed feed, 
+    CollectionWriter writer, 
+    Selector selector) {
+    ASBase header = header(feed);
+    if (header != null)
+      writer.writeHeader(header);
+    Iterable<Entry> entries = 
+      selector != null ? 
+        feed.getEntries(selector) : 
+        feed.getEntries();
+    for (Entry entry : entries) {
+      Activity activity = item(entry);
+      if (activity != null)
+        writer.writeObject(activity);
+    }
+    writer.complete();
+  }
+
+  protected ASBase header(Feed feed) {
+    Collection<Activity> col = 
+      new Collection<Activity>();
+    col.setId(feed.getId().toString());
+    col.setAuthor(authors(feed.getAuthors()));
+    col.setProperty("contributors", authors(feed.getContributors()));
+    categories(feed.getCategories(), col);
+    col.setProperty("generator", generator(feed.getGenerator()));
+    col.setImage(image(feed.getIcon()));
+    col.setUrl(feed.getAlternateLinkResolvedHref());
+    col.setDisplayName(feed.getTitle());
+    col.setSummary(feed.getSubtitle());
+    col.setUpdated(feed.getUpdated());
+    col.setProperty("nextLink", FeedPagingHelper.getNext(feed));
+    col.setProperty("previousLink", FeedPagingHelper.getPrevious(feed));
+    col.setProperty("firstLink", FeedPagingHelper.getFirst(feed));
+    col.setProperty("lastLink", FeedPagingHelper.getLast(feed));
+    col.setProperty("selfLink", feed.getSelfLinkResolvedHref());
+    return col;
+  }
+  
+  protected Verb verb(Entry entry) {
+    Verb verb = Verb.POST;
+    if (entry.has(VERB)) {
+      String val = entry.getSimpleExtension(VERB);
+      // might be a url, just get the last component
+      int n = val.indexOf('/');
+      if (n > -1) val = val.substring(n+1);
+      verb = Verb.get(val);
+    }
+    return verb;
+  }
+  
+  protected Activity item(Entry entry) {
+    Activity activity = new Activity();
+    activity.setId(entry.getId().toString());
+    activity.setUpdated(entry.getUpdated());
+    activity.setPublished(entry.getPublished());
+    activity.setUrl(entry.getAlternateLinkResolvedHref());
+    activity.setTitle(entry.getTitle());
+    activity.setSummary(entry.getSummary());
+    categories(entry.getCategories(), activity);
+    activity.setLang(entry.getLanguageTag());
+    activity.setVerb(verb(entry));
+    List<Person> authors = entry.getAuthorsInherited();
+    activity.setActor(authors(authors));
+    activity.setProperty("contributors", authors(entry.getContributors()));
+    activity.setObject(object(entry));
+    activity.setTarget(target(entry));
+    List<Link> enclosures = entry.getLinks("enclosure");
+    for (Link link : enclosures) {
+      activity.addAttachment(
+        attachment(link));
+    }
+    return activity;
+  }
+  
+  protected ASObject object(ExtensibleElement ext) {
+    ASObject obj = new ASObject();
+    if (ext.has(Constants.ID))
+      obj.setId(ext.getSimpleExtension(Constants.ID));
+    if (ext.has(Constants.TITLE)) {
+      Text text = ext.getExtension(Constants.TITLE);
+      obj.setDisplayName(text.getValue());
+    }
+    if (ext.has(Constants.SUMMARY)) {
+      Text text = ext.getExtension(Constants.SUMMARY);
+      obj.setSummary(text.getValue());
+    }
+    if (ext.has(OBJECTTYPE)) {
+      String val = ext.getSimpleExtension(OBJECTTYPE);
+      int n = val.lastIndexOf('/');
+      if (n > -1) val = val.substring(n+1);
+      obj.setObjectType(val);
+    }
+    LinkRelSelector sel = 
+      new LinkRelSelector("alternate","preview");
+    List<Link> links = ext.getExtensions(Constants.LINK, sel);
+    for (Link link : links) {
+      String rel = link.getCanonicalRel();
+      if (Link.REL_ALTERNATE.equalsIgnoreCase(rel)) {
+        obj.setUrl(link.getResolvedHref());
+      } else if ("preview".equalsIgnoreCase(rel)) {
+        obj.setImage(image(link.getResolvedBaseUri()));
+      }
+    }
+    return obj;
+  }
+  
+  protected ASObject target(Entry entry) {
+    return entry.has(TARGET) ?
+        object((ExtensibleElement)entry.getExtension(TARGET)) :
+        null;
+  }
+  
+  protected ASObject object(Entry entry) {    
+    return entry.has(OBJECT) ?
+      object((ExtensibleElement)entry.getExtension(OBJECT)) :
+      object((ExtensibleElement)entry);
+  }
+  
+  protected ASObject attachment(Link link) {
+    ASObject obj = new ASObject();
+    obj.setUrl(link.getResolvedHref());
+    obj.setProperty("mimeType", link.getMimeType());
+    obj.setDisplayName(link.getTitle());
+    obj.setProperty("hreflang", link.getHrefLang());
+    obj.setObjectType("link");
+    return obj;
+  }
+  
+  protected MediaLink image(IRI iri) {
+    MediaLink link = null;
+    if (iri != null) {
+      link = new MediaLink();
+      link.setUrl(iri);
+    }
+    return link;
+  }
+  
+  protected ASObject generator(Generator generator) {
+    ASObject _generator = null;
+    if (generator != null) {
+      _generator = new ServiceObject();
+      _generator.setDisplayName(generator.getText());
+      _generator.setProperty("version", generator.getVersion());
+      _generator.setUrl(generator.getUri());
+    }
+    return _generator;
+  }
+  
+  protected void categories(List<Category> categories, ASObject obj) {
+    for (Category category : categories)
+      obj.addTag(category(category));
+  }
+  
+  protected ASObject category(Category category) {
+    ASObject _category = new ASObject("category");
+    _category.setDisplayName(category.getTerm());
+    if (category.getScheme() != null)
+      _category.setProperty("scheme", category.getScheme());
+    return _category;
+  }
+  
+  protected ASObject authors(List<Person> authors) {
+    if (authors.size() == 1) {
+      return person(authors.get(0));
+    } else if (authors.size() > 1) {
+      Collection<PersonObject> _authors = 
+        new Collection<PersonObject>();
+      for (Person person : authors) {
+        PersonObject _person = person(person);
+        if (_person != null) 
+          _authors.addItem(_person);
+      }
+      return _authors;
+    } else return null;
+  }
+  
+  protected PersonObject person(Person person) {
+    PersonObject _person = new PersonObject();
+    _person.setDisplayName(person.getName());
+    if (person.getUri() != null)
+      _person.setUrl(person.getUri());
+    if (person.getEmail() != null) {
+      Set<String> emails = new HashSet<String>();
+      emails.add(person.getEmail());
+      _person.setEmails(emails);
+    }
+    return _person;
+  }
+}

Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/activities/FeedToActivityConverter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/json/JSONWriter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/json/JSONWriter.java?rev=1174409&r1=1174408&r2=1174409&view=diff
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/json/JSONWriter.java (original)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/json/JSONWriter.java Thu Sep 22
21:58:02 2011
@@ -34,7 +34,12 @@ import org.apache.abdera2.writer.WriterO
 public class JSONWriter extends AbstractWriter {
 
     public JSONWriter(Abdera abdera) {
-        super("application/json", "application/javascript", "application/ecmascript", "text/javascript",
"text/ecmascript");
+        super(
+          "application/json", 
+          "application/javascript", 
+          "application/ecmascript", 
+          "text/javascript", 
+          "text/ecmascript");
     }
 
     @Override

Modified: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssEnclosure.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssEnclosure.java?rev=1174409&r1=1174408&r2=1174409&view=diff
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssEnclosure.java (original)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssEnclosure.java Thu Sep
22 21:58:02 2011
@@ -66,6 +66,10 @@ public class RssEnclosure extends Extens
         return "enclosure";
     }
 
+    public String getCanonicalRel() {
+      return getRel();
+    }
+    
     public IRI getResolvedHref() {
         return getHref();
     }

Modified: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssGuid.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssGuid.java?rev=1174409&r1=1174408&r2=1174409&view=diff
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssGuid.java (original)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssGuid.java Thu Sep 22 21:58:02
2011
@@ -83,6 +83,10 @@ public class RssGuid extends ExtensibleE
     public String getRel() {
         return Link.REL_ALTERNATE;
     }
+    
+    public String getCanonicalRel() {
+      return getRel();
+    }
 
     public IRI getResolvedHref() {
         return getValue();

Modified: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssLink.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssLink.java?rev=1174409&r1=1174408&r2=1174409&view=diff
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssLink.java (original)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssLink.java Thu Sep 22 21:58:02
2011
@@ -63,6 +63,10 @@ public class RssLink extends ExtensibleE
             return Link.REL_ALTERNATE;
         }
     }
+    
+    public String getCanonicalRel() {
+      return getRel();
+    }
 
     public IRI getResolvedHref() {
         return getHref();

Propchange: abdera/abdera2/security/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Sep 22 21:58:02 2011
@@ -0,0 +1 @@
+target

Propchange: abdera/abdera2/server/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Sep 22 21:58:02 2011
@@ -0,0 +1 @@
+target

Propchange: abdera/abdera2/test/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Sep 22 21:58:02 2011
@@ -0,0 +1 @@
+target



Mime
View raw message