abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r568231 - in /incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext: ./ Bidi.java Features.java Geo.java Json.java License.java Paging.java Sharing.java Thread.java
Date Tue, 21 Aug 2007 18:53:01 GMT
Author: jmsnell
Date: Tue Aug 21 11:53:00 2007
New Revision: 568231

URL: http://svn.apache.org/viewvc?rev=568231&view=rev
Log:
Some examples that show how some of the extensions work

Added:
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Bidi.java
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Features.java
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Geo.java
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Json.java
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/License.java
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Paging.java
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Sharing.java
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Thread.java

Added: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Bidi.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Bidi.java?rev=568231&view=auto
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Bidi.java
(added)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Bidi.java
Tue Aug 21 11:53:00 2007
@@ -0,0 +1,66 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.examples.ext;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.ext.bidi.BidiHelper;
+import org.apache.abdera.model.Entry;
+
+/**
+ * The Atom Bidi Extension is described in an IETF Internet-Draft and is used
+ * to communicate information about the base directionality of text in an Atom
+ * document.
+ */
+public class Bidi {
+
+  public static void main(String... args) throws Exception {
+    
+    String text = "\u05e4\u05e2\u05d9\u05dc\u05d5\u05ea \u05d4\u05d1\u05d9\u05e0\u05d0\u05d5\u05dd,
W3C";
+    
+    Abdera abdera = new Abdera();
+    Entry entry = abdera.newEntry();
+    BidiHelper.setDirection(BidiHelper.Direction.RTL, entry);
+    
+    entry.setTitle(text);
+    
+    // non bidi, incorrectly displayed
+    System.out.println(entry.getTitle()); 
+    
+    // with bidi, correctly displayed
+    System.out.println(
+      BidiHelper.getBidiElementText(
+        entry.getTitleElement()));
+    
+    // with bidi, correctly displayed
+    System.out.println(
+      BidiHelper.getBidiText(
+        BidiHelper.getDirection(entry), 
+        entry.getTitle()));
+    
+
+    // there are also direction guessing algorithms available
+    entry = abdera.newEntry();
+    entry.setTitle(text);
+    entry.setLanguage("ar");
+    
+    System.out.println(BidiHelper.guessDirectionFromJavaBidi(entry.getTitleElement()));
+    System.out.println(BidiHelper.guessDirectionFromTextProperties(entry.getTitleElement()));
+    System.out.println(BidiHelper.guessDirectionFromLanguage(entry.getTitleElement()));
+  }
+  
+}

