001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.examples.bean.atom;
018
019import static org.apache.juneau.bean.atom.AtomBuilder.*;
020
021import java.net.*;
022
023import org.apache.juneau.bean.atom.*;
024
025/**
026 * Atom feed example.
027 *
028 */
029@SuppressWarnings({
030   "java:S115", // Constants use UPPER_snakeCase convention (e.g., CONST_timestamp)
031   "java:S1118" // Utility class instantiation intentional for this use case
032})
033public class AtomFeed {
034
035   private static final String CONST_timestamp = "2016-12-31T05:02:03Z";
036   private static final String EXAMPLE_URL_FOO_ORG = "http://foo.org/";
037   private static final String EXAMPLE_URL_WWW_FOO_ORG = "http://www.foo.org/";
038
039   /**
040    * @return A sample Atom feed.
041    * @throws URISyntaxException Won't happen
042    */
043   public static Feed getAtomFeed() throws URISyntaxException {
044
045      return
046         feed("tag:foo.org", "Title", CONST_timestamp)
047         .setSubtitle(text("html").setText("Subtitle"))
048         .setLinks(
049            link("alternate", "text/html", EXAMPLE_URL_FOO_ORG).setHreflang("en"),
050            link("self", "application/atom+xml", "http://foo.org/feed.atom")
051         )
052         .setGenerator(
053            generator("Example Toolkit").setUri(EXAMPLE_URL_WWW_FOO_ORG).setVersion("1.0")
054         )
055         .setEntries(
056            entry("tag:foo.org", "Title", CONST_timestamp)
057            .setLinks(
058               link("alternate", "text/html", "http://foo.org/2005/04/02/atom"),
059               link("enclosure", "audio/mpeg", "http://foo.org/audio/foobar.mp3").setLength(1337)
060            )
061            .setPublished(CONST_timestamp)
062            .setAuthors(
063               person("John Smith").setUri(new URI(EXAMPLE_URL_FOO_ORG)).setEmail("foo@foo.org")
064            )
065            .setContributors(
066               person("John Smith"),
067               person("Jane Smith")
068            )
069            .setContent(
070               content("xhtml")
071               .setLang("en")
072               .setBase(EXAMPLE_URL_FOO_ORG)
073               .setText("<div><p><i>[Sample content]</i></p></div>")
074            )
075         );
076   }
077}