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