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.json.JsonSerializer;
017import org.apache.juneau.json.SimpleJsonSerializer;
018
019/**
020 * Atom feed JSON example.
021 *
022 * <ul class='seealso'>
023 *    <li class='extlink'>{@source}
024 * </ul>
025 */
026public class AtomJsonExample {
027
028   /**
029    * JSON Atom feed example.
030    *
031    * @param args Unused.
032    * @throws Exception Unused.
033    */
034   @SuppressWarnings("unused")
035   public static void main(String[] args) throws Exception {
036
037      Feed feed = AtomFeed.getAtomFeed();
038
039      // Get JSON serializer with readable output.
040      JsonSerializer s = SimpleJsonSerializer.DEFAULT_READABLE;
041
042      // Serialize to ATOM/JSON
043      //Produces
044      /**
045       * {
046       *  id: {
047       *      text: 'tag:juneau.apache.org'
048       *  },
049       *  links: [
050       *      {
051       *          href: 'http://juneau.apache.org/',
052       *          rel: 'alternate',
053       *          type: 'text/html',
054       *          hreflang: 'en'
055       *      },
056       *      {
057       *          href: 'http://juneau.apache.org/juneau.atom',
058       *          rel: 'self',
059       *          type: 'application/atom+xml'
060       *      }
061       *  ],
062       *  title: {
063       *      type: 'text',
064       *      text: 'Juneau ATOM specification'
065       *  },
066       *  updated: '2016-01-02T03:04:05Z',
067       *  generator: {
068       *      uri: 'http://juneau.apache.org/',
069       *      version: '1.0',
070       *      text: 'Juneau'
071       *  },
072       *  subtitle: {
073       *      type: 'html',
074       *      text: 'Describes <em>stuff</em> about Juneau'
075       *  },
076       *  entries: [
077       *      {
078       *          authors: [
079       *              {
080       *                  name: 'James Bognar',
081       *                  uri: 'http://juneau.apache.org/',
082       *                  email: 'jamesbognar@apache.org'
083       *              }
084       *          ],
085       *  contributors: [
086       *      {
087       *          name: 'Barry M. Caceres'
088       *      }
089       *  ],
090       *  id: {
091       *      text: 'tag:juneau.apache.org'
092       *  },
093       *  links: [
094       *      {
095       *          href: 'http://juneau.apache.org/juneau.atom',
096       *          rel: 'alternate',
097       *          type: 'text/html'
098       *      },
099       *      {
100       *          href: 'http://juneau.apache.org/audio/juneau_podcast.mp3',
101       *          rel: 'enclosure',
102       *          type: 'audio/mpeg',
103       *          length: 12345
104       *      }
105       *  ],
106       *  title: {
107       *      text: 'Juneau ATOM specification snapshot'
108       *  },
109       *  updated: '2016-01-02T03:04:05Z',
110       *  content: {
111       *      base: 'http://www.apache.org/',
112       *      lang: 'en',
113       *      type: 'xhtml',
114       *      text: '<div xmlns="http://www.w3.org/1999/xhtml"><p><i>[Update: Juneau supports ATOM.]</i></p></div>'
115       *  },
116       *  published: '2016-01-02T03:04:05Z'
117       *  }
118       *  ]
119       *  }
120       */
121      String atomJson = s.serialize(feed);
122   }
123}