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.rest.dto; 018 019import static org.apache.juneau.bean.atom.AtomBuilder.*; 020 021import java.net.*; 022 023import org.apache.juneau.annotation.*; 024import org.apache.juneau.bean.atom.*; 025import org.apache.juneau.encoders.*; 026import org.apache.juneau.html.annotation.*; 027import org.apache.juneau.http.annotation.*; 028import org.apache.juneau.http.annotation.Content; 029import org.apache.juneau.rest.annotation.*; 030import org.apache.juneau.rest.servlet.*; 031import org.apache.juneau.rest.widget.*; 032import org.apache.juneau.serializer.annotation.*; 033 034/** 035 * Sample resource that shows how to generate ATOM feeds. 036 * 037 * 038 * @serial exclude 039 */ 040@Rest( 041 path="/atom", 042 title="Sample ATOM feed resource", 043 description="Sample resource that shows how to render ATOM feeds", 044 encoders=GzipEncoder.class, 045 swagger=@Swagger( 046 contact=@Contact(name="Juneau Developer",email="dev@juneau.apache.org"), 047 license=@License(name="Apache 2.0",url="http://www.apache.org/licenses/LICENSE-2.0.html"), 048 version="2.0", 049 termsOfService="You are on your own.", 050 externalDocs=@ExternalDocs(description="Apache Juneau",url="http://juneau.apache.org") 051 ) 052) 053@HtmlDocConfig( 054 widgets={ 055 ContentTypeMenuItem.class 056 }, 057 navlinks={ 058 "up: request:/..", 059 "api: servlet:/api", 060 "stats: servlet:/stats", 061 "$W{ContentTypeMenuItem}", 062 "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/dto/AtomFeedResource.java" 063 } 064) 065@SerializerConfig( 066 quoteChar="'" 067) 068public class AtomFeedResource extends BasicRestServlet { 069 private static final long serialVersionUID = 1L; 070 071 private Feed feed; // The root resource object 072 073 /** 074 * [HTTP GET /dto/atom] 075 * Get the sample ATOM feed 076 * 077 * @return The sample ATOM feed. 078 */ 079 @RestGet(summary = "Get the sample ATOM feed") 080 public Feed get() { 081 return feed; 082 } 083 084 @Override /* Servlet */ 085 public void init() { 086 try { 087 feed = 088 feed("tag:foo.org", "Title", "2016-12-31T05:02:03Z") 089 .setSubtitle(text("html").setText("Subtitle")) 090 .setLinks( 091 link("alternate", "text/html", "http://foo.org/").setHreflang("en"), 092 link("self", "application/atom+xml", "http://foo.org/feed.atom") 093 ) 094 .setGenerator( 095 generator("Example Toolkit").setUri("http://www.foo.org/").setVersion("1.0") 096 ) 097 .setEntries( 098 entry("tag:foo.org", "Title", "2016-12-31T05:02:03Z") 099 .setLinks( 100 link("alternate", "text/html", "http://foo.org/2005/04/02/atom"), 101 link("enclosure", "audio/mpeg", "http://foo.org/audio/foobar.mp3").setLength(1337) 102 ) 103 .setPublished("2016-12-31T05:02:03Z") 104 .setAuthors( 105 person("John Smith").setUri(new URI("http://foo.org/")).setEmail("foo@foo.org") 106 ) 107 .setContributors( 108 person("John Smith"), 109 person("Jane Smith") 110 ) 111 .setContent( 112 content("xhtml") 113 .setLang("en") 114 .setBase("http://foo.org/") 115 .setText("<div><p><i>[Sample content]</i></p></div>") 116 ) 117 ); 118 } catch (Exception e) { 119 throw new IllegalStateException(e); 120 } 121 } 122 123 /** 124 * [HTTP PUT /dto/atom] 125 * Overwrite the sample ATOM feed 126 * 127 * @param feed The new ATOM feed. 128 * @return The updated ATOM feed. 129 */ 130 @RestPut(summary = "Overwrite the sample ATOM feed", description = "Replaces the feed with the specified content, and then mirrors it as the response.") 131 public Feed put(@Content Feed feed) { 132 this.feed = feed; 133 return feed; 134 } 135}