001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.examples.core.dto.atom;
014
015import org.apache.juneau.dto.atom.Feed;
016import org.apache.juneau.xml.XmlSerializer;
017
018/**
019 * Atom feed XML example.
020 *
021 * <h5 class='section'>See Also:</h5><ul>
022 * </ul>
023 */
024public class AtomXmlExample {
025
026   /**
027    * XML Atom feed example.
028    *
029    * @param args Unused.
030    * @throws Exception Unused.
031    */
032   @SuppressWarnings("unused")
033   public static void main(String[] args) throws Exception {
034
035
036      Feed feed = AtomFeed.getAtomFeed();
037
038      // Example with no namespaces
039      // Create a serializer with readable output, no namespaces yet.
040      XmlSerializer s = XmlSerializer.create().sq().ws().build();
041
042      //Produces
043      /**
044       *<feed>
045       *<id> tag:juneau.apache.org</id>
046       *<link href='http://juneau.apache.org/' rel='alternate' type='text/html' hreflang='en'/>
047       *<link href='http://juneau.apache.org/feed.atom' rel='self' type='application/atom+xml'/>
048       *<title type='text'>Juneau ATOM specification</title>
049       *<updated>2016-01-02T03:04:05Z</updated>
050       *<generator uri='http://juneau.apache.org/' version='1.0'>Juneau</generator>
051       *<subtitle type='html'>Describes <em>stuff</em> about Juneau</subtitle>
052       *<entry>
053       *  <author>
054       *      <name>Jane Smith</name>
055       *      <uri>http://juneau.apache.org/</uri>
056       *      <email>janesmith@apache.org</email>
057       *  </author>
058       *  <contributor>
059       *      <name>John Smith</name>
060       *  </contributor>
061       *  <id>tag:juneau.apache.org</id>
062       *  <link href='http://juneau.apache.org/juneau.atom' rel='alternate' type='text/html'/>
063       *  <link href='http://juneau.apache.org/audio/juneau_podcast.mp3' rel='enclosure' type='audio/mpeg' length='12345'/>
064       *  <title>Juneau ATOM specification snapshot</title>
065       *  <updated>2016-01-02T03:04:05Z</updated>
066       *  <content base='http://www.apache.org/' lang='en' type='xhtml'>
067       *      <div xmlns="http://www.w3.org/1999/xhtml"><p><i>[Update: Juneau supports ATOM.]</i></p></div>
068       *  </content>
069       *  <published>2016-01-02T03:04:05Z</published>
070       *</entry>
071       *</feed>
072       */
073      //Serialize to ATOM/XML
074      String atomXml = s.serialize(feed);
075
076      /**
077       * Produces
078       * <feed>
079       * <link hreflang='en' rel='alternate' href='http://juneau.apache.org' type='text/html'/>
080       * <link rel='self' href='http://juneau.apache.org/feed.atom' type='application/atom+xml'/>
081       * <title>Juneau ATOM specification</title>
082       * <updated>2016-01-02T03:04:05Z</updated>
083       * <id>tag:juneau.apache.org</id>
084       * <subtitle type='html'>Describes <em>stuff</em> about Juneau</subtitle>
085       * <generator version='1.0' uri='http://juneau.apache.org'>Juneau</generator>
086       * <entry>
087       *  <link rel='alternate' href='http://juneau.apache.org/juneau.atom' type='text/html'/>
088       *  <link rel='enclosure' href='http://juneau.apache.org/audio/juneau_podcast.mp3' type='audio/mpeg' length='1337'/>
089       *  <author>
090       *      <uri>http://juneau.apache.org</uri>
091       *      <email>janesmith@apache.org</email>
092       *      <name>Jane Smith</name>
093       *  </author>
094       *  <contributor>
095       *      <name>John Smith</name>
096       *  </contributor>
097       *  <title>Juneau ATOM specification snapshot</title>
098       *  <updated>2016-01-02T03:04:05Z</updated>
099       *  <id>tag:juneau.sample.com,2013:1.2345</id>
100       *  <published>2016-01-02T03:04:05Z</published>
101       *  <content lang='en' base='http://www.apache.org/' type='xhtml'><div><p><i>[Update: Juneau supports ATOM.]</i></p></div></content>
102       * </entry>
103       * </feed>
104       */
105      // Create a serializer with readable output, no namespaces yet.
106      XmlSerializer ns = XmlSerializer.create().sq().ws().build();
107
108      // Serialize to ATOM/XML
109      atomXml = ns.serialize(feed);
110   }
111}