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@RestResource( 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 "$W{ContentTypeMenuItem}", 061 "$W{ThemeMenuItem}", 062 "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/dto/$R{servletClassSimple}.java" 063 } 064) 065@SerializerConfig( 066 quoteChar="'" 067) 068@RdfConfig( 069 rdfxml_tab="5", 070 addRootProperty="true" 071) 072@BeanConfig( 073 examples="Feed: $F{AtomFeedResource_example.json}" 074) 075public class AtomFeedResource extends BasicRestServletJena { 076 private static final long serialVersionUID = 1L; 077 078 private Feed feed; // The root resource object 079 080 @Override /* Servlet */ 081 public void init() { 082 try { 083 feed = 084 feed("tag:juneau.sample.com,2013:1", "Juneau ATOM specification", "2013-05-08T12:29:29Z") 085 .subtitle(text("html").text("A <em>lot</em> of effort went into making this effortless")) 086 .links( 087 link("alternate", "text/html", "http://www.sample.com/").hreflang("en"), 088 link("self", "application/atom+xml", "http://www.sample.com/feed.atom") 089 ) 090 .generator( 091 generator("Juneau").uri("http://juneau.apache.org/").version("1.0") 092 ) 093 .entries( 094 entry("tag:juneau.sample.com,2013:1.2345", "Juneau ATOM specification snapshot", "2013-05-08T12:29:29Z") 095 .links( 096 link("alternate", "text/html", "http://www.sample.com/2012/05/08/juneau.atom"), 097 link("enclosure", "audio/mpeg", "http://www.sample.com/audio/juneau_podcast.mp3").length(1337) 098 ) 099 .published("2013-05-08T12:29:29Z") 100 .authors( 101 person("James Bognar").uri(new URI("http://www.sample.com/")).email("jamesbognar@apache.org") 102 ) 103 .contributors( 104 person("Barry M. Caceres") 105 ) 106 .content( 107 content("xhtml") 108 .lang("en") 109 .base("http://www.apache.org/") 110 .text("<div><p>[Update: Juneau supports ATOM.]</p></div>") 111 ) 112 ); 113 } catch (Exception e) { 114 throw new RuntimeException(e); 115 } 116 } 117 118 /** 119 * Get the sample ATOM feed 120 * 121 * @return The sample ATOM feed. 122 */ 123 @RestMethod( 124 summary="Get the sample ATOM feed" 125 ) 126 public Feed get() { 127 return feed; 128 } 129 130 /** 131 * Overwrite the sample ATOM feed 132 * 133 * @param feed The new ATOM feed. 134 * @return The updated ATOM feed. 135 */ 136 @RestMethod( 137 summary="Overwrite the sample ATOM feed", 138 description="Replaces the feed with the specified content, and then mirrors it as the response." 139 ) 140 public Feed put(@Body Feed feed) { 141 this.feed = feed; 142 return feed; 143 } 144}