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 * <h5 class='section'>See Also:</h5>
026 * <ul>
027 *    <li class='link'>{@doc juneau-marshall.HtmlDetails.HtmlAnnotation}
028 * </ul>
029 */
030@Documented
031@Target({TYPE,FIELD,METHOD})
032@Retention(RUNTIME)
033@Inherited
034public @interface Html {
035
036   /**
037    * Use the specified anchor text when serializing a URI.
038    *
039    * <p>
040    * The text can contain any bean property values resolved through variables of the form <js>"{property-name}"</js>.
041    *
042    * <h5 class='figure'>Example:</h5>
043    * <p class='bcode w800'>
044    *    <jc>// Produces &lt;a href&#61;'...'&gt;drive&lt;/a&gt; when serialized to HTML.</jc>
045    *    <ja>@Html</ja>(anchorText=<js>"drive"</js>)
046    *    <ja>@URI</ja> <jc>// Treat property as a URL</jc>
047    *    <jk>public</jk> String getDrive() {...}
048    * </p>
049    *
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    * <h5 class='section'>See Also:</h5>
092    * <ul>
093    *    <li class='jf'>{@link HtmlSerializer#HTML_addKeyValueTableHeaders}
094    * </ul>
095    */
096   boolean noTableHeaders() default false;
097
098   /**
099    * When <jk>true</jk>, collections of beans should be rendered as trees instead of tables.
100    *
101    * <p>
102    * Default is <jk>false</jk>.
103    */
104   boolean noTables() default false;
105
106   /**
107    * Associates an {@link HtmlRender} with a bean property for custom HTML rendering of the property.
108    *
109    * <p>
110    * This annotation applies to bean properties and classes.
111    */
112   @SuppressWarnings("rawtypes")
113   Class<? extends HtmlRender> render() default HtmlRender.class;
114}