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.rest.dto;
014
015import static org.apache.juneau.dto.atom.AtomBuilder.*;
016
017import java.net.URI;
018
019import org.apache.juneau.jsonschema.annotation.ExternalDocs;
020import org.apache.juneau.annotation.*;
021import org.apache.juneau.dto.atom.*;
022import org.apache.juneau.encoders.*;
023import org.apache.juneau.html.annotation.*;
024import org.apache.juneau.http.annotation.*;
025import org.apache.juneau.http.annotation.Body;
026import org.apache.juneau.jena.annotation.*;
027import org.apache.juneau.rest.*;
028import org.apache.juneau.rest.annotation.*;
029import org.apache.juneau.rest.widget.*;
030import org.apache.juneau.serializer.annotation.*;
031
032/**
033 * Sample resource that shows how to generate ATOM feeds.
034 *
035 * <ul class='seealso'>
036 *    <li class='extlink'>{@source}
037 * </ul>
038 */
039@Rest(
040   path="/atom",
041   title="Sample ATOM feed resource",
042   description="Sample resource that shows how to render ATOM feeds",
043   encoders=GzipEncoder.class,
044   swagger=@ResourceSwagger(
045      contact=@Contact(name="Juneau Developer",email="dev@juneau.apache.org"),
046      license=@License(name="Apache 2.0",url="http://www.apache.org/licenses/LICENSE-2.0.html"),
047      version="2.0",
048      termsOfService="You are on your own.",
049      externalDocs=@ExternalDocs(description="Apache Juneau",url="http://juneau.apache.org")
050   )
051)
052@HtmlDocConfig(
053   widgets={
054      ContentTypeMenuItem.class,
055      ThemeMenuItem.class
056   },
057   navlinks={
058      "up: request:/..",
059      "options: servlet:/?method=OPTIONS",
060      "stats: servlet:/stats",
061      "$W{ContentTypeMenuItem}",
062      "$W{ThemeMenuItem}",
063      "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/dto/$R{servletClassSimple}.java"
064   }
065)
066@SerializerConfig(
067   quoteChar="'"
068)
069@RdfConfig(
070   rdfxml_tab="5",
071   addRootProperty="true"
072)
073@BeanConfig(
074   examples="Feed: $F{AtomFeedResource_example.json}"
075)
076public class AtomFeedResource extends BasicRestServletJena {
077   private static final long serialVersionUID = 1L;
078
079   private Feed feed;     // The root resource object
080
081   @Override /* Servlet */
082   public void init() {
083      try {
084         feed =
085            feed("tag:juneau.sample.com,2013:1", "Juneau ATOM specification", "2013-05-08T12:29:29Z")
086            .subtitle(text("html").text("A <em>lot</em> of effort went into making this effortless"))
087            .links(
088               link("alternate", "text/html", "http://www.sample.com/").hreflang("en"),
089               link("self", "application/atom+xml", "http://www.sample.com/feed.atom")
090            )
091            .generator(
092               generator("Juneau").uri("http://juneau.apache.org/").version("1.0")
093            )
094            .entries(
095               entry("tag:juneau.sample.com,2013:1.2345", "Juneau ATOM specification snapshot", "2013-05-08T12:29:29Z")
096               .links(
097                  link("alternate", "text/html", "http://www.sample.com/2012/05/08/juneau.atom"),
098                  link("enclosure", "audio/mpeg", "http://www.sample.com/audio/juneau_podcast.mp3").length(1337)
099               )
100               .published("2013-05-08T12:29:29Z")
101               .authors(
102                  person("James Bognar").uri(new URI("http://www.sample.com/")).email("jamesbognar@apache.org")
103               )
104               .contributors(
105                  person("Barry M. Caceres")
106               )
107               .content(
108                  content("xhtml")
109                  .lang("en")
110                  .base("http://www.apache.org/")
111                  .text("<div><p>[Update: Juneau supports ATOM.]</p></div>")
112               )
113            );
114      } catch (Exception e) {
115         throw new RuntimeException(e);
116      }
117   }
118
119   /**
120    * Get the sample ATOM feed
121    *
122    * @return The sample ATOM feed.
123    */
124   @RestMethod(
125      summary="Get the sample ATOM feed"
126   )
127   public Feed get() {
128      return feed;
129   }
130
131   /**
132    * Overwrite the sample ATOM feed
133    *
134    * @param feed The new ATOM feed.
135    * @return The updated ATOM feed.
136    */
137   @RestMethod(
138      summary="Overwrite the sample ATOM feed",
139      description="Replaces the feed with the specified content, and then mirrors it as the response."
140   )
141   public Feed put(@Body Feed feed) {
142      this.feed = feed;
143      return feed;
144   }
145}