Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Abdera: Atom Content Element

By using Atom content element, you can specify the content of the entry. It either contains the content or links to the content of the entry.

There are two attributes ‘type’, ‘src’ associated with content element.

type attribute
Type attribute specifies the type of the content. It can be one of "text", "html", or "xhtml". If you don’t specify type attribute, it consider ‘text’ as default type.

src attribute
‘src’ attribute is used to give IRI reference to the content. If the "src" attribute is present, atom:content MUST be empty. Atom processors use the value of src attribute to get the content.

Entry interface provides following overloaded methods to set the content to an entry.

Entry setContentElement(Content content);
Content setContent(String value);
Content setContentAsHtml(String value);
Content setContentAsXhtml(String value);
Content setContentAsXhtml(String value);
Content setContent(Element value);
Content setContent(Element element, String mediaType);
Content setContent(DataHandler dataHandler);
Content setContent(DataHandler dataHandler, String mediatype);
Content setContent(InputStream inputStream);
Content setContent(InputStream inputStream, String mediatype);
Content setContent(String value, String mediatype);
Content setContent(IRI uri, String mediatype);

Entry with only src attribute (No content)

tag:blogger.com,1999:blog-3062500619105519975.post-918659526208416961120
2016-12-17T08:02:37.966Z
2016-12-17T08:02:37.966Z

Hari Krishna Gurram
[email protected]
http://self-learning-java-tutorial.blogspot.com

type="application/xhtml+xml" src="http://self-learning-java-tutorial.blogspot.in/2016/11/eclipse-swt-tutorial.html"/>


Entry with content

tag:blogger.com,1999:blog-3062500619105519975.post-918659526208416960
2016-12-17T08:02:37.966Z
2016-12-17T08:02:37.966Z
<span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text"</span><span style="color: #007700;">></span>SWT: Slider Tutorial<span style="color: #007700;"></span>
type="html">Slider class is used to define Slider widget

Hari Krishna Gurram
[email protected]
http://self-learning-java-tutorial.blogspot.com


Rama Krishna Gurram
[email protected]
http://self-learning-java-tutorial.blogspot.com


Ritweek Mehenty
[email protected]
http://self-learning-java-tutorial.blogspot.com


Sailaja Navakotla
[email protected]
http://self-learning-java-tutorial.blogspot.com




Find the complete working application.

HelloWorld.java
package abdera_tutorial.abdera_tutorial;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;

import org.apache.abdera.Abdera;
import org.apache.abdera.i18n.iri.IRI;
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 = "http://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 = "[email protected]";
String iri = "http://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", "[email protected]", "http://self-learning-java-tutorial.blogspot.com");
entry1.addAuthor("Rama Krishna Gurram", "[email protected]", "http://self-learning-java-tutorial.blogspot.com");
entry1.addContributor("Ritweek Mehenty", "[email protected]", "http://self-learning-java-tutorial.blogspot.com");
entry1.addContributor("Sailaja Navakotla", "[email protected]", "http://self-learning-java-tutorial.blogspot.com");


Entry entry2 = feed.addEntry();
entry2.setId("tag:blogger.com,1999:blog-3062500619105519975.post-918659526208416961120");
entry2.setPublished(date);
entry2.setUpdated(date);
entry2.addAuthor("Hari Krishna Gurram", "[email protected]", "http://self-learning-java-tutorial.blogspot.com");
try {
entry2.setContent(new IRI(new URL("http://self-learning-java-tutorial.blogspot.in/2016/11/eclipse-swt-tutorial.html")), "application/xhtml+xml");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

feed.addEntry(entry1);
feed.addEntry(entry2);
}

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

xmlns="http://www.w3.org/2005/Atom">
tag:blogger.com,1999:blog-3062500619105519975
2016-12-17T08:05:04.460Z
<span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text"</span><span style="color: #007700;">></span>java tutorial : Blog to learn java programming<span style="color: #007700;"></span>
type="text">Learners Blog
href="http://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"/>
href="http://www.blogger.com/feeds/3062500619105519975/posts/default?alt=atom" rel="self" type="application/atom+xml" title="" hreflang="" length="0"/>

hari krishna
[email protected]
http://self-learning-java-tutorial.blogspot.com


tag:blogger.com,1999:blog-3062500619105519975.post-918659526208416960
2016-12-17T08:05:04.479Z
2016-12-17T08:05:04.479Z
<span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text"</span><span style="color: #007700;">></span>SWT: Slider Tutorial<span style="color: #007700;"></span>
type="html">Slider class is used to define Slider widget

Hari Krishna Gurram
[email protected]
http://self-learning-java-tutorial.blogspot.com


Rama Krishna Gurram
[email protected]
http://self-learning-java-tutorial.blogspot.com


Ritweek Mehenty
[email protected]
http://self-learning-java-tutorial.blogspot.com


Sailaja Navakotla
[email protected]
http://self-learning-java-tutorial.blogspot.com



tag:blogger.com,1999:blog-3062500619105519975.post-918659526208416961120
2016-12-17T08:05:04.479Z
2016-12-17T08:05:04.479Z

Hari Krishna Gurram
[email protected]
http://self-learning-java-tutorial.blogspot.com

type="application/xhtml+xml" src="http://self-learning-java-tutorial.blogspot.in/2016/11/eclipse-swt-tutorial.html"/>








Previous                                                 Next                                                 Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Abdera: Atom Content Element

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×