juneau-bean-atom
The Juneau ATOM feed DTO beans are plain beans with fluent-style setters, built through AtomBuilder.
When to use it
Use these beans to produce or consume an ATOM feed from Java without writing XML by hand. Serialize a Feed with the XML serializer, or with any other serializer to get the same feed as JSON.
Example
import static org.apache.juneau.bean.atom.AtomBuilder.*;
import org.apache.juneau.bean.atom.*;
import org.apache.juneau.marshall.xml.*;
public class AtomExample {
public static void main(String[] args) throws Exception {
Feed feed =
feed("tag:juneau.apache.org", "Juneau ATOM specification", "2016-01-02T03:04:05Z")
.setSubtitle(text("html").setText("Describes stuff about Juneau"))
.setLinks(link("self", "application/atom+xml", "http://juneau.apache.org/feed.atom"))
.setEntries(
entry("tag:juneau.sample.com,2013:1.2345", "Juneau ATOM specification snapshot", "2016-01-02T03:04:05Z")
.setAuthors(person("Jane Smith").setEmail("janesmith@apache.org"))
);
XmlSerializer serializer = XmlSerializer.create().sq().ws().build();
System.out.println(serializer.write(feed));
}
}
The output is the feed as XML:
<feed>
<entry>
<author>
<email>janesmith@apache.org</email>
<name>Jane Smith</name>
</author>
<id>tag:juneau.sample.com,2013:1.2345</id>
<title>Juneau ATOM specification snapshot</title>
<updated>2016-01-02T03:04:05Z</updated>
</entry>
<id>tag:juneau.apache.org</id>
<link href='http://juneau.apache.org/feed.atom' rel='self' type='application/atom+xml'/>
<subtitle type='html'>Describes stuff about Juneau</subtitle>
<title>Juneau ATOM specification</title>
<updated>2016-01-02T03:04:05Z</updated>
</feed>
Options
| Builder | Creates |
|---|---|
feed(id, title, updated) | The Feed root |
entry(id, title, updated) | A feed Entry |
link(rel, type, href) | A Link |
person(name) | An author or contributor |
text(type) / content(type) | Typed text and entry content |
generator(name) | The Generator |
A fuller feed
The following code builds a feed with links, a generator, contributors and entry content.
import static org.apache.juneau.bean.atom.AtomBuilder.*;
Feed feed =
feed("tag:juneau.apache.org", "Juneau ATOM specification", "2016-01-02T03:04:05Z")
.setSubtitle(text("html").setText("Describes stuff about Juneau"))
.setLinks(
link("alternate", "text/html", "http://juneau.apache.org").setHreflang("en"),
link("self", "application/atom+xml", "http://juneau.apache.org/feed.atom")
)
.setRights("Copyright (c) ...")
.setGenerator(
generator("Juneau").setUri("http://juneau.apache.org/").setVersion("1.0")
)
.setEntries(
entry("tag:juneau.sample.com,2013:1.2345", "Juneau ATOM specification snapshot", "2016-01-02T03:04:05Z")
.setLinks(
link("alternate", "text/html", "http://juneau.apache.org/juneau.atom"),
link("enclosure", "audio/mpeg", "http://juneau.apache.org/audio/juneau_podcast.mp3").setLength(1337)
)
.setPublished("2016-01-02T03:04:05Z")
.setAuthors(
person("Jane Smith").setUri("http://juneau.apache.org/").setEmail("janesmith@apache.org")
)
.setContributors(
person("John Smith")
)
.setContent(
content("xhtml")
.setLang("en")
.setBase("http://www.apache.org/")
.setText("<div xmlns='http://www.w3.org/1999/xhtml'><p><i>[Update: Juneau supports ATOM.]</i></p></div>")
)
);
Serialize it with the same XmlSerializer call as above. The result is:
<feed>
<id>
tag:juneau.apache.org
</id>
<link href='http://juneau.apache.org/' rel='alternate'
type='text/html' hreflang='en'/>
<link href='http://juneau.apache.org/feed.atom' rel='self'
type='application/atom+xml'/>
<rights>
Copyright (c) ...
</rights>
<title type='text'>
Juneau ATOM specification
</title>
<updated>2016-01-02T03:04:05Z</updated>
<generator uri='http://juneau.apache.org/' version='1.0'>
Juneau
</generator>
<subtitle type='html'>
Describes stuff about Juneau
</subtitle>
<entry>
<author>
<name>Jane Smith</name>
<uri>http://juneau.apache.org/</uri>
<email>janesmith@apache.org</email>
</author>
<contributor>
<name>John Smith</name>
</contributor>
<id>
tag:juneau.sample.com,2013:1.2345
</id>
<link href='http://juneau.apache.org/juneau.atom'
rel='alternate' type='text/html'/>
<link href='http://juneau.apache.org/audio/juneau_podcast.mp3'
rel='enclosure' type='audio/mpeg' length='1337'/>
<title>
Juneau ATOM specification snapshot
</title>
<updated>2016-01-02T03:04:05Z</updated>
<content base='http://www.apache.org/' lang='en'
type='xhtml'>
<div xmlns="http://www.w3.org/1999/xhtml">
<p><i>[Update: Juneau supports ATOM.]</i></p>
</div>
</content>
<published>2016-01-02T03:04:05Z</published>
</entry>
</feed>
The XmlParser class can be used convert these Atom documents back into POJOs.
Other serializers and parsers (e.g. JsonSerializer) can be used to represent these POJOs in languages other than XML.