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.html.annotation;
014
015import static java.lang.annotation.ElementType.*;
016import static java.lang.annotation.RetentionPolicy.*;
017
018import java.lang.annotation.*;
019
020import org.apache.juneau.html.*;
021
022/**
023 * Annotation that can be applied to classes, fields, and methods to tweak how they are handled by {@link HtmlSerializer}.
024 *
025 * <ul class='seealso'>
026 *    <li class='link'>{@doc HtmlAnnotation}
027 * </ul>
028 */
029@Documented
030@Target({TYPE,FIELD,METHOD})
031@Retention(RUNTIME)
032@Inherited
033public @interface Html {
034
035   /**
036    * Use the specified anchor text when serializing a URI.
037    *
038    * <p>
039    * The text can contain any bean property values resolved through variables of the form <js>"{property-name}"</js>.
040    *
041    * <h5 class='figure'>Example:</h5>
042    * <p class='bcode w800'>
043    *    <jc>// Produces &lt;a href&#61;'...'&gt;drive&lt;/a&gt; when serialized to HTML.</jc>
044    *    <ja>@Html</ja>(anchorText=<js>"drive"</js>)
045    *    <ja>@URI</ja> <jc>// Treat property as a URL</jc>
046    *    <jk>public</jk> String getDrive() {...}
047    * </p>
048    *
049    * <p>
050    * This overrides the behavior specified by {@link HtmlSerializer#HTML_uriAnchorText}.
051    */
052   String anchorText() default "";
053
054   /**
055    * Specifies what format to use for the HTML element.
056    */
057   HtmlFormat format() default HtmlFormat.HTML;
058
059   /**
060    * Adds a hyperlink to a bean property when rendered as HTML.
061    *
062    * <p>
063    * The text can contain any bean property values resolved through variables of the form <js>"{property-name}"</js>.
064    *
065    * <p>
066    * The URLs can be any of the following forms:
067    * <ul>
068    *    <li>Absolute - e.g. <js>"http://host:123/myContext/myServlet/myPath"</js>
069    *    <li>Context-root-relative - e.g. <js>"/myContext/myServlet/myPath"</js>
070    *    <li>Context-relative - e.g. <js>"context:/myServlet/myPath"</js>
071    *    <li>Servlet-relative - e.g. <js>"servlet:/myPath"</js>
072    *    <li>Path-info-relative - e.g. <js>"myPath"</js>
073    * </ul>
074    *
075    * <h5 class='figure'>Example:</h5>
076    * <p class='bcode w800'>
077    *    <jk>public class</jk> FileSpace {
078    *
079    *       <ja>@Html</ja>(link=<js>"servlet:/drive/{drive}"</js>)
080    *       <jk>public</jk> String getDrive() {
081    *          ...;
082    *       }
083    *    }
084    * </p>
085    */
086   String link() default "";
087
088   /**
089    * When <jk>true</jk>, don't add headers to tables.
090    *
091    * <ul class='seealso'>
092    *    <li class='jf'>{@link HtmlSerializer#HTML_addKeyValueTableHeaders}
093    * </ul>
094    */
095   boolean noTableHeaders() default false;
096
097   /**
098    * When <jk>true</jk>, collections of beans should be rendered as trees instead of tables.
099    *
100    * <p>
101    * Default is <jk>false</jk>.
102    */
103   boolean noTables() default false;
104
105   /**
106    * Dynamically apply this annotation to the specified classes/methods/fields.
107    *
108    * <p>
109    * Used in conjunction with the {@link HtmlConfig#applyHtml()}.
110    * It is ignored when the annotation is applied directly to classes/methods/fields.
111    *
112    * <h5 class='section'>Valid patterns:</h5>
113    * <ul class='spaced-list'>
114    *  <li>Classes:
115    *       <ul>
116    *          <li>Fully qualified:
117    *             <ul>
118    *                <li><js>"com.foo.MyClass"</js>
119    *             </ul>
120    *          <li>Fully qualified inner class:
121    *             <ul>
122    *                <li><js>"com.foo.MyClass$Inner1$Inner2"</js>
123    *             </ul>
124    *          <li>Simple:
125    *             <ul>
126    *                <li><js>"MyClass"</js>
127    *             </ul>
128    *          <li>Simple inner:
129    *             <ul>
130    *                <li><js>"MyClass$Inner1$Inner2"</js>
131    *                <li><js>"Inner1$Inner2"</js>
132    *                <li><js>"Inner2"</js>
133    *             </ul>
134    *       </ul>
135    *    <li>Methods:
136    *       <ul>
137    *          <li>Fully qualified with args:
138    *             <ul>
139    *                <li><js>"com.foo.MyClass.myMethod(String,int)"</js>
140    *                <li><js>"com.foo.MyClass.myMethod(java.lang.String,int)"</js>
141    *                <li><js>"com.foo.MyClass.myMethod()"</js>
142    *             </ul>
143    *          <li>Fully qualified:
144    *             <ul>
145    *                <li><js>"com.foo.MyClass.myMethod"</js>
146    *             </ul>
147    *          <li>Simple with args:
148    *             <ul>
149    *                <li><js>"MyClass.myMethod(String,int)"</js>
150    *                <li><js>"MyClass.myMethod(java.lang.String,int)"</js>
151    *                <li><js>"MyClass.myMethod()"</js>
152    *             </ul>
153    *          <li>Simple:
154    *             <ul>
155    *                <li><js>"MyClass.myMethod"</js>
156    *             </ul>
157    *          <li>Simple inner class:
158    *             <ul>
159    *                <li><js>"MyClass$Inner1$Inner2.myMethod"</js>
160    *                <li><js>"Inner1$Inner2.myMethod"</js>
161    *                <li><js>"Inner2.myMethod"</js>
162    *             </ul>
163    *       </ul>
164    *    <li>Fields:
165    *       <ul>
166    *          <li>Fully qualified:
167    *             <ul>
168    *                <li><js>"com.foo.MyClass.myField"</js>
169    *             </ul>
170    *          <li>Simple:
171    *             <ul>
172    *                <li><js>"MyClass.myField"</js>
173    *             </ul>
174    *          <li>Simple inner class:
175    *             <ul>
176    *                <li><js>"MyClass$Inner1$Inner2.myField"</js>
177    *                <li><js>"Inner1$Inner2.myField"</js>
178    *                <li><js>"Inner2.myField"</js>
179    *             </ul>
180    *       </ul>
181    *    <li>A comma-delimited list of anything on this list.
182    * </ul>
183    *
184    * <ul class='seealso'>
185    *    <li class='link'>{@doc DynamicallyAppliedAnnotations}
186    * </ul>
187    */
188   String on() default "";
189
190   /**
191    * Associates an {@link HtmlRender} with a bean property for custom HTML rendering of the property.
192    *
193    * <p>
194    * This annotation applies to bean properties and classes.
195    */
196   @SuppressWarnings("rawtypes")
197   Class<? extends HtmlRender> render() default HtmlRender.class;
198}