Added: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Features.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Features.java?rev=568231&view=auto
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Features.java
(added)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Features.java
Tue Aug 21 11:53:00 2007
@@ -0,0 +1,90 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.examples.ext;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.ext.features.Feature;
+import org.apache.abdera.ext.features.FeatureSelector;
+import org.apache.abdera.ext.features.FeaturesHelper;
+import org.apache.abdera.model.Collection;
+import org.apache.abdera.model.Service;
+import org.apache.abdera.model.Workspace;
+
+/**
+ * The Atompub Features Extension is described in an IETF I-D and is used to
+ * communicate information about features that are supported, required or 
+ * unsupported by an Atompub collection.
+ */
+public class Features {
+
+  public static void main(String... args) throws Exception {
+    
+    Abdera abdera = new Abdera();
+    Service service = abdera.newService();
+    Workspace workspace = service.addWorkspace("My workspace");
+    Collection collection = workspace.addCollection("My collection", "foo");
+    
+    // Specify which features are supported by the collection
+    FeaturesHelper.addFeature(collection, FeaturesHelper.FEATURE_DRAFTS);
+    FeaturesHelper.addFeature(collection, FeaturesHelper.FEATURE_TEXT_TITLE, Feature.Status.REQUIRED);
+    FeaturesHelper.addFeature(collection, FeaturesHelper.FEATURE_SLUG, Feature.Status.UNSUPPORTED);
+    FeaturesHelper.addFeature(collection, FeaturesHelper.ABDERA_FEATURE_BIDI);
+    
+    // Get the support status of a specific feature
+    System.out.println(FeaturesHelper.getFeatureStatus(collection, FeaturesHelper.FEATURE_DRAFTS));
+    System.out.println(FeaturesHelper.getFeatureStatus(collection, FeaturesHelper.FEATURE_TEXT_TITLE));
+    System.out.println(FeaturesHelper.getFeatureStatus(collection, FeaturesHelper.FEATURE_SLUG));
+    System.out.println(FeaturesHelper.getFeatureStatus(collection, FeaturesHelper.ABDERA_FEATURE_BIDI));
+    System.out.println(FeaturesHelper.getFeatureStatus(collection, FeaturesHelper.ABDERA_FEATURE_GEO));
+    
+    
+    // Listing features by support status
+    Feature[] features = null;
+    features = FeaturesHelper.getRequiredFeatures(collection);
+    System.out.println("Required:");
+    for (Feature feature : features) {
+      System.out.println("\t" + feature.getRef());
+    }
+    
+    features = FeaturesHelper.getSupportedFeatures(collection);
+    System.out.println("Supported:");
+    for (Feature feature : features) {
+      System.out.println("\t" + feature.getRef());
+    }
+    
+    features = FeaturesHelper.getUnsupportedFeatures(collection);
+    System.out.println("Unsupported:");
+    for (Feature feature : features) {
+      System.out.println("\t" + feature.getRef());
+    }
+    
+    
+    // Select a collection by feature support status
+    Collection[] selectedCollections = 
+      FeaturesHelper.select(
+        service, 
+        new FeatureSelector(
+          FeaturesHelper.FEATURE_DRAFTS, 
+          FeaturesHelper.ABDERA_FEATURE_BIDI));
+    System.out.println("Selected Collections:");
+    for (Collection selected : selectedCollections) 
+      System.out.println("\t" + selected.getTitle());
+    
+  }
+  
+}

Added: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Geo.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Geo.java?rev=568231&view=auto
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Geo.java
(added)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Geo.java
Tue Aug 21 11:53:00 2007
@@ -0,0 +1,55 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.examples.ext;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.ext.geo.Coordinate;
+import org.apache.abdera.ext.geo.GeoHelper;
+import org.apache.abdera.ext.geo.Point;
+import org.apache.abdera.ext.geo.Position;
+import org.apache.abdera.model.Entry;
+
+/**
+ * The Geo extensions allow Atom entries to be geotagged using the Georss extensions.
+ */
+public class Geo {
+
+  public static void main(String... args) throws Exception {
+    
+    Abdera abdera = new Abdera();
+    Entry entry = abdera.newEntry();
+    entry.setTitle("Middle of the Ocean");
+    
+    Point point = new Point(new Coordinate(37.0625,-95.677068));
+    GeoHelper.addPosition(entry, point);
+    
+    Position[] positions = GeoHelper.getPositions(entry);
+    for (Position pos : positions) {
+      if (pos instanceof Point) {
+        Point p = (Point) pos;
+        System.out.println(p.getCoordinate());
+      }
+    }
+    
+    // By default, positions are encoded using the simple georss encoding,
+    // W3C and GML encodings are also supported
+    GeoHelper.addPosition(entry, point, GeoHelper.Encoding.W3C);
+    GeoHelper.addPosition(entry, point, GeoHelper.Encoding.GML);
+  }
+  
+}

