Monday 22 May 2017

Abdera: Atom Id element

Id is a universal unique identifier given to a feed (or) element. The content of an atom:id element MUST be created in a way that assures uniqueness.

Example
<id>tag:blogger.com,1999:blog-3062500619105519975.post-918659526208416960</id>

Following normalization strategy SHOULD be applied when generating atom:id elements.

a. Provide the scheme in lowercase characters.
b. Provide the host, if any, in lowercase characters.
c. Only perform percent-encoding where it is essential.
d. Use uppercase A through F characters when percent-encoding.
e. Prevent dot-segments from appearing in paths.
f. For schemes that define a default authority, use an empty authority if the default is desired.
g. For schemes that define an empty path to be equivalent to a path of "/", use "/".
h. For schemes that define a port, use an empty port if the default is desired.
i. Preserve empty fragment identifiers and queries.
j. Ensure that all components of the IRI are appropriately character normalized, e.g., by using NFC or NFKC.

Feed and Entry interfaces provide setId method to set an id to feed, entry.

Following is the complete working application.

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");

  feed.addCategory("scheme", "Programming", "Java Tutorial for beginners");

  feed.addContributor("Krishna", "Krishna@Krishna.com", "https://self-learning-java-tutorial.blogspot.com");

  feed.setGenerator("http://www.blogger.com", "7.00", "Blogger");
  
  feed.setIcon("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJHpypki-Y-JqQUorVvFkZkU0JWZKxkb138p8W-saAaVr4qaPKTgpkE7BV8sqq0elgI_pDejsHMxTEmY2KPLgwrkfyQXwWqkXYWRUJIKj_ci1JDFzVpKg1lddacb8SifWynpsWfmR_RH4j/s1600/1.bmp");
 }

 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");
  entry1.addAuthor("Rama Krishna Gurram", "noreply@blogger.com",
    "https://self-learning-java-tutorial.blogspot.com");
  entry1.addContributor("Ritweek Mehenty", "noreply@blogger.com",
    "https://self-learning-java-tutorial.blogspot.com");
  entry1.addContributor("Sailaja Navakotla", "noreply@blogger.com",
    "https://self-learning-java-tutorial.blogspot.com");

  entry1.addCategory("scheme", "GUI", "SWT for beginners");

  feed.addEntry(entry1);
 }

 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-17T16:11:18.692Z</updated>
  <title type="text">java tutorial : Blog to learn java programming</title>
  <subtitle type="text">Learners Blog</subtitle>
  <category term="Programming" scheme="scheme" label="Java Tutorial for beginners"/>
  <contributor>
    <name>Krishna</name>
    <email>Krishna@Krishna.com</email>
    <uri>https://self-learning-java-tutorial.blogspot.com</uri>
  </contributor>
  <generator uri="http://www.blogger.com" version="7.00">Blogger</generator>
  <icon>https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJHpypki-Y-JqQUorVvFkZkU0JWZKxkb138p8W-saAaVr4qaPKTgpkE7BV8sqq0elgI_pDejsHMxTEmY2KPLgwrkfyQXwWqkXYWRUJIKj_ci1JDFzVpKg1lddacb8SifWynpsWfmR_RH4j/s1600/1.bmp</icon>
  <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-17T16:11:18.722Z</published>
    <updated>2016-12-17T16:11:18.722Z</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>
    <author>
      <name>Rama Krishna Gurram</name>
      <email>noreply@blogger.com</email>
      <uri>https://self-learning-java-tutorial.blogspot.com</uri>
    </author>
    <contributor>
      <name>Ritweek Mehenty</name>
      <email>noreply@blogger.com</email>
      <uri>https://self-learning-java-tutorial.blogspot.com</uri>
    </contributor>
    <contributor>
      <name>Sailaja Navakotla</name>
      <email>noreply@blogger.com</email>
      <uri>https://self-learning-java-tutorial.blogspot.com</uri>
    </contributor>
    <category term="GUI" scheme="scheme" label="SWT for beginners"/>
  </entry>
</feed>




Previous                                                 Next                                                 Home

No comments:

Post a Comment