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 * <ul class='seealso'> 022 * <li class='extlink'>{@source} 023 * </ul> 024 */ 025public class AtomXmlExample { 026 027 /** 028 * XML Atom feed example. 029 * 030 * @param args Unused. 031 * @throws Exception Unused. 032 */ 033 @SuppressWarnings("unused") 034 public static void main(String[] args) throws Exception { 035 036 037 Feed feed = AtomFeed.getAtomFeed(); 038 039 // Example with no namespaces 040 // Create a serializer with readable output, no namespaces yet. 041 XmlSerializer s = XmlSerializer.create().sq().ws().build(); 042 043 //Produces 044 /** 045 *<feed> 046 *<id> tag:juneau.apache.org</id> 047 *<link href='http://juneau.apache.org/' rel='alternate' type='text/html' hreflang='en'/> 048 *<link href='http://juneau.apache.org/feed.atom' rel='self' type='application/atom+xml'/> 049 *<title type='text'>Juneau ATOM specification</title> 050 *<updated>2016-01-02T03:04:05Z</updated> 051 *<generator uri='http://juneau.apache.org/' version='1.0'>Juneau</generator> 052 *<subtitle type='html'>Describes <em>stuff</em> about Juneau</subtitle> 053 *<entry> 054 * <author> 055 * <name>Jane Smith</name> 056 * <uri>http://juneau.apache.org/</uri> 057 * <email>janesmith@apache.org</email> 058 * </author> 059 * <contributor> 060 * <name>John Smith</name> 061 * </contributor> 062 * <id>tag:juneau.apache.org</id> 063 * <link href='http://juneau.apache.org/juneau.atom' rel='alternate' type='text/html'/> 064 * <link href='http://juneau.apache.org/audio/juneau_podcast.mp3' rel='enclosure' type='audio/mpeg' length='12345'/> 065 * <title>Juneau ATOM specification snapshot</title> 066 * <updated>2016-01-02T03:04:05Z</updated> 067 * <content base='http://www.apache.org/' lang='en' type='xhtml'> 068 * <div xmlns="http://www.w3.org/1999/xhtml"><p><i>[Update: Juneau supports ATOM.]</i></p></div> 069 * </content> 070 * <published>2016-01-02T03:04:05Z</published> 071 *</entry> 072 *</feed> 073 */ 074 //Serialize to ATOM/XML 075 String atomXml = s.serialize(feed); 076 077 /** 078 * Produces 079 * <feed> 080 * <link hreflang='en' rel='alternate' href='http://juneau.apache.org' type='text/html'/> 081 * <link rel='self' href='http://juneau.apache.org/feed.atom' type='application/atom+xml'/> 082 * <title>Juneau ATOM specification</title> 083 * <updated>2016-01-02T03:04:05Z</updated> 084 * <id>tag:juneau.apache.org</id> 085 * <subtitle type='html'>Describes <em>stuff</em> about Juneau</subtitle> 086 * <generator version='1.0' uri='http://juneau.apache.org'>Juneau</generator> 087 * <entry> 088 * <link rel='alternate' href='http://juneau.apache.org/juneau.atom' type='text/html'/> 089 * <link rel='enclosure' href='http://juneau.apache.org/audio/juneau_podcast.mp3' type='audio/mpeg' length='1337'/> 090 * <author> 091 * <uri>http://juneau.apache.org</uri> 092 * <email>janesmith@apache.org</email> 093 * <name>Jane Smith</name> 094 * </author> 095 * <contributor> 096 * <name>John Smith</name> 097 * </contributor> 098 * <title>Juneau ATOM specification snapshot</title> 099 * <updated>2016-01-02T03:04:05Z</updated> 100 * <id>tag:juneau.sample.com,2013:1.2345</id> 101 * <published>2016-01-02T03:04:05Z</published> 102 * <content lang='en' base='http://www.apache.org/' type='xhtml'><div><p><i>[Update: Juneau supports ATOM.]</i></p></div></content> 103 * </entry> 104 * </feed> 105 */ 106 // Create a serializer with readable output, no namespaces yet. 107 XmlSerializer ns = XmlSerializer.create().sq().ws().build(); 108 109 // Serialize to ATOM/XML 110 atomXml = ns.serialize(feed); 111 } 112}