Added: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Json.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Json.java?rev=568231&view=auto
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Json.java
(added)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Json.java
Tue Aug 21 11:53:00 2007
@@ -0,0 +1,62 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.examples.ext;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.writer.Writer;
+
+/**
+ * The JSONWriter can be used to serialize an Abdera entry into a JSON structure
+ */
+public class Json {
+
+  public static void main(String... args) throws Exception {
+    
+    Abdera abdera = new Abdera();
+    Entry entry = abdera.newEntry();
+    entry.newId();
+    entry.setTitle("test");
+    entry.setContentAsHtml("<b>foo</b>");
+    entry.addAuthor("James");
+    entry.addCategory("term");
+    
+    Writer w = abdera.getWriterFactory().getWriter("json");
+    entry.writeTo(w, System.out);
+    
+    /**
+     * Produces: 
+     * 
+     * {
+     *   "categories":[
+     *     {"term":"term"}
+     *   ],
+     *   "id":"urn:uuid:BFE2C793F1E4327BA91187720122895",
+     *   "content":{
+     *     "type":"html",
+     *     "value":"<b>foo<\/b>"},
+     *   "links":[],
+     *   "contributors":[],
+     *   "authors":[
+     *     {"name":"James"}
+     *   ],
+     *   "title":"test"}
+     */
+  }
+  
+}

Added: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/License.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/License.java?rev=568231&view=auto
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/License.java
(added)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/License.java
Tue Aug 21 11:53:00 2007
@@ -0,0 +1,68 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.examples.ext;
+
+import java.util.List;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.ext.license.LicenseHelper;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Link;
+
+/**
+ * The Atom License extension is described in Experimental RFC4946 and provides
+ * a way of associating copyright licenses with feeds and entries.  This is 
+ * useful when working with things like Creative Commons licenses.
+ */
+public class License {
+
+  public static void main(String... args) throws Exception {
+    
+    Abdera abdera = new Abdera();
+    Feed feed = abdera.newFeed();
+    Entry entry = feed.addEntry();
+    
+    // Add a license to the feed
+    LicenseHelper.addLicense(feed, "http://example.org/foo", "Foo");
+    
+    // does the feed have a license link?
+    System.out.println(LicenseHelper.hasLicense(feed));
+    
+    // does the feed have a specific license link?
+    System.out.println(LicenseHelper.hasLicense(feed, "http://example.org/foo"));
+    
+    // since the entry does not have a license, it inherits the feeds
+    System.out.println(LicenseHelper.hasLicense(entry));
+    System.out.println(LicenseHelper.hasLicense(entry, "http://example.org/foo"));
+    
+    // list the licenses
+    List<Link> licenses = LicenseHelper.getLicense(entry);
+    for (Link link : licenses) {
+      System.out.println(link.getResolvedHref());
+    }
+    
+    // Add an unspecified license to the entry
+    LicenseHelper.addUnspecifiedLicense(entry);
+    
+    // now the entry does not inherit the feeds license
+    System.out.println(LicenseHelper.hasLicense(entry, "http://example.org/foo"));
+    
+  }
+  
+}

Added: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Paging.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Paging.java?rev=568231&view=auto
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Paging.java
(added)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Paging.java
Tue Aug 21 11:53:00 2007
@@ -0,0 +1,58 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.examples.ext;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.ext.history.FeedPagingHelper;
+import org.apache.abdera.model.Feed;
+
+public class Paging {
+
+  public static void main(String... args) throws Exception {
+    
+    Abdera abdera = new Abdera();
+    Feed feed = abdera.newFeed();
+    
+    // Set/Get the paging links
+    FeedPagingHelper.setCurrent(feed, "feed");
+    FeedPagingHelper.setNext(feed, "feed?page=3");
+    FeedPagingHelper.setPrevious(feed, "feed?page=1");
+    FeedPagingHelper.setFirst(feed, "feed");
+    FeedPagingHelper.setLast(feed, "feed?page=10");
+    FeedPagingHelper.setNextArchive(feed, "feed?page=3");
+    FeedPagingHelper.setPreviousArchive(feed, "feed?page=1");
+    
+    System.out.println(FeedPagingHelper.getCurrent(feed));
+    System.out.println(FeedPagingHelper.getNext(feed));
+    System.out.println(FeedPagingHelper.getPrevious(feed));
+    System.out.println(FeedPagingHelper.getFirst(feed));
+    System.out.println(FeedPagingHelper.getLast(feed));
+    System.out.println(FeedPagingHelper.getNextArchive(feed));
+    System.out.println(FeedPagingHelper.getPreviousArchive(feed));
+
+    // Set/Get the archive flag
+    FeedPagingHelper.setArchive(feed, true);
+    if (FeedPagingHelper.isArchive(feed)) System.out.println("archive feed!");
+    
+    // Set/Get the complete flag
+    FeedPagingHelper.setComplete(feed, true);
+    if (FeedPagingHelper.isComplete(feed)) System.out.println("complete feed!");
+    
+  }
+  
+}

