{title:'Atom'}

The Juneau ATOM feed DTOs are simply beans with fluent-style setters. The following code shows a feed being created programmatically using the {@link oaj.dto.atom.AtomBuilder} class.

| import static org.apache.juneau.dto.atom.AtomBuilder.*; | | Feed feed = | feed("tag:juneau.apache.org", "Juneau ATOM specification", "2016-01-02T03:04:05Z") | .setSubtitle(text("html").setText("Describes <em>stuff</em> 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><p><i>[Update: Juneau supports ATOM.]</i></p></div>") | ) | );

To serialize this to ATOM, use the {@link oaj.xml.XmlSerializer} class:

##### Example with no namespaces

| // Create a serializer with readable output, no namespaces yet. | XmlSerializer serializer = XmlSerializer.create().sq().ws().build(); | | // Serialize to ATOM/XML | String atomXml = serializer.serialize(feed);

##### Results

| <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 <em>stuff</em> 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.apache.org | </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='12345'/> | <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 {@link oaj.xml.XmlParser} class can be used convert these Atom documents back into POJOs.

Other serializers and parsers (e.g. {@link oaj.json.JsonSerializer}) can be used to represent these POJOs in languages other than XML.