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; 014 015import static org.apache.juneau.dto.html5.HtmlBuilder.*; 016 017import org.apache.juneau.dto.html5.*; 018import org.apache.juneau.html.annotation.*; 019import org.apache.juneau.rest.annotation.*; 020import org.apache.juneau.rest.beans.*; 021import org.apache.juneau.rest.servlet.*; 022import org.apache.juneau.rest.widget.*; 023 024/** 025 * Sample resource that allows images to be uploaded and retrieved. 026 * 027 * <h5 class='section'>See Also:</h5><ul> 028 * <li class='link'><a class="doclink" href="../../../../../index.html#jrs.Marshalling">REST Marshalling</a> 029 * <li class='link'><a class="doclink" href="../../../../../index.html#jrs.HtmlBeans">HtmlBeans</a> 030 * </ul> 031 */ 032@Rest( 033 path="/htmlbeans", 034 title="HTML bean examples", 035 description="Examples of serialized HTML beans." 036) 037@HtmlDocConfig( 038 widgets={ 039 ContentTypeMenuItem.class 040 }, 041 navlinks={ 042 "up: request:/..", 043 "api: servlet:/api", 044 "stats: servlet:/stats", 045 "$W{ContentTypeMenuItem}", 046 "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/HtmlBeansResource.java" 047 }, 048 aside={ 049 "<div class='text'>", 050 " <p>Examples of serialized HTML beans.</p>", 051 "</div>" 052 }, 053 asideFloat="RIGHT" 054) 055public class HtmlBeansResource extends BasicRestObject { 056 057 @SuppressWarnings("unused") 058 private static final long serialVersionUID = 1L; 059 060 /** 061 * [HTTP GET /htmlbeans] 062 * @return Descriptive links to the child endpoints. 063 */ 064 @RestGet("/") 065 public ResourceDescriptions getChildDescriptions() { 066 return ResourceDescriptions 067 .create() 068 .append("table", "Example of a serialized table") 069 .append("div", "Example of a serialized div tag") 070 .append("form", "Example of a serialized form"); 071 } 072 073 /** 074 * [HTTP GET /htmlbeans/table] 075 * @return An example table. 076 */ 077 @RestGet("/table") 078 @HtmlDocConfig( 079 aside={ 080 "<div class='text'>", 081 " <p>Example of serialized table.</p>", 082 "</div>" 083 } 084 ) 085 public Table aTable() { 086 return table( 087 tr( 088 th("c1"), 089 th("c2") 090 ), 091 tr( 092 td("v1"), 093 td("v2") 094 ) 095 ); 096 } 097 098 /** 099 * [HTTP GET /htmlbeans/div] 100 * @return An example div tag. 101 */ 102 @RestGet("/div") 103 @HtmlDocConfig( 104 aside={ 105 "<div class='text'>", 106 " <p>Example of serialized div tag.</p>", 107 "</div>" 108 } 109 ) 110 public HtmlElement aDiv() { 111 return div() 112 .children( 113 p("Juneau supports ", b(i("mixed")), " content!") 114 ) 115 .onmouseover("alert(\"boo!\");"); 116 } 117 118 /** 119 * [HTTP GET /htmlbeans/form] 120 * @return An example form tag. 121 */ 122 @RestGet("/form") 123 @HtmlDocConfig( 124 aside={ 125 "<div class='text'>", 126 " <p>Example of serialized HTML form.</p>", 127 "</div>" 128 } 129 ) 130 public Form aForm() { 131 return form().action("/submit").method("POST") 132 .children( 133 "Position (1-10000): ", input("number").name("pos").value(1), br(), 134 "Limit (1-10000): ", input("number").name("limit").value(100), br(), 135 button("submit", "Submit"), 136 button("reset", "Reset") 137 ); 138 } 139}