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/div]
066    * @return An example div tag.
067    */
068   @RestGet("/div")
069   @HtmlDocConfig(
070      aside={
071         "<div class='text'>",
072         "  <p>Example of serialized div tag.</p>",
073         "</div>"
074      }
075   )
076   public HtmlElement aDiv() {
077      return div()
078         .children(
079            p("Juneau supports ", b(i("mixed")), " content!")
080         )
081         .onmouseover("alert(\"boo!\");");
082   }
083
084   /**
085    * [HTTP GET /htmlbeans/form]
086    * @return An example form tag.
087    */
088   @RestGet("/form")
089   @HtmlDocConfig(
090      aside={
091         "<div class='text'>",
092         "  <p>Example of serialized HTML form.</p>",
093         "</div>"
094      }
095   )
096   public Form aForm() {
097      return form().action("/submit").method("POST")
098         .children(
099            "Position (1-10000): ", input("number").name("pos").value(1), br(),
100            "Limit (1-10000): ", input("number").name("limit").value(100), br(),
101            button("submit", "Submit"),
102            button("reset", "Reset")
103         );
104   }
105
106   /**
107    * [HTTP GET /htmlbeans/table]
108    * @return An example table.
109    */
110   @RestGet("/table")
111   @HtmlDocConfig(
112      aside={
113         "<div class='text'>",
114         "  <p>Example of serialized table.</p>",
115         "</div>"
116      }
117   )
118   public Table aTable() {
119      return table(
120         tr(
121            th("c1"),
122            th("c2")
123         ),
124         tr(
125            td("v1"),
126            td("v2")
127         )
128      );
129   }
130
131   /**
132    * [HTTP GET /htmlbeans]
133    * @return Descriptive links to the child endpoints.
134    */
135   @RestGet("/")
136   public ResourceDescriptions getChildDescriptions() {
137      return ResourceDescriptions
138         .create()
139         .append("table", "Example of a serialized table")
140         .append("div", "Example of a serialized div tag")
141         .append("form", "Example of a serialized form");
142   }
143}