Added: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Sharing.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Sharing.java?rev=568231&view=auto
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Sharing.java
(added)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Sharing.java
Tue Aug 21 11:53:00 2007
@@ -0,0 +1,72 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.examples.ext;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.ext.sharing.Conflicts;
+import org.apache.abdera.ext.sharing.SharingHelper;
+import org.apache.abdera.ext.sharing.Sync;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+
+/**
+ * Basic Simple Sharing Extensions support
+ */
+public class Sharing {
+
+  public static void main(String... args) throws Exception {
+    
+    Abdera abdera = new Abdera();
+    
+    // Create two feeds
+    Feed f1 = abdera.newFeed();
+    Feed f2 = abdera.newFeed();
+    
+    // Create a couple of sharing-enabled entries
+    Entry e1 = SharingHelper.createEntry(abdera, "jms", f1);
+    e1.newId();
+    
+    Entry e2 = SharingHelper.createEntry(abdera, "jms", f1);
+    e2.newId();
+    
+    Entry e3 = (Entry) e2.clone();
+    f2.addEntry(e3);
+    
+    // concurrent modification of the same entry by two different users in two different
feeds
+    SharingHelper.updateEntry(e2, "bob");
+    SharingHelper.updateEntry(e3, "joe");
+    
+    // prepare a third feed for merging
+    Feed f3 = (Feed) f2.clone();
+    
+    // merge f1 with f2 to produce f3
+    SharingHelper.mergeFeeds(f1, f3);
+    
+    // there will be two entries in f3, one of which shows a conflict
+    for (Entry entry : f3.getEntries()) {
+      System.out.println(entry.getId());
+      if (SharingHelper.hasConflicts(entry)) {
+        Sync sync = SharingHelper.getSync(entry);
+        Conflicts conflicts = sync.getConflicts();
+        System.out.println("\tNumber of conflicts: " + conflicts.getEntries().size());
+      }
+    }
+    
+  }
+  
+}

Added: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Thread.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Thread.java?rev=568231&view=auto
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Thread.java
(added)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/Thread.java
Tue Aug 21 11:53:00 2007
@@ -0,0 +1,60 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.examples.ext;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.ext.thread.InReplyTo;
+import org.apache.abdera.ext.thread.ThreadHelper;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Link;
+
+/**
+ * The Atom Threading Extensions are described in RFC4685 and provide a means
+ * of representing threaded discussions and parent/child relationships in 
+ * Atom.
+ */
+public class Thread {
+
+  public static void main(String... args) throws Exception {
+
+    Abdera abdera = new Abdera();
+    Entry e1 = abdera.newEntry();
+    Entry e2 = abdera.newEntry();
+    
+    e1.newId();
+    e2.newId();
+    
+    // Entry e2 is a reply to Entry e1
+    ThreadHelper.addInReplyTo(e2, e1);
+    
+    // Get the in-reply-to information
+    InReplyTo irt = ThreadHelper.getInReplyTo(e2);
+    System.out.println(irt.getRef());
+    
+    // Add a link to a feed containing replies to e1
+    Link replies = e1.addLink("replies.xml", Link.REL_REPLIES);
+    
+    // Set the known number of replies as an attribute on the link 
+    ThreadHelper.setCount(replies, 10);
+    
+    // alternatively, use the thr:total element to specify the number of replies
+    ThreadHelper.addTotal(e1, 10);
+    
+  }
+
+}



Mime
View raw message