A
Text construct contains small quantity of human readable text. For example,
title of the entry comes under text construct.
Text
constructs use 'type' attribute to specify the type of the text. For example
type can be text, html, xhtml.
Text constructs
supported by ATOM Protocol
Atom
allows three kinds of Text constructs
a.
Text
: consisting of content that is to be interpreted as plain text with no markup.
b.
HTML
: consisting of content that is to be interpreted escaped HTML markup.
c.
XHTML : consisting of well-formed XHTML
content wrapped in an XHTML div element.
org.apache.abdera.model.Text
interface provide constants like Type.TEXT, Type.HTML, Type.XHTML to represent
type the text construct.
1. Forming Text
construct of type 'text'.
Entry
entry1 = feed.addEntry();
entry1.setTitle("SWT:
Slider Tutorial", Text.Type.TEXT);
Above
statements interpreted like below.
<title
type="text">SWT: Slider Tutorial</title>
2. Forming Text
construct of type 'html'.
Entry
entry2 = feed.addEntry();
entry2.setTitle("SWT:
Slider Tutorial", Text.Type.HTML);
Above
statement interpreted like below.
<title
type="html">SWT: Slider Tutorial</title>
3. Forming Text construct
of type xhtml.
Entry
entry3 = feed.addEntry();
entry3.setTitle("SWT:
Slider Tutorial", Text.Type.XHTML);
Above
statement interpreted like below.
<title
type="xhtml">
<div
xmlns="http://www.w3.org/1999/xhtml">SWT: Slider
Tutorial</div>
</title>
If
type is xhtml, then content is wrapped inside div element.
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"); } 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"; feed.addAuthor(name, email, ""); } private static void addEntry(Feed feed) { Entry entry1 = feed.addEntry(); entry1.setId("tag:blogger.com,1999:blog-3062500619105519975.post-918659526208416960"); entry1.setPublished(new Date()); entry1.setTitle("SWT: Slider Tutorial", Text.Type.TEXT); entry1.setContent("Slider class is used to define Slider widget", Content.Type.HTML); Entry entry2 = feed.addEntry(); entry2.setId("tag:blogger.com,1999:blog-3062500619105519975.post-918659526208416960"); entry2.setPublished(new Date()); entry2.setTitle("SWT: Slider Tutorial", Text.Type.HTML); entry2.setContent("Slider class is used to define Slider widget", Content.Type.HTML); 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); 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-16T11:33:57.685Z</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></uri> </author> <entry> <id>tag:blogger.com,1999:blog-3062500619105519975.post-918659526208416960</id> <published>2016-12-16T11:33:57.702Z</published> <title type="text">SWT: Slider Tutorial</title> <content type="html">Slider class is used to define Slider widget</content> </entry> <entry> <id>tag:blogger.com,1999:blog-3062500619105519975.post-918659526208416960</id> <published>2016-12-16T11:33:57.704Z</published> <title type="html">SWT: Slider Tutorial</title> <content type="html">Slider class is used to define Slider widget</content> </entry> <entry> <id>tag:blogger.com,1999:blog-3062500619105519975.post-918659526208416960</id> <published>2016-12-16T11:33:57.704Z</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> </entry> </feed>
No comments:
Post a Comment