Friday 19 May 2017

Abdera : Atom Feed Element

Atom feed element is the top level element of atom feed document. A Feed element contains Meta data followed by zero (or) more Entry child elements.

a.   atom:feed elements MUST contain one or more atom:author elements, unless all of the atom:feed element's child atom:entry elements contain at least one atom:author element.

b.   atom:feed elements MAY contain any number of atom:category elements.

c.    atom:feed elements MAY contain any number of atom:contributor elements.

d.   atom:feed elements MUST NOT contain more than one atom:generator element.

e.   atom:feed elements MUST NOT contain more than one atom:icon element.

f.    atom:feed elements MUST NOT contain more than one atom:logo element.

g.   atom:feed elements MUST contain exactly one atom:id element.

h.   atom:feed elements SHOULD contain one atom:link element with a rel attribute value of "self".  This is the preferred URI for retrieving Atom Feed Documents representing this Atom feed.

i.     atom:feed elements MUST NOT contain more than one atom:link element with a rel attribute value of "alternate" that has the  same combination of type and hreflang attribute values.

j.    atom:feed elements MAY contain additional atom:link elements beyond those described above.

k.   atom:feed elements MUST NOT contain more than one atom:rights element.

l.     atom:feed elements MUST NOT contain more than one atom:subtitle element.

m. atom:feed elements MUST contain exactly one atom:title element.

n.   atom:feed elements MUST contain exactly one atom:updated element.

Can multiple entry documents exists with same id?
Yes, if multiple atom:entry elements with the same atom:id value appear in an Atom Feed Document, they represent the same entry.  Their atom:updated timestamps SHOULD be different.  If an Atom Feed Document contains multiple entries with the same atom:id, Atom Processors MAY choose to display all of them or some subset of them. One typical behavior would be to display only the entry with the latest atom:updated timestamp.

HelloWorld.java
import java.io.IOException;
import java.util.Date;

import org.apache.abdera.Abdera;
import org.apache.abdera.model.Content;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
import org.apache.abdera.model.Text;
import org.apache.abdera.writer.Writer;

public class HelloWorld {

 private static void addMetaData(Feed feed) {
  feed.setId("tag:blogger.com,1999:blog-3062500619105519975");
  feed.setUpdated(new Date());
  feed.setTitle("java tutorial : Blog to learn java programming");
  feed.setSubtitle("Learners Blog");
 }

 private static void addLinksToFeed(Feed feed) {
  /* Adding Links */
  String rel = "http://schemas.google.com/g/2005#feed";
  String type = "application/atom+xml";
  String href = "https://self-learning-java-tutorial.blogspot.com/feeds/posts/default";
  String title = "";
  String hreflang = "";
  long length = 0;

  feed.addLink(href, rel, type, title, hreflang, length);

  rel = "self";
  type = "application/atom+xml";
  href = "http://www.blogger.com/feeds/3062500619105519975/posts/default?alt=atom";

  feed.addLink(href, rel, type, title, hreflang, length);
 }

 private static void addAuthorToFeed(Feed feed) {
  String name = "hari krishna";
  String email = "noreply@blogger.com";
  String iri = "https://self-learning-java-tutorial.blogspot.com";

  feed.addAuthor(name, email, iri);
 }
 

