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