 private static void addEntry(Feed feed) {

  Entry entry1 = feed.addEntry();
  entry1.setId("tag:blogger.com,1999:blog-3062500619105519975.post-918659526208416960");
  Date date = new Date();
  entry1.setPublished(date);
  entry1.setUpdated(date);
  entry1.setTitle("SWT: Slider Tutorial", Text.Type.TEXT);
  entry1.setContent("Slider class is used to define Slider widget", Content.Type.HTML);
  entry1.addAuthor("Hari Krishna Gurram", "noreply@blogger.com", "https://self-learning-java-tutorial.blogspot.com");
  
  Entry entry2 = feed.addEntry();
  entry2.setId("tag:blogger.com,1999:blog-3062500619105519975.post-918659526208416960");
  entry2.setPublished(date);
  entry2.setTitle("SWT: Slider Tutorial", Text.Type.HTML);
  entry2.setContent("Slider class is used to define Slider widget", Content.Type.HTML);
  entry2.addAuthor("Hari Krishna Gurram", "noreply@blogger.com", "https://self-learning-java-tutorial.blogspot.com");

  Entry entry3 = feed.addEntry();
  entry3.setId("tag:blogger.com,1999:blog-3062500619105519975.post-918659526208416960");
  entry3.setPublished(new Date());
  entry3.setTitle("SWT: Slider Tutorial", Text.Type.XHTML);
  entry3.setContent("Slider class is used to define Slider widget", Content.Type.HTML);
  entry3.addAuthor("Hari Krishna Gurram", "noreply@blogger.com", "https://self-learning-java-tutorial.blogspot.com");
  
  feed.addEntry(entry1);
  feed.addEntry(entry2);
  feed.addEntry(entry3);
 }

 public static void main(String args[]) throws IOException {
  Abdera abdera = new Abdera();

  /* Create a new Feed instance. */
  Feed feed = abdera.newFeed();

  /* Populate feed */
  addMetaData(feed);
  addLinksToFeed(feed);
  addAuthorToFeed(feed);
  addEntry(feed);

  /* Print the feed to console */
  Writer writer = abdera.getWriterFactory().getWriter("prettyxml");
  feed.writeTo(writer, System.out);
 }
}

Output
<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>tag:blogger.com,1999:blog-3062500619105519975</id>
  <updated>2016-12-17T06:34:39.566Z</updated>
  <title type="text">java tutorial : Blog to learn java programming</title>
  <subtitle type="text">Learners Blog</subtitle>
  <link href="https://self-learning-java-tutorial.blogspot.com/feeds/posts/default" rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" title="" hreflang="" length="0"/>
  <link href="http://www.blogger.com/feeds/3062500619105519975/posts/default?alt=atom" rel="self" type="application/atom+xml" title="" hreflang="" length="0"/>
  <author>
    <name>hari krishna</name>
    <email>noreply@blogger.com</email>
    <uri>https://self-learning-java-tutorial.blogspot.com</uri>
  </author>
  <entry>
    <id>tag:blogger.com,1999:blog-3062500619105519975.post-918659526208416960</id>
    <published>2016-12-17T06:34:39.588Z</published>
    <updated>2016-12-17T06:34:39.588Z</updated>
    <title type="text">SWT: Slider Tutorial</title>
    <content type="html">Slider class is used to define Slider widget</content>
    <author>
      <name>Hari Krishna Gurram</name>
      <email>noreply@blogger.com</email>
      <uri>https://self-learning-java-tutorial.blogspot.com</uri>
    </author>
  </entry>
  <entry>
    <id>tag:blogger.com,1999:blog-3062500619105519975.post-918659526208416960</id>
    <published>2016-12-17T06:34:39.588Z</published>
    <title type="html">SWT: Slider Tutorial</title>
    <content type="html">Slider class is used to define Slider widget</content>
    <author>
      <name>Hari Krishna Gurram</name>
      <email>noreply@blogger.com</email>
      <uri>https://self-learning-java-tutorial.blogspot.com</uri>
    </author>
  </entry>
  <entry>
    <id>tag:blogger.com,1999:blog-3062500619105519975.post-918659526208416960</id>
    <published>2016-12-17T06:34:39.590Z</published>
    <title type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">SWT: Slider Tutorial</div>
    </title>
    <content type="html">Slider class is used to define Slider widget</content>
    <author>
      <name>Hari Krishna Gurram</name>
      <email>noreply@blogger.com</email>
      <uri>https://self-learning-java-tutorial.blogspot.com</uri>
    </author>
  </entry>
</feed> 




Previous                                                 Next                                                 Home

No comments:

Post a Comment